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
Wayne is implementing row-level security in a PostgreSQL database, setting a session parameter app.current_tenant_id before executing a query, which works in a SQL IDE/repl. However, when using the @effect/sql-kysely library in TypeScript, the session configuration doesn't persist between queries within a transaction. Wayne provided the initial code attempt and encountered an error indicating the session setting wasn't recognized. After further investigation, Wayne found that db.executeQuery from @effect/sql-kysely does not execute the session parameter setting correctly, unlike when using the kysely library directly, which does work as expected.
Key Takeaways:
Transaction Scope: It's crucial to ensure commands like setting session parameters are executed within the same transaction/session scope.
Library Specific Behavior: Third-party libraries like @effect/sql-kysely may not behave the same as their underlying libraries (like kysely) and may require custom handling or a different approach to execute raw SQL statements correctly.
Debugging and Testing: When encountering issues, cross-verifying with the underlying library (kysely in this case) can help identify if the problem lies within the third-party wrapper or elsewhere.
Effectful Programming Understanding: Understanding how asynchronous operations are wrapped in effectful programming libraries is key, as seen with the Effect.tryPromise not influencing the execution of a non-effectified method.
Summary
Summary:
Wayne is implementing row-level security in a PostgreSQL database, setting a session parameter
app.current_tenant_id
before executing a query, which works in a SQL IDE/repl. However, when using the@effect/sql-kysely
library in TypeScript, the session configuration doesn't persist between queries within a transaction. Wayne provided the initial code attempt and encountered an error indicating the session setting wasn't recognized. After further investigation, Wayne found thatdb.executeQuery
from@effect/sql-kysely
does not execute the session parameter setting correctly, unlike when using thekysely
library directly, which does work as expected.Key Takeaways:
Transaction Scope: It's crucial to ensure commands like setting session parameters are executed within the same transaction/session scope.
Library Specific Behavior: Third-party libraries like
@effect/sql-kysely
may not behave the same as their underlying libraries (likekysely
) and may require custom handling or a different approach to execute raw SQL statements correctly.Debugging and Testing: When encountering issues, cross-verifying with the underlying library (
kysely
in this case) can help identify if the problem lies within the third-party wrapper or elsewhere.Effectful Programming Understanding: Understanding how asynchronous operations are wrapped in effectful programming libraries is key, as seen with the
Effect.tryPromise
not influencing the execution of a non-effectified method.Discord thread
https://discord.com/channels/795981131316985866/1339354717498773555
The text was updated successfully, but these errors were encountered: