(options: {
readonly acquire?: Effect.Effect<void, never, Scope.Scope> | undefined
readonly begin?: SqlClient.SqlClient.MakeOptions["begin"]
readonly borrow?: boolean | undefined
readonly commit?: Effect.Effect<void, SqlError.SqlError> | undefined
readonly prepareTransactionControls?: boolean | undefined
readonly release?: Effect.Effect<void> | undefined
readonly releaseSavepoint?: boolean | undefined
} = {})
| 149 | * `Reactivity` service the client uses. |
| 150 | */ |
| 151 | const makeClient = (options: { |
| 152 | readonly acquire?: Effect.Effect<void, never, Scope.Scope> | undefined |
| 153 | readonly begin?: SqlClient.SqlClient.MakeOptions["begin"] |
| 154 | readonly borrow?: boolean | undefined |
| 155 | readonly commit?: Effect.Effect<void, SqlError.SqlError> | undefined |
| 156 | readonly prepareTransactionControls?: boolean | undefined |
| 157 | readonly release?: Effect.Effect<void> | undefined |
| 158 | readonly releaseSavepoint?: boolean | undefined |
| 159 | } = {}) => { |
| 160 | const calls: Array<string> = [] |
| 161 | const record = (call: string) => |
| 162 | Effect.sync(() => { |
| 163 | calls.push(call) |
| 164 | }) |
| 165 | const execute = (sql: string) => Effect.as(record(sql), []) |
| 166 | const connection: SqlConnection.Connection = { |
| 167 | execute: (sql) => execute(`prepared(${sql})`), |
| 168 | executeRaw: execute, |
| 169 | executeValues: execute, |
| 170 | executeUnprepared: execute, |
| 171 | executeValuesUnprepared: execute, |
| 172 | executeStream: (sql) => Stream.fromEffect(execute(sql)) |
| 173 | } |
| 174 | const commit = options.commit |
| 175 | return SqlClient.make({ |
| 176 | driver: "test", |
| 177 | acquirer: Effect.as( |
| 178 | Effect.andThen( |
| 179 | options.acquire ?? Effect.void, |
| 180 | Effect.addFinalizer(() => Effect.andThen(record("release"), options.release ?? Effect.void)) |
| 181 | ), |
| 182 | connection |
| 183 | ), |
| 184 | compiler: Statement.makeCompilerSqlite(), |
| 185 | spanAttributes: [], |
| 186 | prepareTransactionControls: options.prepareTransactionControls, |
| 187 | begin: options.begin, |
| 188 | releaseSavepoint: options.releaseSavepoint ? (name) => `RELEASE SAVEPOINT ${name}` : undefined, |
| 189 | borrower: options.borrow ? (f) => Effect.andThen(record("borrow"), f(connection)) : undefined, |
| 190 | commit: commit === undefined ? undefined : () => Effect.andThen(record("COMMIT"), commit) |
| 191 | }).pipe( |
| 192 | Effect.flatMap((sql) => |
| 193 | Effect.map(Effect.service(Reactivity.Reactivity), (reactivity) => ({ |
| 194 | sql, |
| 195 | reactivity, |
| 196 | calls, |
| 197 | record, |
| 198 | after: (name: string) => sql.afterCommit(record(`after(${name})`)) |
| 199 | })) |
| 200 | ), |
| 201 | Effect.provide(Reactivity.layer) |
| 202 | ) |
| 203 | } |
| 204 | |
| 205 | const assertEnded = (error: SqlError.SqlError) => |
| 206 | assert.deepStrictEqual( |
no test coverage detected