MCPcopy Create free account
hub / github.com/Effect-TS/effect / runRaw

Method runRaw

packages/sql/clickhouse/src/ClickhouseClient.ts:250–301  ·  view source on GitHub ↗
(sql: string, params: ReadonlyArray<unknown>, format: Clickhouse.DataFormat = "JSON")

Source from the content-addressed store, hash-verified

248 }
249
250 private runRaw(sql: string, params: ReadonlyArray<unknown>, format: Clickhouse.DataFormat = "JSON") {
251 const paramsObj: Record<string, unknown> = {}
252 for (let i = 0; i < params.length; i++) {
253 paramsObj[`p${i + 1}`] = params[i]
254 }
255 return Effect.withFiber<Clickhouse.ResultSet<"JSON"> | Clickhouse.CommandResult, SqlError>((fiber) => {
256 const method = fiber.getRef(ClientMethod)
257 return Effect.callback<Clickhouse.ResultSet<"JSON"> | Clickhouse.CommandResult, SqlError>((resume) => {
258 const queryId = fiber.getRef(QueryId) ?? Crypto.randomUUID()
259 const settings = fiber.getRef(ClickhouseSettings)
260 const controller = new AbortController()
261 if (method === "command") {
262 this.conn.command({
263 query: sql,
264 query_params: paramsObj,
265 abort_signal: controller.signal,
266 query_id: queryId,
267 clickhouse_settings: settings
268 }).then(
269 (result) => resume(Effect.succeed(result)),
270 (cause) =>
271 resume(
272 Effect.fail(
273 new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
274 )
275 )
276 )
277 } else {
278 this.conn.query({
279 query: sql,
280 query_params: paramsObj,
281 abort_signal: controller.signal,
282 query_id: queryId,
283 clickhouse_settings: settings,
284 format
285 }).then(
286 (result) => resume(Effect.succeed(result)),
287 (cause) =>
288 resume(
289 Effect.fail(
290 new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
291 )
292 )
293 )
294 }
295 return Effect.suspend(() => {
296 controller.abort()
297 return killQuery(this.conn, queryId)
298 })
299 })
300 })
301 }
302
303 private run(sql: string, params: ReadonlyArray<unknown>, format?: Clickhouse.DataFormat) {
304 return this.runRaw(sql, params, format).pipe(

Callers 3

runMethod · 0.95
executeRawMethod · 0.95
executeStreamMethod · 0.95

Calls 9

killQueryFunction · 0.85
getRefMethod · 0.80
classifyErrorFunction · 0.70
commandMethod · 0.65
failMethod · 0.65
queryMethod · 0.65
abortMethod · 0.65
resumeFunction · 0.50
succeedMethod · 0.45

Tested by

no test coverage detected