ugly-sql database tool
Project description
## ugly-sql
### 基础使用
数据库连接工具:
```python
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()
```
基础操作:
```python
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))
```
### 基础使用
数据库连接工具:
```python
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()
```
基础操作:
```python
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
Release history Release notifications | RSS feed
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
Close
Hashes for ugly_sql-0.0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42e72f3d102097418e7d9a46945d1fbe5acd68499dd9fe5f56c72ba08c4ba5fd |
|
MD5 | e4d15b741871a9b5616d15334ef32463 |
|
BLAKE2b-256 | 57364d4e34306ae5f897075dcfd8112b1dba37cc634acb0162ef195d5dcc8584 |