GithubHelp home page GithubHelp logo

fastsql's Introduction

fastsql

A bit of extra usability for sqlalchemy.

Install

pip install fastsql

Usage examples

Connect to db and return filled MetaData object (sqlalchemy format)

# from https://pypi.org/project/python-dotenv/
load_dotenv('.env.local')

USER = environ['SQLUSER']
PASS = environ['SQLPASS']
DRIV = 'mysql+pymysql'
DB   = 'prisma'
HOST = '127.0.0.1'
PORT = 3306

db = conn_db(DRIV, USER, PASS, HOST, PORT, DB)

Show list of table names

' '.join(db.tables)

Get the User table. Note that db supports tab completion of table names here. The Table object and collection of columns is returned as a tuple.

u,uc = db.User

The collection of columns supports tab completion too.

uc.billingAddress

Get a data frame, with optional where clause and limit, with the df method on either Table or MetaData.

# These are equivalent
u.df(where=uc.email.startswith('j'), limit=1)
db.df(u.select(uc.email.startswith('j'), limit=1))

You can also pass SQL statements directly.

# returns a DataFrame
db.sql("select count(*) from User")
# returns None
db.sql("insert into User select * from User where email = 'xxx'")

fastsql's People

Contributors

jph00 avatar

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.