Answer the question
In order to leave comments, you need to log in
What is the difference between asyncpg.Connection.transaction and asyncpg.Connection.acquire?
Hello.
I don’t really rummage in the database, and I don’t understand what is the difference transaction()
from acquire()
Judging by the asyncpg documentation, acquire()
it allows you to pick up a connection from the pool (which is created in advance),
execute some code, and then return it back to the pool.
But what does it do then transaction()
?
Well, that is, I understand that he opens a transaction. But what does this give us? What can we do rollback, but acquire()
writes directly, without wrapping it into a transaction?
Both of them are used like this:
async with pool.transaction() as conn:
ИЛИ
async with pool.acquire() as conn:
result = conn.fetch(query)
<or any code i want to execute>
BEGIN;
, COMMIT;
. acquire()
should be used for read-only, but transaction()
for create-update-delete?
Answer the question
In order to leave comments, you need to log in
Mixed in a bunch of horses, people
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question