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

Function make

packages/sql-sqlite-bun/src/SqliteClient.ts:78–198  ·  view source on GitHub ↗
(
  options: SqliteClientConfig
)

Source from the content-addressed store, hash-verified

76 * @since 1.0.0
77 */
78export const make = (
79 options: SqliteClientConfig
80): Effect.Effect<SqliteClient, never, Scope.Scope | Reactivity.Reactivity> =>
81 Effect.gen(function*() {
82 const compiler = Statement.makeCompilerSqlite(options.transformQueryNames)
83 const transformRows = options.transformResultNames ?
84 Statement.defaultTransforms(
85 options.transformResultNames
86 ).array :
87 undefined
88
89 const makeConnection = Effect.gen(function*() {
90 const db = new Database(options.filename, {
91 readonly: options.readonly,
92 readwrite: options.readwrite ?? true,
93 create: options.create ?? true
94 } as any)
95 yield* Effect.addFinalizer(() => Effect.sync(() => db.close()))
96
97 if (options.disableWAL !== true) {
98 db.run("PRAGMA journal_mode = WAL;")
99 }
100
101 const run = (
102 sql: string,
103 params: ReadonlyArray<unknown> = []
104 ) =>
105 Effect.withFiberRuntime<Array<any>, SqlError>((fiber) => {
106 const useSafeIntegers = Context.get(fiber.currentContext, Client.SafeIntegers)
107 try {
108 const statement = db.query(sql)
109 // @ts-ignore bun-types missing safeIntegers method, fixed in https://github.com/oven-sh/bun/pull/26627
110 statement.safeIntegers(useSafeIntegers)
111 return Effect.succeed((statement.all(...(params as any)) ?? []) as Array<any>)
112 } catch (cause) {
113 return Effect.fail(new SqlError({ cause, message: "Failed to execute statement" }))
114 }
115 })
116
117 const runValues = (
118 sql: string,
119 params: ReadonlyArray<unknown> = []
120 ) =>
121 Effect.withFiberRuntime<Array<any>, SqlError>((fiber) => {
122 const useSafeIntegers = Context.get(fiber.currentContext, Client.SafeIntegers)
123 try {
124 const statement = db.query(sql)
125 // @ts-ignore bun-types missing safeIntegers method, fixed in https://github.com/oven-sh/bun/pull/26627
126 statement.safeIntegers(useSafeIntegers)
127 return Effect.succeed((statement.values(...(params as any)) ?? []) as Array<any>)
128 } catch (cause) {
129 return Effect.fail(new SqlError({ cause, message: "Failed to execute statement" }))
130 }
131 })
132
133 return identity<SqliteConnection>({
134 execute(sql, params, transformRows) {
135 return transformRows

Callers 1

layerFunction · 0.70

Calls 11

identityFunction · 0.85
restoreFunction · 0.85
syncMethod · 0.80
withPermitsMethod · 0.80
releaseMethod · 0.80
entriesMethod · 0.80
addFinalizerMethod · 0.65
closeMethod · 0.65
takeMethod · 0.65
makeMethod · 0.65
runMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…