| 150 | ] |
| 151 | |
| 152 | class LibsqlConnectionImpl implements LibsqlConnection { |
| 153 | constructor(readonly sdk: Libsql.Client | Libsql.Transaction) {} |
| 154 | |
| 155 | run( |
| 156 | sql: string, |
| 157 | params: ReadonlyArray<unknown> = [] |
| 158 | ) { |
| 159 | return Effect.map( |
| 160 | Effect.tryPromise({ |
| 161 | try: () => this.sdk.execute({ sql, args: params as Array<any> }), |
| 162 | catch: (cause) => new SqlError({ cause, message: "Failed to execute statement" }) |
| 163 | }), |
| 164 | (results) => results.rows |
| 165 | ) |
| 166 | } |
| 167 | |
| 168 | runRaw( |
| 169 | sql: string, |
| 170 | params: ReadonlyArray<unknown> = [] |
| 171 | ) { |
| 172 | return Effect.tryPromise({ |
| 173 | try: () => this.sdk.execute({ sql, args: params as Array<any> }), |
| 174 | catch: (cause) => new SqlError({ cause, message: "Failed to execute statement" }) |
| 175 | }) |
| 176 | } |
| 177 | |
| 178 | execute( |
| 179 | sql: string, |
| 180 | params: ReadonlyArray<unknown>, |
| 181 | transformRows: (<A extends object>(row: ReadonlyArray<A>) => ReadonlyArray<A>) | undefined |
| 182 | ) { |
| 183 | return transformRows |
| 184 | ? Effect.map(this.run(sql, params), transformRows) |
| 185 | : this.run(sql, params) |
| 186 | } |
| 187 | executeRaw(sql: string, params: ReadonlyArray<unknown>) { |
| 188 | return this.runRaw(sql, params) |
| 189 | } |
| 190 | executeValues(sql: string, params: ReadonlyArray<unknown>) { |
| 191 | return Effect.map(this.run(sql, params), (rows) => rows.map((row) => Array.from(row) as Array<any>)) |
| 192 | } |
| 193 | executeUnprepared( |
| 194 | sql: string, |
| 195 | params: ReadonlyArray<unknown>, |
| 196 | transformRows: (<A extends object>(row: ReadonlyArray<A>) => ReadonlyArray<A>) | undefined |
| 197 | ) { |
| 198 | return this.execute(sql, params, transformRows) |
| 199 | } |
| 200 | executeStream() { |
| 201 | return Effect.dieMessage("executeStream not implemented") |
| 202 | } |
| 203 | get beginTransaction() { |
| 204 | return Effect.map( |
| 205 | Effect.tryPromise({ |
| 206 | try: () => (this.sdk as Libsql.Client).transaction("write"), |
| 207 | catch: (cause) => new SqlError({ cause, message: "Failed to begin transaction" }) |
| 208 | }), |
| 209 | (tx) => new LibsqlConnectionImpl(tx) |
nothing calls this directly
no outgoing calls
no test coverage detected