Coder Social home page Coder Social logo

tmthyjames / sqlcell Goto Github PK

View Code? Open in Web Editor NEW
150.0 10.0 11.0 4.24 MB

SQLCell is a magic function for the Jupyter Notebook that executes raw, parallel, parameterized SQL queries with the ability to accept Python values as parameters and assign output data to Python variables while concurrently running Python code. And *much* more.

License: MIT License

Python 100.00%
ipython ipython-notebook ipython-magic python sql postgresql multi-threading inline-editing jupyter-notebook jupyter

sqlcell's Introduction

SQLCell

Bringing together the power of SQL, Python, and Javascript. Run raw, multi-threaded SQL in an IPython Notebook while concurrently executing python cells, and a ton of other features.

*** New Version 2.0 ***

Find a tutorial here.

To Install:

pip install sqlcell

sqlcell's People

Contributors

allysonoakleydobbins avatar dependabot[bot] avatar tmthyjames avatar xiaochuanyu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sqlcell's Issues

stop watch for timing queries

using this same technique

import sys
for i in range(1, 1100):
    sys.stdout.write('\r')
    sys.stdout.write("Progress: %s%% | Timer: %s | %-s" % (100*2.0, float(2)*i, '#'))
    sys.stdout.flush()

Engine connection string persistence

After setting the engine, if engine argument is used on subsequent queries instead of using same connection, the current connection is closed and a new one is open which takes significant time.

SQLCell should do a check to see if the current connection string is the same as new one being passed. If so, use same connection, else open new one and persist that one until new engine passed.

Accept psql meta-commands

Using subprocess, we can execute psql commands (with the -H flag to convert output to HTML tables) from the CLI via python and get the output using subprocess.check_ouput. Then we convert the HTML to a pandas dataframe with pd.read_html.

import subprocess

psql_command = False
if cell.startswith('\\'):
    psql_command = True
    pg = ['psql', 'phTeam-allpayer', '-c', cell.strip(), '-H']

    output = subprocess.check_output(pg)
    data = pd.read_html(output, header=0)[0]

Testing...

check types before creating UPDATE statement

Check for types for quote injection into UPDATE statement.

(ProgrammingError) column "phteam" does not exist
LINE 1: ...E branding SET host_name = 'local' WHERE brand_name = PHTEAM
^
"UPDATE branding SET host_name = 'local' WHERE brand_name = PHTEAM" {}

PHTEAM here should be in quotes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.