很喜欢的一套 ORM,看中的特性:
https://docs.ponyorm.com/database.html#using-database-object-for-raw-sql-queries
有时候,用 ORM 不能满足一些细节的需求,需要针对特定的数据库写 SQL,可以选用 Database 实例的 get, select, execute 等方法。
对于直接裸写 SQL,pony 也提供了一些帮助如连接池,自动提交,统一异常和传入参数,优化返回结果,自动补全 SELECT
https://docs.ponyorm.com/database.html#customizing-connection-behavior
database = Database()
# entities declaration
...
@database.on_connect(provider='sqlite')
def sqlite_case_sensitivity(_, conn):
import pathlib
rc = pathlib.Path.home() / ".sqliterc"
rc.exists() and conn.executescript(rc.read_text())
...
database.bind(**options)
database.generate_mapping(create_tables=True)