-
-
Notifications
You must be signed in to change notification settings - Fork 71
allow setting "default search path" #9
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
Not just databases, the schema name should be configurable too. |
@vzsg schema name? |
Sorry, I was being imprecise. What I actually meant is setting a default search path after the connection is made, some database drivers expose it. The search path is important in (typ. enterprisish) scenarios where schemas are used as an extra level of grouping/access control over tables. This has been a pretty common feature request for the libpq-based postgresql package and the -provider. |
Ah okay, will re-open to track that issue then. |
Looks like this can be done by simply running: SET search_path TO myschema; This could be done in |
Thanks for finding a solution. I'm very eager to see how using public func boot(_ app: Application) throws {
// what would actually go here?
} |
@fwgreen something like this: public func boot(_ app: Application) throws {
try app.withNewConnection(to: .psql) { conn in
return conn.simpleQuery("SET search_path TO myschema").transform(to: ())
}.wait()
} |
I think that would only change that setting for that single (ephemeral) connection. You could prepend it with |
I can confirm that prepending with public func boot(_ app: Application) throws {
try app.withNewConnection(to: .psql) { conn in
return conn.simpleQuery("ALTER DATABASE my_db SET search_path TO my_schema").transform(to: ())
}.wait()
} Maybe one day users could have something as simple as static let entity = "my_schema.my_table" But this gets us up and running, so I'll take it. Thank you all! |
Ah, didn't realize that was ephemeral to the connection. You can use var databases = DatabasesConfig()
// register your dbs and what have you
databases.appendConfigurationHandler(on: .psql) { conn in
return conn.simpleQuery("SET search_path TO myschema")
}
services.register(databases)
|
@tanner0101 Will this workaround continue to work in the next major release? |
This workaround is not perfect, at least not in Vapor 3. I have not tried this in Vapor 4. It seems like the Postgres driver has been completely redone, so it's possible that this works now. However, without explicit support and the tests to back it up, it's possible that this accidentally breaks even if it is currently working. I'm willing to help in this regard. Let me know what your plans are for this. |
configuration.searchPath = ["foo", "bar", "baz"] When set, the following query will be run automatically on new connections: SET search_path = "foo", "bar", "baz" |
* 2.0.0 gm * file updates * update guide docs * fix img * fix img * fixes * fixes * fixes * fixes * fixes * fixes * fixes * fixes * code cleanup * add search path * add searchPath fixes #9 * optional password * fix decoder force unwrap #175 * pass server hostname, fixes #178 * array type test * test fluent gm branch * master + import fix
Related to #8.
The text was updated successfully, but these errors were encountered: