Disabling Prepared statements
重要的是要注意,虽然直接连接和会话模式下的 Supavisor 支持预处理语句,但事务模式下的 Supavisor 不支持。 #
🌐 It is important to note that although the direct connections and Supavisor in session mode support prepared statements, Supavisor in transaction mode does not.
如何在事务模式下禁用 Supavisor 的预处理语句 #
🌐 How to disable prepared statements for Supavisor in transaction mode
每个 ORM 或库对预处理语句的配置方式都不同。这里是一些常用的设置。如果没看到你用的,可以留言评论
🌐 Each ORM or library configures prepared statements differently. Here are settings for some common ones. If you don't see yours, make a comment
Prisma: #
🌐 Prisma:
在连接字符串末尾加上 ?pgbouncer=true:
🌐 add ?pgbouncer=true to end of connection string:
1postgres://[db-user].[project-ref]:[db-password]@aws-0-[aws-region].pooler.supabase.com:6543/[db-name]?pgbouncer=true细雨: #
🌐 Drizzle:
向客户端添加一个准备好的假标志:
🌐 Add a prepared false flag to the client:
1export const client = postgres(connectionString, { prepare: false })Node Postgres#
1const query = {2 name: 'fetch-user', // <--------- DO NOT INCLUDE3 text: 'SELECT * FROM user WHERE id = $1',4 values: [1],5}Psycopg#
将 prepare_threshold 设置为 None。
🌐 set the prepare_threshold to None.
asyncpg#
遵循 asyncpg 文档 中的建议
🌐 Follow the recommendation in the asyncpg docs
通过向 asyncpg.connect() 和 asyncpg.create_pool() 传递
statement_cache_size=0来禁用自动使用预处理语句(显然,也要避免使用 Connection.prepare());
Rust 的死侍或 tokio-postgres#
🌐 Rust's Deadpool or tokio-postgres:
- 查看 GitHub 讨论