-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
need connection support currentSchema #1123
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
Comments
me too it will be great ! thanks |
You can set the schema using a query: I think it will be better if you do this yourself, instead that we code this query into the library. @brianc opinion? |
Fair point. Could you suggest at what point you should run that query? This should run for every new connection that is setup, but before any other queries are executed. On/pool/connect doesn't seem to support an async/callback function so I'm curious what the best approach would be. |
Hi @bramkoot, |
Thanks, that was a nice idea. I've made another implementation that works for now, but it feels very hacky. For anyone who is interested, this is what I used;
I'm using this in conjunction with pg-async and that works as expected. I would still be very interested in a proper implementation. |
I guess @brianc is happy to review a pull request ;) |
See also #1393 (comment) to set arbitrary options. |
Not sure how you would use @charmander's solution to set the search path, but the next comment worked for me: #1393 (comment)
|
@safi2510 I added my own answer there also ;) |
Here's how we send various custom options to a client, following @charmander's example. class EnhancedClient extends Client {
getStartupConf() {
if (process.env.PG_OPTIONS) {
try {
const options = JSON.parse(process.env.PG_OPTIONS);
return {
...super.getStartupConf(),
...options,
};
} catch (e) {
console.error(e);
// Coalesce to super.getStartupConf() on parse error
}
}
return super.getStartupConf();
}
}
const pool = new Pool({ Client: EnhancedClient }); In this example, PG_OPTIONS is stringified JSON, e.g. provided via the command line, a PM2 ecosystem file, etc. For example, |
How about simply setting process.env.PGOPTIONS="-c search_path=some_schema"
const pool = new Pool(); |
Hi, I am finding that when I create a client with a login that I have previously set the search path for, that client.query seems to ignore this when running queries. #2419 |
any updates? |
Here's another option: const pool = new Pool({
options: "-c search_path=some_schema",
}); |
what @bhanson-techempower said is how I handle this in our own apps. I haven't checked to see if |
Hope that through the configuration can be specified default schema, like this
var cn = {
host: 'localhost',
port: 5432,
database: 'MyDB',
user: 'user1',
password: 'pw',
currentSchema:'C0001'
};
thanks!
The text was updated successfully, but these errors were encountered: