MCPcopy
hub / github.com/Effect-TS/effect / ConnectionImpl

Class ConnectionImpl

packages/sql-mysql2/src/MysqlClient.ts:96–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 }
143 executeValues(sql: string, params: ReadonlyArray<unknown>) {
144 return this.run(sql, params, true)
145 }
146 executeUnprepared(
147 sql: string,
148 params: ReadonlyArray<unknown>,
149 transformRows: (<A extends object>(row: ReadonlyArray<A>) => ReadonlyArray<A>) | undefined
150 ) {
151 return transformRows
152 ? Effect.map(this.run(sql, params, false, "query"), transformRows)
153 : this.run(sql, params, false, "query")

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…