【问题标题】:How to use PostgreSQL in Python Pyramid without ORM如何在没有 ORM 的 Python Pyramid 中使用 PostgreSQL
【发布时间】:2020-03-06 14:18:16
【问题描述】:

如果我想将 PostgreSQL 与 Python Pyramid 一起使用,但我不想使用 ORM,我是否需要 SQLAlchemy?或者我可以直接使用 psycopg2 吗?以及如何做到这一点?

【问题讨论】:

    标签: python postgresql pyramid


    【解决方案1】:

    即使你不想使用 ORM,你仍然可以使用 SQLAlchemy 的查询 语言。

    如果你不想使用 SQLAlchemy,你当然可以直接使用 psycopg2。查看 Pyramid 食谱 - MongoDB 和 Pyramid 或 CouchDB 和 Pyramid 以获得灵感。

    【讨论】:

      【解决方案2】:

      您可以使用 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,))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-08-02
        • 2020-03-09
        • 2019-01-22
        • 2019-05-18
        • 2021-01-17
        • 1970-01-01
        • 2021-06-26
        • 1970-01-01
        相关资源
        最近更新 更多