A lightweight SQLite helper library.
Project description
DBSqlite
基于 Sqlite3 的数据操控工具,对连接(connect)、游标(cursor)概念进行了封装,支持使用 Dict 数据类型来操作数据库。
简单示例
from DBSqlite import Sqlite
db = Sqlite('mydb.db')
rows = [{'name': 'xiaoming', 'age': '12', 'gender': 'male'},
{'name': 'xiaohong', 'age': '11', 'gender': 'female'}]
ret = db.insert('table_student', rows)
print('ret:',ret)
# print
# ret:[{'id': 1, 'name': 'xiaoming', 'age': '12', 'gender': 'male', 'class': None}, {'id': 2, 'name': 'xiaohong', 'age': '11', 'gender': 'female', 'class': None}]
依赖
- python3.6+
- sqlite3:
pip install pysqlite3
方法
DBSqlite 创建一个数据库工具实例
-
必选参数:
db:数据库文件路径
-
返回:DBSqlit 示例
qj 执行一个查询语句,query json 的简写
-
参数:
sql查询语句字符串
-
返回:查询结果,数据结构为
list
qvs 执行一个查询语句, query values 的简写
-
参数:
sql查询语句字符串
-
返回:查询结果集的第一列组成的
list
qv 执行一个查询语句, query value 的简写
-
参数:
sql查询语句字符串
-
返回:查询结果集的第一行第一列的值
qo 执行一个查询语句 query object 的简写
-
参数:
sql查询语句字符串
-
返回:查询结果集的第一行的
dict
de 执行一个sql语句 do execute 的简写
-
参数:
sql查询语句字符串
-
返回:影响行数
insert 向库表中插入多行记录
说明
- 以库表字段为主,记录中不提供视为None
- 每行记录的字段可以不一致
- 记录中不属于库表的字段会被忽略
-
参数:
table_name库表名称rows需要插入的记录,list类型
-
返回:插入库表的结果,
list类型
update 更新库表中的多行记录
说明
- 只更新库表中存在且记录中提供的字段
- 每行记录的字段可以不一致
- 如果记录中没有提供主键,会被做插入处理
-
参数
table_name库表名称rows需要更新的记录,list类型
-
返回:更新库表的结果,
list类型
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
dbsqlite-1.0.0.tar.gz
(5.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dbsqlite-1.0.0.tar.gz.
File metadata
- Download URL: dbsqlite-1.0.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4082a36a42148e77b2fdaddfd70aa59b272fc40c74ec5530ade19879ce3572c
|
|
| MD5 |
e22c606ba37c4f63e3d10bfb986806e7
|
|
| BLAKE2b-256 |
d37138bdef2ecdf553bd41394f173e431a32b727875c9acf8e60d3ad9cd727f0
|
File details
Details for the file DBSQLite-1.0.0-py3-none-any.whl.
File metadata
- Download URL: DBSQLite-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d496f095dd7fef7cc90ccbbe007ec5d4895aaf183e5eb63e534001aeec2f5ab6
|
|
| MD5 |
b789e6ebf22870a513cbcf8da0911d2d
|
|
| BLAKE2b-256 |
f6595325e0087d66d496c4007d29dd1ee6c86aca90f895022adf57925f576663
|