-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Schema resets to public whenever a query fails #1584
Comments
You can't use the generic Be easiest if you add a local wrapper in your app and use that everywhere. Something like: export async function query(sql, params) {
// Get a connection from the pool:
let client = await pool.connect();
try {
// Run our custom SQL to set search_path
await client.query('SET search_path TO airlines');
// Run the actual SQL we want to execute
const result = await client.query(sql, params);
// This is done in two steps so that we can catch the error and discard the connection
return result;
} catch(err) {
// Release the connection back to the pool
client.release(err);
client = null;
// Throw the original error so the caller gets it
throw err;
} finally {
if (client) {
// Work completed successfully so release the connection back to the pool for reuse
client.release();
}
}
} There's also a That has it's own issues though as it doesn't wait for the command to complete or even be successful. I think there's an open issue regarding fixing that (i.e. making it async and waiting for explicit complete). Until that's done I'd suggest manually managing it yourself. |
See brianc/node-pg-pool#97 for more discussion on changing settings for all clients in a pool. |
Here is how I'm creating a new conn poll
Then set the search_path to a schema
Now when I execute a query that does not fail, I sill get the schema that I had previously set when I run
SELECT current_schema();
But when I deliberately run a query that fails (for instance a typo in "SEKECT..." instead of "SELECT...",
the schema is reset to "public" when I run
SELECT current_schema();
This definitely looks like a bug and I'm not sure how to get around this. Any help is appreciated. Thanks.
Edit:
BTW, I'm currently using v7.4.1
The text was updated successfully, but these errors were encountered: