MCPcopy Index your code
hub / github.com/Effect-TS/effect / make

Function make

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

Source from the content-addressed store, hash-verified

134 * @since 1.0.0
135 */
136export const make = (
137 options: LibsqlClientConfig
138): Effect.Effect<LibsqlClient, never, Scope.Scope | Reactivity.Reactivity> =>
139 Effect.gen(function*() {
140 const compiler = Statement.makeCompilerSqlite(options.transformQueryNames)
141 const transformRows = options.transformResultNames ?
142 Statement.defaultTransforms(
143 options.transformResultNames
144 ).array :
145 undefined
146
147 const spanAttributes: Array<[string, unknown]> = [
148 ...(options.spanAttributes ? Object.entries(options.spanAttributes) : []),
149 [ATTR_DB_SYSTEM_NAME, "sqlite"]
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(

Callers 1

layerFunction · 0.70

Calls 14

restoreFunction · 0.85
entriesMethod · 0.80
syncMethod · 0.80
releaseMethod · 0.80
withPermitsMethod · 0.80
mapMethod · 0.65
toStringMethod · 0.65
closeMethod · 0.65
pipeMethod · 0.65
makeMethod · 0.65
takeMethod · 0.65
addFinalizerMethod · 0.65

Tested by

no test coverage detected