Skip to content
/ PyDO Public

PyDO defines a lightweight, consistent interface for accessing databases in Python

License

Notifications You must be signed in to change notification settings

bobby4k/PyDO

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyDO

Python DataBase Objects ¶

Support:

  • 1 类似PHP PDO简单操作数据的方法, 没有orm 只有sql与dict/list类型的操作

  • 2 返回格式支持:

    • None: tuple
    • dict: 字典(默认)
    • row: Row
    • namedtuple: 具名元组
  • 3 目前仅支持项目中用到的

    • sqlite3
    • mysql(pymysql)
    • postgres(psycopg2)
  • 4 insert支持dict + list(tuple)格式数据

  • 5 placeholders(显示SQL占位符)仅支持 %s 方式

#qmark style:
    cur.execute("INSERT INTO lang VALUES(%s, %s)", ("C", 1972))

Usage:

# https://en.wikipedia.org/wiki/Data_source_name
dsn = "sqlite:///local_sqlite_file"
dsn = "mysql://username:password@host:port/database?charset=utf8mb4"
dsn = "postgresql://username:password@host:port/database"

timeout = 3
db = PyDO(dsn=dsn, timeout=timeout)
print(db.version())

共六大类方法

  1. 连接与游标
  2. DQL/DML
  3. table便捷查询
  4. 事务包装
  5. 配置选项
  6. 数据类型转换/字符串转义

新加入数据库支持,需注意:

  • cursor:
    • rowcount
    • lastrowid ==> 自定义使用last_insertId
  • 数据返回格式 FETCH_MODE:
    • cursor_factory
  • sql占位符
    • _placeholder

END FILE

About

PyDO defines a lightweight, consistent interface for accessing databases in Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages