簡體   English   中英

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

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

如果我想將 PostgreSQL 與 Python 金字塔一起使用,我是否需要 SQLAlchemy,但我不想使用 PostgreSQL 或者我可以直接使用psycopg2嗎? 以及如何做到這一點?

您可以使用 psycopg2-wrapper 在 psycopg2 上執行查詢或命令。

用於安裝;

pip install psycopg2-wrapper

用於使用;

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

即使您不想使用 ORM,您仍然可以使用 SQLAlchemy 的查詢語言。

如果不想用SQLAlchemy,當然可以直接用psycopg2。 查看 Pyramid 食譜 - MongoDB 和 Pyramid 或 CouchDB 和 Pyramid 以獲得靈感。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM