a quick tool base dict for mysql and sqlite
Project description
Cator
简介
封装了mysql和sqlite,用于零时执行一些脚本,项目中使用
返回数据以dict字典为主,若要修改返回值类型,可以通过继承修改
支持4种占位符:
mysql风格: %s %(key)s
sqlite风格:? :key
安装
pip install cator
使用示例
指定 autocommit 模式
import cator
# mysql
db_url = "mysql://root:123456@127.0.0.1:3306/data?charset=utf8&autocommit=true"
# sqlite
db_url = 'sqlite:///data.db?isolation_level=null'
# open Database
db = cator.connect(db_url)
# close
db.close()
接口
Database类
class Database:
@property
def tables(self):
pass
def table(self, table_name):
pass
def select(self, operation, params=()):
pass
def select_one(self, operation, params=()):
pass
def update(self, operation, params=()):
pass
def delete(self, operation, params=()):
pass
def insert(self, operation, params: Union[list, dict]):
pass
def insert_one(self, operation, params: Union[tuple, dict] = ()):
pass
def before_execute(self, operation, params=None):
pass
def after_execute(self, cursor):
pass
def execute(self, operation, params=None):
pass
def cursor(self, *args, **kwargs):
"""返回cursor 对象"""
def connect(self):
"""连接数据库"""
def close(self):
"""关闭连接"""
Table 类
class Table:
@property
def columns(self):
pass
@property
def total(self):
pass
def insert(self, data: Union[dict, list]):
pass
def insert_one(self, data: dict):
pass
def delete_by_id(self, uid):
pass
def update_by_id(self, uid, data):
pass
def select_by_id(self, uid):
pass
注意问题
- 使用时需注意链接超时问题
- cator支持了autocommit自动提交,默认关闭,如有需要可以打开,
- 如果需要执行事务就需要关闭自动提交
cator基于以下模块进行改进
- myquery
- aquery
- puremysql
- pythink
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 Distribution
cator-0.0.4.tar.gz
(8.9 kB
view details)
Built Distribution
cator-0.0.4-py3-none-any.whl
(13.4 kB
view details)
File details
Details for the file cator-0.0.4.tar.gz
.
File metadata
- Download URL: cator-0.0.4.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5acb85f65be62e46eac679c7d6085a605c72edcd75912f09b9a7f867d37cdaab |
|
MD5 | 02b849813cc2f7ea914e7f03fdd0c02c |
|
BLAKE2b-256 | c50ab4679f278ef9ff09cd23a8eb838bc0c40cb853775a19b2e077eb2d5a67a2 |
File details
Details for the file cator-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: cator-0.0.4-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17d75114a24f9e38d6316d06a6081ce03f5e5f2515d7df551e2f831845d355fa |
|
MD5 | 294208c1e9b8ae994407d2a312d8c7b9 |
|
BLAKE2b-256 | 1ddfeb52ebc3f8814e5ceb9a28db705c0965417b6e772be03b855294e1f756de |