You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I have a huge application and I'm migrating the code from "brianc/node-postgres" to "porsager/postgres", I have some question.
FIRST QUESTION
I'm replace all query method of "brianc/node-postgres" (docs) with unsafe method of "porsager/postgres", eg.:
constsql='SELECT * FROM users WHERE id = $1'constparams=[10]constname='user_id'// name of the query - used for prepared statements on brianc/node-postgres// from brianc/node-postgresimport{Pool}from'pg';constclient=newPool(config)client.query(sql,params,name)// to porsager/postgresimportpostgresfrom'postgres';constclient=postgres(config)client.unsafe(sql,params);
"porsager/postgres" has no argument for prepared statements. If a name is provided into "brianc/node-postgres" the query is auto-prepared before execution. What I do if i want the same into "porsager/postgres"
SECOND QUESTION
In "brianc/node-postgres" I can retrive a client from the pool and use the same connection for all the query instead of get a connection for each query, eg.:
import{Pool}from'pg';constpool=newPool(config)// In this way teach query use the same connectionconstclient=awaitpool.connect()try{awaitclient.query('SELECT * FROM users WHERE id = $1',[1])awaitclient.query('SELECT * FROM users WHERE id = $1',[2])}finally{client.release()}// ------// In this way each query use a different connectionawaitpool.query('SELECT * FROM users WHERE id = $1',[1])awaitpool.query('SELECT * FROM users WHERE id = $1',[2])
If I understand correctly "porsager/postgres" the correct replacement is:
importpostgresfrom'postgres';constpool=postgres(config)// In this way each query use the same connectionconstclient=awaitpool.reserve()try{awaitclient.unsafe('SELECT * FROM users WHERE id = $1',[1])awaitclient.unsafe('SELECT * FROM users WHERE id = $1',[2])}finally{client.release()}// ------// In this way each query use a different connectionawaitpool.unsafe('SELECT * FROM users WHERE id = $1',[1])awaitpool.unsafe('SELECT * FROM users WHERE id = $1',[2])
The text was updated successfully, but these errors were encountered:
Hi, I have a huge application and I'm migrating the code from "brianc/node-postgres" to "porsager/postgres", I have some question.
FIRST QUESTION
I'm replace all query method of "brianc/node-postgres" (docs) with unsafe method of "porsager/postgres", eg.:
"porsager/postgres" has no argument for prepared statements. If a name is provided into "brianc/node-postgres" the query is auto-prepared before execution. What I do if i want the same into "porsager/postgres"
SECOND QUESTION
In "brianc/node-postgres" I can retrive a client from the pool and use the same connection for all the query instead of get a connection for each query, eg.:
If I understand correctly "porsager/postgres" the correct replacement is:
The text was updated successfully, but these errors were encountered: