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
As recently mentioned in kysely-org/kysely#330 (comment) I'm using RLS and configure it while initiating the client connection. For various reasons I had to switch to postgresjs where currently there is no configuration param exposed for hooking into the db client lifecycle.
As a workaround, I'm manually overriding Dialect.createDriver() as such:
classRlsDriverextendsPostgresJSDriver{constructor(protectedconfig: PostgresJSDialectConfig,protectedvars: UserVariables){super(config);}asyncacquireConnection(): Promise<PostgresJSConnection>{constreservedConnection=awaitthis.config.postgres.reserve();// apply any configs for RLSawaitreservedConnection`SELECT set_config('request.jwt.claim.sub', ${this.vars.userId}, FALSE)`;awaitreservedConnection`SET ROLE authenticated`;returnnewPostgresJSConnection(reservedConnection);}}
Feels a bit hacky bc I'm exposing that private #config prop, and it seems like the API wasn't designed for this use case.
Proposed solution
It would be helpful to have a config param on PostgresJSDialectConfig that would allow to specify a callback that may modify the reservedConnection at
For completeness onDestroyConnection might also be useful.. There might also be a better place to put that param or use a different approach, in any case the goal is to modify fresh connections before they are used.
The text was updated successfully, but these errors were encountered:
As recently mentioned in kysely-org/kysely#330 (comment) I'm using RLS and configure it while initiating the client connection. For various reasons I had to switch to postgresjs where currently there is no configuration param exposed for hooking into the db client lifecycle.
As a workaround, I'm manually overriding
Dialect.createDriver()
as such:And am subclassing PostgresJSDriver as such:
Feels a bit hacky bc I'm exposing that private
#config
prop, and it seems like the API wasn't designed for this use case.Proposed solution
It would be helpful to have a config param on
PostgresJSDialectConfig
that would allow to specify a callback that may modify the reservedConnection atkysely-postgres-js/src/driver.ts
Lines 18 to 22 in 48af0e0
For example:
For completeness onDestroyConnection might also be useful.. There might also be a better place to put that param or use a different approach, in any case the goal is to modify fresh connections before they are used.
The text was updated successfully, but these errors were encountered: