({
acquirer,
beginTransaction = "BEGIN",
commit = "COMMIT",
compiler,
reactiveMailbox,
rollback = "ROLLBACK",
rollbackSavepoint = (id) => `ROLLBACK TO SAVEPOINT ${id}`,
savepoint = (id) => `SAVEPOINT ${id}`,
spanAttributes,
transactionAcquirer,
transformRows
}: Client.SqlClient.MakeOptions)
| 30 | |
| 31 | /** @internal */ |
| 32 | export function make({ |
| 33 | acquirer, |
| 34 | beginTransaction = "BEGIN", |
| 35 | commit = "COMMIT", |
| 36 | compiler, |
| 37 | reactiveMailbox, |
| 38 | rollback = "ROLLBACK", |
| 39 | rollbackSavepoint = (id) => `ROLLBACK TO SAVEPOINT ${id}`, |
| 40 | savepoint = (id) => `SAVEPOINT ${id}`, |
| 41 | spanAttributes, |
| 42 | transactionAcquirer, |
| 43 | transformRows |
| 44 | }: Client.SqlClient.MakeOptions): Effect.Effect<Client.SqlClient, never, Reactivity.Reactivity> { |
| 45 | return Effect.gen(function*() { |
| 46 | const getConnection = Effect.flatMap( |
| 47 | Effect.serviceOption(TransactionConnection), |
| 48 | Option.match({ |
| 49 | onNone: () => acquirer, |
| 50 | onSome: ([conn]) => Effect.succeed(conn) |
| 51 | }) |
| 52 | ) |
| 53 | |
| 54 | transactionAcquirer = transactionAcquirer ?? acquirer |
| 55 | const withTransaction = makeWithTransaction({ |
| 56 | transactionTag: TransactionConnection, |
| 57 | spanAttributes, |
| 58 | acquireConnection: Effect.flatMap( |
| 59 | Scope.make(), |
| 60 | (scope) => Effect.map(Scope.extend(transactionAcquirer!, scope), (conn) => [scope, conn] as const) |
| 61 | ), |
| 62 | begin: (conn) => conn.executeUnprepared(beginTransaction, [], undefined), |
| 63 | savepoint: (conn, id) => conn.executeUnprepared(savepoint(`effect_sql_${id}`), [], undefined), |
| 64 | commit: (conn) => conn.executeUnprepared(commit, [], undefined), |
| 65 | rollback: (conn) => conn.executeUnprepared(rollback, [], undefined), |
| 66 | rollbackSavepoint: (conn, id) => conn.executeUnprepared(rollbackSavepoint(`effect_sql_${id}`), [], undefined) |
| 67 | }) |
| 68 | |
| 69 | const reactivity = yield* Reactivity.Reactivity |
| 70 | const client: Client.SqlClient = Object.assign( |
| 71 | Statement.make(getConnection, compiler, spanAttributes, transformRows), |
| 72 | { |
| 73 | [TypeId as Client.TypeId]: TypeId as Client.TypeId, |
| 74 | safe: undefined as any, |
| 75 | withTransaction, |
| 76 | reserve: transactionAcquirer, |
| 77 | withoutTransforms(): any { |
| 78 | if (transformRows === undefined) { |
| 79 | return this |
| 80 | } |
| 81 | const statement = Statement.make(getConnection, compiler.withoutTransform, spanAttributes, undefined) |
| 82 | const client = Object.assign(statement, { |
| 83 | ...this, |
| 84 | ...statement |
| 85 | }) |
| 86 | ;(client as any).safe = client |
| 87 | ;(client as any).withoutTransforms = () => client |
| 88 | return client |
| 89 | }, |
nothing calls this directly
no test coverage detected