Closed NrajuIO closed 5 months ago
I'm not a aware of a way to set this via the connection string.
You could create a post_create
hook that issues the following SQL for every newly created connection:
SET search_path TO raju_dev;
e.g.
builder.post_create(Hook::async_fn(|conn, _metrics| {
conn.execute("SET search_path TO raju_dev;", &[]).await?;
Ok(())
})
I am aware of the SET serach_path To SchemaName, but we need to handle by doing the extra query while get the connection from the pool.
But if in case of JDBC url, we have option to mention schema name in the JDBC url it self,
ex: jdbc:postgresql://localhost:5432/mydatabase?currentSchema=myschema
As deadpool-postgres
is based on tokio-postgres
this is something that needs to be fixed in the tokio-postgres
crate.
I found the following issue which seams to be exactly what you're looking for:
For the time being using a post_create
hook is the easiest fix to your problem.
we need to handle by doing the extra query while get the connection from the pool.
A connection URL parameter isn't going to do that for you, either, so what you're asking for isn't what JDBC gives you. The equivalent to a connstring parameter is the create_hook
example that bikeshedder gave you earlier. If you want something that runs on every "checkout" of a connection from the pool, one of the pre_recycle
or post_recycle
hooks might be what you want, but it depends on what exactly you want to do. Perhaps a new pre_checkout
hook could be needed, but without knowing your use-case, it's difficult to say.
I'm closing this because I don't see how this could be implemented in deadpool-postgres
as it is blocked by https://github.com/sfackler/rust-postgres/issues/631.
If you need this feature and issuing an extra query is fine for you I'd welcome a PR for either adding this feature to the Manager implementation or providing a hook. Better yet add this feature to tokio-postgres
and ping me once it is merged and it can be added to the config struct of deadpool-postgres
.
I am try to use the db pool using the postgresSQL database connection url, i want specify the one default schema to use it,
For Example, DB Name: raju_db, Schema: public, raju_test, raju_dev
I want create the one dbpool specific to the raju_dev schema is to default schema.
Is there any way to specify the schema name itself in the url, like example
if the schema or serach_path name not
DB_URL: host=localhost port=5432 dbname=raju user=user password=pwd schema=raju_dev.
(or) host=localhost port=5432 dbname=raju user=user password=pwd search_path=raju_dev