Effect-TS / effect

An ecosystem of tools for building production-grade applications in TypeScript.
https://effect.website
MIT License
7.18k stars 230 forks source link

sql-kysely: cannot use transaction #3520

Closed fredericrous closed 1 month ago

fredericrous commented 1 month ago

What version of Effect is running?

@effect/sql-kysely@0.5.0

What steps can reproduce the bug?

We cannot use transaction when instantiating @effect/sql-kysely ourselves (in order to provide a custom dialect)

  it.effect("transaction", () =>
    Effect.gen(function* (_) {
      const db = yield* KyselyDB
      db.withTransaction // withTransaction is not available

What is the expected behavior?

withTransaction should be available. db signature should be the patched version EffectKysely

What do you see instead?

transaction. db signature is Kysely

Additional information

workaround, under src/internal/kysely.ts

edit makeWithExecute and cast db variable

export const makeWithExecute = <DB>(config: KyselyConfig) => {
  const db = new Kysely<DB>(config) as unknown as EffectKysely<DB>
 ...
}
mikearnaldi commented 1 month ago

The normal withTransaction from the sql package can be used as kysley uses the connection from sql

fredericrous commented 1 month ago

Indeed, I think I mixed things up. We can use the normal db.transaction().execute from Kysely's