pg_async
|
There are two query modes: simple query mode and extended query mode. Simple query mode executes arbitrary parameterless SQL scripts. Extended query mode prepares a query and executes the query with (or without) parameters.
A simple query is an arbitrary script. It can have several statements, each statement will generate a resultset callback.
When a single query needs to be made, it might be easier not to wrap it into a begin
call, but to pass the query the alias of the database to use. Don't forget to commit the transaction after handling the result.
Independent queries (i.e. queries that do not depend on each others' results can be enqueued in a single begin callback together with the call to commit
. The queries will be run one by one in a single transaction, their results callbacks will be called as they will be completed. After all statements finish, the transaction will be committed.
commit
or rollback
is enqueued, no other queries can be started, neither from the block containing the commit call, nor from the queries' results callbacks.Prepared statements is an efficient way to run repeated queries (the most frequent situation). pg_async
uses PostgreSQL extended query mode to parse the statement, bind parameters and execute the query.