V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
MarioLuo
V2EX  ›  Python

鉴于 Python DB-API2.0 操作 SQL 太麻烦,封装了一个最轻量的工具包 dbtool.

  •  
  •   MarioLuo ·
    lkqm · 2021-03-05 19:25:44 +08:00 · 1847 次点击
    这是一个创建于 1118 天前的主题,其中的信息可能已经有所发展或是发生改变。

    有一个 Java 程序员,居然日常使用 Python 处理数据执行一些 sql, 不想使用重量 ORM 框架,DBAPI-2.0 简直比 JDBC 还繁琐,操作 sqlite, mysql 居然占位符还不一样(?, %s), 作为一个工具人自然会去发现 SQLAlchemy 、records...没找到我的滑板鞋,我的滑板鞋必须是:

    • 执行 sql 语句方便
    • 轻量的 crud 功能
    • 连接池支持: dbutils
    • 屏蔽不同 db 驱动包差异: 占位符一致?, 默认行数据 dict 类型

    于是有了 dbtool:

    # sqlite3 ....
    db = dbtool.DB('sqlite', database=':memory:')
    
    # sql
    db.execute(sql)
    db.execute_fetchone(sql)
    db.execute_count(sql)
    db.execute_cursor(sql)
    db.execute_many(sql)
    db.execute_script(sql)
    db.execute_file(file)
    
    # crud
    db.insert(dict, table='user')
    db.update(dict, table='user')
    ...
    

    ~摩擦~ https://github.com/lkqm/dbtool.py ~摩擦~

    4 条回复    2021-04-20 17:52:25 +08:00
    Acoffice
        1
    Acoffice  
       2021-03-05 19:35:42 +08:00
    厉害
    qile1
        2
    qile1  
       2021-03-06 13:53:43 +08:00 via Android
    有没有考虑 oracle 和 mssql 这些时间字段处理的区分,另外时间数据库微妙是三位,python 是六位好像,这些有没有办法处理
    MarioLuo
        3
    MarioLuo  
    OP
       2021-03-06 14:07:07 +08:00 via Android
    @qile1 mssql 使用驱动包 pymssql,如果包本身时间处理有问题就没发处理了,dbtool 主要简化 dbapi2.0, 屏蔽底层驱动包差异
    adocder
        4
    adocder  
       2021-04-20 17:52:25 +08:00
    我觉得 peewee 就挺好用的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5323 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 09:16 · PVG 17:16 · LAX 02:16 · JFK 05:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.