智能SQL-轻量级SQL生成器。
sqlbuilder的Python项目详细描述
smartsql-轻量级python sql生成器,遵循KISS principle。支持python2和python3。
您可以单独使用smartsql,或者与django一起使用,或者与超轻量级Ascetic ORM一起使用,或者与超轻量级数据映射器Openorm(miror)一起使用。
- 主页:https://bitbucket.org/emacsway/sqlbuilder
- 文件:https://sqlbuilder.readthedocs.io/
- 浏览源代码(规范回购):https://bitbucket.org/emacsway/sqlbuilder/src
- Github镜像:https://github.com/emacsway/sqlbuilder
- 获取源代码(规范回购):hg clone https://bitbucket.org/emacsway/sqlbuilder
- 获取源代码(镜像):git clone https://github.com/emacsway/sqlbuilder.git
- PYPI:https://pypi.python.org/pypi/sqlbuilder
许可证:
- 许可证是BSD
快速启动
>>> from sqlbuilder.smartsql import Q, T, compile >>> compile(Q().tables( ... (T.book & T.author).on(T.book.author_id == T.author.id) ... ).columns( ... T.book.name, T.author.first_name, T.author.last_name ... ).where( ... (T.author.first_name != 'Tom') & (T.author.last_name != 'Smith') ... )[20:30]) ('SELECT "book"."name", "author"."first_name", "author"."last_name" FROM "book" INNER JOIN "author" ON ("book"."author_id" = "author"."id") WHERE "author"."first_name" <> %s AND "author"."last_name" <> %s LIMIT %s OFFSET %s', ['Tom', 'Smith', 10, 20])
django集成
简单地将“django_sqlbuilder”添加到已安装的应用程序中。
>>> object_list = Book.s.q.tables( ... (Book.s & Author.s).on(Book.s.author == Author.s.pk) ... ).where( ... (Author.s.first_name != 'James') & (Author.s.last_name != 'Joyce') ... )[:10]