Skip to main content

ugly-sql 数据库工具

Project description

ugly-sql

基础使用

数据库连接工具:

import pymysql
from ugly_sql import SessionManager
import logging
import sys
import contextlib

@contextlib.contextmanager
def db_ctx(cfg,tran=False):
    conn=pymysql.connect(**cfg)
    sm=SessionManager(conn)
    try:
        if tran:
            sm.begin()
        yield sm.__enter__()
        sm.__exit__(None,None,None)
    except Exception as e:
        logging.warning("db_ctx error %s",e)
        et,ev,tb=sys.exc_info()
        sm.__exit__(et,ev,tb)
        raise e
    finally:
        conn.close()

基础操作:

from ugly_sql import Table
User = Table("users",("id","name","password"),"id",True)
db_cfg={}
if __name__ == '__main__':
    with db_ctx(db_cfg,True) as db:
        user=db.query(User).filter(User.name=="root",User.password=="***").one()
        print("name= {}\n password= {}".format(user.name,user.password))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

ugly_sql-0.0.4-py2.py3-none-any.whl (9.8 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page