简体   繁体   English

如何在没有 ORM 的 Python 金字塔中使用 PostgreSQL

[英]How to use PostgreSQL in Python Pyramid without ORM

Do I need SQLAlchemy if I want to use PostgreSQL with Python Pyramid, but I do not want to use the ORM?如果我想将 PostgreSQL 与 Python 金字塔一起使用,我是否需要 SQLAlchemy,但我不想使用 PostgreSQL Or can I just use the psycopg2 directly?或者我可以直接使用psycopg2吗? And how to do that?以及如何做到这一点?

you can use psycopg2-wrapper for executing query or commands on psycopg2.您可以使用 psycopg2-wrapper 在 psycopg2 上执行查询或命令。

For installation;用于安装;

pip install psycopg2-wrapper

For usage;用于使用;

from psycopg2_wrapper.database import Database
database = Database(host='', database='', user='', password='')
database.execute_query('select * from user where id=%s', (1,))

Even if you do not want to use ORM, you can still use SQLAlchemy's query language.即使您不想使用 ORM,您仍然可以使用 SQLAlchemy 的查询语言。

If you do not want to use SQLAlchemy, you can certainly use psycopg2 directly.如果不想用SQLAlchemy,当然可以直接用psycopg2。 Look into Pyramid cookbook - MongoDB and Pyramid or CouchDB and Pyramid for inspiration.查看 Pyramid 食谱 - MongoDB 和 Pyramid 或 CouchDB 和 Pyramid 以获得灵感。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM