MCPcopy Create free account
hub / github.com/Effect-TS/effect / make

Function make

packages/sql/libsql/src/LibsqlClient.ts:193–380  ·  view source on GitHub ↗
(
  options: LibsqlClientConfig
)

Source from the content-addressed store, hash-verified

191 * @since 4.0.0
192 */
193export const make = (
194 options: LibsqlClientConfig
195): Effect.Effect<LibsqlClient & Client.SqlClient, never, Scope.Scope | Reactivity.Reactivity> =>
196 Effect.gen(function*() {
197 const LibsqlTransaction = Context.Service<readonly [LibsqlConnection, counter: number]>(
198 `@effect/sql-libsql/LibsqlClient/LibsqlTransaction/${clientIdCounter++}`
199 )
200 const compiler = Statement.makeCompilerSqlite(options.transformQueryNames)
201 const transformRows = options.transformResultNames ?
202 Statement.defaultTransforms(
203 options.transformResultNames
204 ).array :
205 undefined
206
207 const spanAttributes = Object.entries({
208 [ATTR_DB_SYSTEM_NAME]: "sqlite",
209 ...options.spanAttributes
210 })
211
212 class LibsqlConnectionImpl implements LibsqlConnection {
213 readonly sdk: Libsql.Client | Libsql.Transaction
214 constructor(sdk: Libsql.Client | Libsql.Transaction) {
215 this.sdk = sdk
216 }
217
218 run(
219 sql: string,
220 params: ReadonlyArray<unknown> = []
221 ) {
222 return Effect.map(
223 Effect.tryPromise({
224 try: () => this.sdk.execute({ sql, args: params as Array<any> }),
225 catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
226 }),
227 (results) => results.rows
228 )
229 }
230
231 runRaw(
232 sql: string,
233 params: ReadonlyArray<unknown> = []
234 ) {
235 return Effect.tryPromise({
236 try: () => this.sdk.execute({ sql, args: params as Array<any> }),
237 catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
238 })
239 }
240
241 execute(
242 sql: string,
243 params: ReadonlyArray<unknown>,
244 transformRows: (<A extends object>(row: ReadonlyArray<A>) => ReadonlyArray<A>) | undefined
245 ) {
246 return transformRows
247 ? Effect.map(this.run(sql, params), transformRows)
248 : this.run(sql, params)
249 }
250 executeRaw(sql: string, params: ReadonlyArray<unknown>) {

Callers 1

layerFunction · 0.70

Calls 10

assignMethod · 0.80
toStringMethod · 0.65
closeMethod · 0.65
takeScopedMethod · 0.65
makeMethod · 0.65
restoreFunction · 0.50
mapMethod · 0.45
syncMethod · 0.45
valueMethod · 0.45
executeRawMethod · 0.45

Tested by

no test coverage detected