MCPcopy Create free account
hub / github.com/effect-app/libs / make

Function make

repos/effect/packages/sql/libsql/src/LibsqlClient.ts:183–346  ·  view source on GitHub ↗
(
  options: LibsqlClientConfig
)

Source from the content-addressed store, hash-verified

181 * @category constructors
182 * @since 4.0.0
183 */
184export const make = (
185 options: LibsqlClientConfig
186): Effect.Effect<LibsqlClient, never, Scope.Scope | Reactivity.Reactivity> =>
187 Effect.gen(function*() {
188 const compiler = Statement.makeCompilerSqlite(options.transformQueryNames)
189 const transformRows = options.transformResultNames ?
190 Statement.defaultTransforms(
191 options.transformResultNames
192 ).array :
193 undefined
194
195 const spanAttributes: Array<[string, unknown]> = [
196 ...(options.spanAttributes ? Object.entries(options.spanAttributes) : []),
197 [ATTR_DB_SYSTEM_NAME, "sqlite"]
198 ]
199
200 class LibsqlConnectionImpl implements LibsqlConnection {
201 readonly sdk: Libsql.Client | Libsql.Transaction
202 constructor(sdk: Libsql.Client | Libsql.Transaction) {
203 this.sdk = sdk
204 }
205
206 run(
207 sql: string,
208 params: ReadonlyArray<unknown> = []
209 ) {
210 return Effect.map(
211 Effect.tryPromise({
212 try: () => this.sdk.execute({ sql, args: params as Array<any> }),
213 catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
214 }),
215 (results) => results.rows
216 )
217 }
218
219 runRaw(
220 sql: string,
221 params: ReadonlyArray<unknown> = []
222 ) {
223 return 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 }
228
229 execute(
230 sql: string,
231 params: ReadonlyArray<unknown>,
232 transformRows: (<A extends object>(row: ReadonlyArray<A>) => ReadonlyArray<A>) | undefined
233 ) {
234 return transformRows
235 ? Effect.map(this.run(sql, params), transformRows)
236 : this.run(sql, params)
237 }
238 executeRaw(sql: string, params: ReadonlyArray<unknown>) {
239 return this.runRaw(sql, params)
240 }

Callers 1

layerFunction · 0.70

Calls 12

syncMethod · 0.80
closeMethod · 0.80
addFinalizerMethod · 0.80
mapMethod · 0.65
valueMethod · 0.65
toStringMethod · 0.65
makeMethod · 0.65
takeMethod · 0.65
releaseMethod · 0.65
withPermitsMethod · 0.65
executeRawMethod · 0.45
succeedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…