@@ -18,18 +18,21 @@ of asyncpg at some point in the future.
18
18
Can I use asyncpg with SQLAlchemy ORM?
19
19
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20
20
21
- Short answer: no. asyncpg uses asynchronous execution model
22
- and API, which is fundamentally incompatible with SQLAlchemy.
23
- However, it is possible to use asyncpg and SQLAlchemy Core
24
- with the help of a third-party adapter, such as asyncpgsa _ or databases _.
21
+ Yes. SQLAlchemy version 1.4 and later supports the asyncpg dialect natively.
22
+ Please refer to its documentation for details. Older SQLAlchemy versions
23
+ may be used in tandem with a third-party adapter such as
24
+ asyncpgsa _ or databases _.
25
25
26
26
27
27
Can I use dot-notation with :class: `asyncpg.Record `? It looks cleaner.
28
28
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29
29
30
30
We decided against making :class: `asyncpg.Record ` a named tuple
31
31
because we want to keep the ``Record `` method namespace separate
32
- from the column namespace.
32
+ from the column namespace. That said, you can provide a custom ``Record ``
33
+ class that implements dot-notation via the ``record_class `` argument to
34
+ :func: `connect() <asyncpg.connection.connect> ` or any of the Record-returning
35
+ methods.
33
36
34
37
35
38
Why can't I use a :ref: `cursor <asyncpg-api-cursor >` outside of a transaction?
@@ -56,15 +59,23 @@ already exists`` errors, you are most likely not connecting to the
56
59
PostgreSQL server directly, but via
57
60
`pgbouncer <https://pgbouncer.github.io/ >`_. pgbouncer, when
58
61
in the ``"transaction" `` or ``"statement" `` pooling mode, does not support
59
- prepared statements. You have two options:
62
+ prepared statements. You have several options:
60
63
61
- * if you are using pgbouncer for connection pooling to a single server,
64
+ * if you are using pgbouncer only to reduce the cost of new connections
65
+ (as opposed to using pgbouncer for connection pooling from
66
+ a large number of clients in the interest of better scalability),
62
67
switch to the :ref: `connection pool <asyncpg-connection-pool >`
63
68
functionality provided by asyncpg, it is a much better option for this
64
69
purpose;
65
70
66
- * if you have no option of avoiding the use of pgbouncer, then you need to
67
- switch pgbouncer's ``pool_mode `` to ``session ``.
71
+ * disable automatic use of prepared statements by passing
72
+ ``statement_cache_size=0 ``
73
+ to :func: `asyncpg.connect() <asyncpg.connection.connect> ` and
74
+ :func: `asyncpg.create_pool() <asyncpg.pool.create_pool> `
75
+ (and, obviously, avoid the use of
76
+ :meth: `Connection.prepare() <asyncpg.connection.Connection.prepare> `);
77
+
78
+ * switch pgbouncer's ``pool_mode `` to ``session ``.
68
79
69
80
70
81
Why do I get ``PostgresSyntaxError `` when using ``expression IN $1 ``?
0 commit comments