具有PostgreSQL和MySQL通用接口的Python模块。
WrappyDatabase的Python项目详细描述
wrappydatabase
具有PostgreSQL和MySQL通用接口的Python模块。
fromWrappyDatabaseimportDatabase# DSNd=Database("scheme://user[:pass]@host[:port]/my_db")# DSN for MySQLmysql=Database("mysql://root@localhost/mysql")# DSN for PostgreSQLpostgres=Database("postgresql://root:toot@dbsrv:5432/db")# Or argumentsdb=Database(host="host",usr="root",passwd="",db="test",driver=Database.POSTGRESQL)# Usedb.query("SELECT * FROM my_tbl WHERE deleted = %s",[0]).fetch()db.query("SELECT * FROM my_tbl WHERE deleted = %(deleted)s",{"deleted":0}).fetch_all()# SqlBuilderdb.table("my_tbl").fetch()db.table("my_tbl").where("id IN %(ids)s",{"ids":[1,2,3]}).delete()db.table("my_tbl").insert({"a":1,"b":"string",})db.table("my_tbl").where("author = %s",[1]).update({"author":2})