File size: 1,758 Bytes
9697ede | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | /* oxlint-disable */
import type * as Effect from "effect/Effect"
import { applyEffectWrapper, type QueryEffectHKTBase } from "drizzle-orm/effect-core/query-effect"
import { entityKind } from "drizzle-orm/entity"
import type { RunnableQuery } from "drizzle-orm/runnable-query"
import type { PreparedQuery } from "drizzle-orm/session"
import type { Query, SQL, SQLWrapper } from "drizzle-orm/sql/sql"
import type { SQLiteAsyncDialect } from "drizzle-orm/sqlite-core/dialect"
type SQLiteEffectRawAction = "all" | "get" | "values" | "run"
export interface SQLiteEffectRaw<TResult, TEffectHKT extends QueryEffectHKTBase = QueryEffectHKTBase>
extends Effect.Effect<TResult, TEffectHKT["error"], TEffectHKT["context"]>,
RunnableQuery<TResult, "sqlite">,
SQLWrapper {}
export class SQLiteEffectRaw<TResult, TEffectHKT extends QueryEffectHKTBase = QueryEffectHKTBase>
implements RunnableQuery<TResult, "sqlite">, SQLWrapper, PreparedQuery
{
static readonly [entityKind]: string = "SQLiteEffectRaw"
declare readonly _: {
readonly dialect: "sqlite"
readonly result: TResult
}
constructor(
public execute: () => Effect.Effect<TResult, TEffectHKT["error"], TEffectHKT["context"]>,
/** @internal */
public getSQL: () => SQL,
private action: SQLiteEffectRawAction,
private dialect: SQLiteAsyncDialect,
private mapBatchResult: (result: unknown) => unknown,
) {}
getQuery(): Query & { method: SQLiteEffectRawAction } {
return { ...this.dialect.sqlToQuery(this.getSQL()), method: this.action }
}
mapResult(result: unknown, isFromBatch?: boolean) {
return isFromBatch ? this.mapBatchResult(result) : result
}
_prepare(): PreparedQuery {
return this
}
}
applyEffectWrapper(SQLiteEffectRaw)
|