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

Function make

packages/sql-sqlite-node/src/SqliteClient.ts:90–252  ·  view source on GitHub ↗
(
  options: SqliteClientConfig
)

Source from the content-addressed store, hash-verified

88 * @since 1.0.0
89 */
90export const make = (
91 options: SqliteClientConfig
92): Effect.Effect<SqliteClient, never, Scope.Scope | Reactivity.Reactivity> =>
93 Effect.gen(function*() {
94 const compiler = Statement.makeCompilerSqlite(options.transformQueryNames)
95 const transformRows = options.transformResultNames ?
96 Statement.defaultTransforms(
97 options.transformResultNames
98 ).array :
99 undefined
100
101 const makeConnection = Effect.gen(function*() {
102 const scope = yield* Effect.scope
103 const db = new Sqlite(options.filename, {
104 readonly: options.readonly ?? false
105 })
106 yield* Scope.addFinalizer(scope, Effect.sync(() => db.close()))
107
108 if (options.disableWAL !== true) {
109 db.pragma("journal_mode = WAL")
110 }
111
112 const prepareCache = yield* Cache.make({
113 capacity: options.prepareCacheSize ?? 200,
114 timeToLive: options.prepareCacheTTL ?? Duration.minutes(10),
115 lookup: (sql: string) =>
116 Effect.try({
117 try: () => db.prepare(sql),
118 catch: (cause) => new SqlError({ cause, message: "Failed to prepare statement " })
119 })
120 })
121
122 const runStatement = (
123 statement: Sqlite.Statement,
124 params: ReadonlyArray<unknown>,
125 raw: boolean
126 ) =>
127 Effect.withFiberRuntime<ReadonlyArray<any>, SqlError>((fiber) => {
128 if (Context.get(fiber.currentContext, Client.SafeIntegers)) {
129 statement.safeIntegers(true)
130 }
131 try {
132 if (statement.reader) {
133 return Effect.succeed(statement.all(...params))
134 }
135 const result = statement.run(...params)
136 return Effect.succeed(raw ? result as unknown as ReadonlyArray<any> : [])
137 } catch (cause) {
138 return Effect.fail(new SqlError({ cause, message: "Failed to execute statement" }))
139 }
140 })
141
142 const run = (
143 sql: string,
144 params: ReadonlyArray<unknown>,
145 raw = false
146 ) =>
147 Effect.flatMap(

Callers 1

layerFunction · 0.70

Calls 10

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…