一、模块介绍
quickdb 是一个操作合集
- mysql
- postgresql
- kafka
- mongo
- redis
二 mysql
使用 sqlalchemy 为其定义了一个类
- MysqlSQLAlchemyEngine
2.1、MysqlSQLAlchemyEngine
该类继承自 SQLAlchemyEngineBase 用来定义连接
可接收 sqlalchemy create_engine 的参数
engine = MysqlSQLAlchemyEngine(host='localhost', port=3306, user='root', pwd='1234', db='test')
with engine.session() as session, session.begin:
pass
with engine.connection() as conn, conn.begin:
pass
2.2、MysqlSQLAlchemyEngine 方法
其含有以下方法:
- reverse_table_model:逆向表模型
- insert:一条或多条
- upsert:一条或多条
- delete
- execute
- merge
主要说一下 reverse_table_model 该方法含有三个参数:
-
path:生成的 model 路径,需含文件名
-
tables:需要的表,可不指定
-
commands:额外的命令
method = MysqlSQLAlchemyMethods(engine=engine) method.reverse_table_model(path='./modules.py')
三、postgresql
同 mysql
四、kafka
主要是使用了 with 和方便的 send,会帮助你将 msg 转化为 bytes,也可以同时 flush
p = KafkaMsgProducer(server=xxx)
p.send(topic, msg)
with KafkaMsgProducer(server=xxx) as p:
p.send()
五、mongo
通过 get_collection 返回的是修改过的 Collection 对象,其有两个新方法
- iter: 快速迭代数据库
- upsert_one:插入或更新的便捷写法
conn = MongoConn(host, port)
col = conn.get_collection(db, col)
for i in col.iter():
print(i)
其使用了 with,可以自动回收连接
conn = MongoConn(host, port)
col = conn.get_collection(db, col)
conn.close()
with MongoConn(host, port) as conn:
col = conn.get_collection(db, col)
六、redis
1、redisConn
with RedisConn() as conn:
pass
2、RedisLock
这是一个阻塞的 redis 事务锁
with RedisLock(lock_name=""):
pass
3、RedisLockNoWait
这是一个非阻塞的 redis 事务锁,只有获取到锁的人才执行,获取不到就不会继续等待锁,但是需要使用 lock_success 判断
with RedisLockNoWait(lock_name=") as lock:
if lock.lock_success:
...
Metadata
Release files for quickdb 0.0.39
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| quickdb-0.0.39.tar.gz | 14.2 kB | Without provenance | Details for quickdb-0.0.39.tar.gz |
Release files / quickdb-0.0.39.tar.gz
| Download URL | quickdb-0.0.39.tar.gz |
|---|---|
| Size | 14.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a8d2420cebc45bd3feb708bcde9bbfb8ceeb0dbd117a860b2787de1aa39c08e6
|
|
BLAKE2b-256 checksum How to use checksums |
7b3e500baef92b3306e2ada5c7ac2d1e63c01913597caf5693df515cfa06c6b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.2
|
Security for quickdb 0.0.39
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.