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

Function make

packages/sql-mysql2/src/MysqlClient.ts:85–269  ·  view source on GitHub ↗
(
  options: MysqlClientConfig
)

Source from the content-addressed store, hash-verified

83 * @since 1.0.0
84 */
85export const make = (
86 options: MysqlClientConfig
87): Effect.Effect<MysqlClient, SqlError, Scope | Reactivity.Reactivity> =>
88 Effect.gen(function*() {
89 const compiler = makeCompiler(options.transformQueryNames)
90 const transformRows = options.transformResultNames ?
91 Statement.defaultTransforms(
92 options.transformResultNames
93 ).array :
94 undefined
95
96 class ConnectionImpl implements Connection {
97 constructor(private readonly conn: Mysql.PoolConnection | Mysql.Pool) {}
98
99 private runRaw(
100 sql: string,
101 values?: ReadonlyArray<any>,
102 rowsAsArray = false,
103 method: "execute" | "query" = "execute"
104 ) {
105 return Effect.async<unknown, SqlError>((resume) => {
106 ;(this.conn as any)[method]({
107 sql,
108 values,
109 rowsAsArray
110 }, (cause: unknown | null, results: unknown, _fields: any) => {
111 if (cause) {
112 resume(Effect.fail(new SqlError({ cause, message: "Failed to execute statement" })))
113 } else {
114 resume(Effect.succeed(results))
115 }
116 })
117 })
118 }
119
120 private run(
121 sql: string,
122 values?: ReadonlyArray<any>,
123 rowsAsArray = false,
124 method: "execute" | "query" = "execute"
125 ) {
126 return this.runRaw(sql, values, rowsAsArray, method).pipe(
127 Effect.map((results) => Array.isArray(results) ? results : [])
128 )
129 }
130
131 execute(
132 sql: string,
133 params: ReadonlyArray<unknown>,
134 transformRows: (<A extends object>(row: ReadonlyArray<A>) => ReadonlyArray<A>) | undefined
135 ) {
136 return transformRows
137 ? Effect.map(this.run(sql, params), transformRows)
138 : this.run(sql, params)
139 }
140 executeRaw(sql: string, params: ReadonlyArray<unknown>) {
141 return this.runRaw(sql, params)
142 }

Callers 1

layerFunction · 0.70

Calls 11

syncMethod · 0.80
releaseMethod · 0.80
entriesMethod · 0.80
makeCompilerFunction · 0.70
pipeMethod · 0.65
failMethod · 0.65
endMethod · 0.65
mapMethod · 0.65
makeMethod · 0.65
resumeFunction · 0.50
valueMethod · 0.45

Tested by

no test coverage detected