简体   繁体   中英

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? Or can I just use the psycopg2 directly? And how to do that?

you can use psycopg2-wrapper for executing query or commands on 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.

If you do not want to use SQLAlchemy, you can certainly use psycopg2 directly. Look into Pyramid cookbook - MongoDB and Pyramid or CouchDB and Pyramid for inspiration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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