effect-qb 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mysql.js +1957 -595
- package/dist/postgres/metadata.js +2507 -182
- package/dist/postgres.js +9587 -8201
- package/dist/sqlite.js +8360 -0
- package/package.json +7 -2
- package/src/internal/column-state.ts +7 -0
- package/src/internal/column.ts +22 -0
- package/src/internal/derived-table.ts +29 -3
- package/src/internal/dialect.ts +14 -1
- package/src/internal/dsl-mutation-runtime.ts +173 -4
- package/src/internal/dsl-plan-runtime.ts +165 -20
- package/src/internal/dsl-query-runtime.ts +60 -6
- package/src/internal/dsl-transaction-ddl-runtime.ts +72 -2
- package/src/internal/executor.ts +62 -13
- package/src/internal/expression-ast.ts +3 -2
- package/src/internal/grouping-key.ts +141 -1
- package/src/internal/implication-runtime.ts +2 -1
- package/src/internal/json/types.ts +155 -40
- package/src/internal/predicate/analysis.ts +103 -1
- package/src/internal/predicate/atom.ts +7 -0
- package/src/internal/predicate/context.ts +170 -17
- package/src/internal/predicate/key.ts +64 -2
- package/src/internal/predicate/normalize.ts +115 -34
- package/src/internal/predicate/runtime.ts +144 -13
- package/src/internal/query.ts +563 -103
- package/src/internal/renderer.ts +39 -2
- package/src/internal/runtime/driver-value-mapping.ts +244 -0
- package/src/internal/runtime/normalize.ts +62 -38
- package/src/internal/runtime/schema.ts +5 -3
- package/src/internal/runtime/value.ts +153 -30
- package/src/internal/scalar.ts +11 -0
- package/src/internal/table-options.ts +108 -1
- package/src/internal/table.ts +87 -29
- package/src/mysql/column.ts +19 -2
- package/src/mysql/datatypes/index.ts +21 -0
- package/src/mysql/errors/catalog.ts +5 -5
- package/src/mysql/errors/normalize.ts +2 -2
- package/src/mysql/executor.ts +20 -5
- package/src/mysql/internal/dialect.ts +12 -6
- package/src/mysql/internal/dsl.ts +995 -263
- package/src/mysql/internal/renderer.ts +13 -3
- package/src/mysql/internal/sql-expression-renderer.ts +530 -128
- package/src/mysql/query.ts +9 -2
- package/src/mysql/renderer.ts +7 -2
- package/src/mysql/table.ts +38 -12
- package/src/postgres/cast.ts +22 -7
- package/src/postgres/column.ts +5 -2
- package/src/postgres/errors/normalize.ts +2 -2
- package/src/postgres/executor.ts +68 -10
- package/src/postgres/function/core.ts +19 -1
- package/src/postgres/internal/dialect.ts +12 -6
- package/src/postgres/internal/dsl.ts +958 -288
- package/src/postgres/internal/renderer.ts +13 -3
- package/src/postgres/internal/schema-ddl.ts +2 -1
- package/src/postgres/internal/schema-model.ts +6 -3
- package/src/postgres/internal/sql-expression-renderer.ts +477 -96
- package/src/postgres/json.ts +57 -17
- package/src/postgres/query.ts +9 -2
- package/src/postgres/renderer.ts +7 -2
- package/src/postgres/schema-management.ts +91 -4
- package/src/postgres/schema.ts +1 -1
- package/src/postgres/table.ts +189 -53
- package/src/postgres/type.ts +4 -0
- package/src/sqlite/column.ts +128 -0
- package/src/sqlite/datatypes/index.ts +79 -0
- package/src/sqlite/datatypes/spec.ts +98 -0
- package/src/sqlite/errors/catalog.ts +103 -0
- package/src/sqlite/errors/fields.ts +19 -0
- package/src/sqlite/errors/index.ts +19 -0
- package/src/sqlite/errors/normalize.ts +229 -0
- package/src/sqlite/errors/requirements.ts +71 -0
- package/src/sqlite/errors/types.ts +29 -0
- package/src/sqlite/executor.ts +227 -0
- package/src/sqlite/function/aggregate.ts +2 -0
- package/src/sqlite/function/core.ts +2 -0
- package/src/sqlite/function/index.ts +19 -0
- package/src/sqlite/function/string.ts +2 -0
- package/src/sqlite/function/temporal.ts +100 -0
- package/src/sqlite/function/window.ts +2 -0
- package/src/sqlite/internal/dialect.ts +37 -0
- package/src/sqlite/internal/dsl.ts +6926 -0
- package/src/sqlite/internal/renderer.ts +47 -0
- package/src/sqlite/internal/sql-expression-renderer.ts +1821 -0
- package/src/sqlite/json.ts +2 -0
- package/src/sqlite/query.ts +196 -0
- package/src/sqlite/renderer.ts +24 -0
- package/src/sqlite/table.ts +183 -0
- package/src/sqlite.ts +22 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect"
|
|
2
|
+
import * as SqlClient from "@effect/sql/SqlClient"
|
|
3
|
+
import * as Stream from "effect/Stream"
|
|
4
|
+
|
|
5
|
+
import * as CoreExecutor from "../internal/executor.js"
|
|
6
|
+
import * as CoreQuery from "../internal/query.js"
|
|
7
|
+
import * as CoreRenderer from "../internal/renderer.js"
|
|
8
|
+
import type * as Expression from "../internal/scalar.js"
|
|
9
|
+
import { renderSqlitePlan } from "./internal/renderer.js"
|
|
10
|
+
import {
|
|
11
|
+
narrowSqliteDriverErrorForReadQuery,
|
|
12
|
+
normalizeSqliteDriverError,
|
|
13
|
+
type SqliteDriverError,
|
|
14
|
+
type SqliteReadQueryError
|
|
15
|
+
} from "./errors/index.js"
|
|
16
|
+
|
|
17
|
+
/** SQLite-specialized flat row returned by SQL drivers. */
|
|
18
|
+
export type FlatRow = CoreExecutor.FlatRow
|
|
19
|
+
/** Runtime decode failure raised after SQL execution but before row remapping. */
|
|
20
|
+
export type RowDecodeError = CoreExecutor.RowDecodeError
|
|
21
|
+
/** SQLite-specialized rendered-query driver. */
|
|
22
|
+
export type Driver<Error = never, Context = never> = CoreExecutor.Driver<"sqlite", Error, Context>
|
|
23
|
+
/** SQLite-specialized executor contract. */
|
|
24
|
+
export type Executor<Error = never, Context = never> = CoreExecutor.Executor<"sqlite", Error, Context>
|
|
25
|
+
/** SQLite-specialized renderer contract. */
|
|
26
|
+
export type Renderer = CoreRenderer.Renderer<"sqlite">
|
|
27
|
+
/** Optional renderer / driver overrides for the standard SQLite executor pipeline. */
|
|
28
|
+
export interface MakeOptions<Error = never, Context = never> {
|
|
29
|
+
readonly renderer?: Renderer
|
|
30
|
+
readonly driver?: Driver<Error, Context>
|
|
31
|
+
readonly driverMode?: CoreExecutor.DriverMode
|
|
32
|
+
readonly valueMappings?: Expression.DriverValueMappings
|
|
33
|
+
}
|
|
34
|
+
/** Standard composed error shape for SQLite executors. */
|
|
35
|
+
export type SqliteExecutorError = SqliteDriverError | RowDecodeError
|
|
36
|
+
/** Read-query error surface emitted by built-in SQLite executors. */
|
|
37
|
+
export type SqliteQueryError<PlanValue extends CoreQuery.QueryPlan<any, any, any, any, any, any, any, any, any, any>> =
|
|
38
|
+
Exclude<CoreQuery.CapabilitiesOfPlan<PlanValue>, "read"> extends never ? SqliteReadQueryError : SqliteExecutorError
|
|
39
|
+
|
|
40
|
+
/** Runs an effect within the ambient SQLite SQL transaction service. */
|
|
41
|
+
export const withTransaction = CoreExecutor.withTransaction
|
|
42
|
+
/** Runs an effect in a nested SQLite SQL transaction scope. */
|
|
43
|
+
export const withSavepoint = CoreExecutor.withSavepoint
|
|
44
|
+
|
|
45
|
+
/** SQLite executor whose error channel narrows based on the query plan. */
|
|
46
|
+
export interface QueryExecutor<Context = never> {
|
|
47
|
+
readonly dialect: "sqlite"
|
|
48
|
+
execute<PlanValue extends CoreQuery.QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
49
|
+
plan: CoreQuery.DialectCompatiblePlan<PlanValue, "sqlite">
|
|
50
|
+
): Effect.Effect<CoreQuery.ResultRows<PlanValue>, SqliteQueryError<PlanValue>, Context>
|
|
51
|
+
stream<PlanValue extends CoreQuery.QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
52
|
+
plan: Exclude<CoreQuery.CapabilitiesOfPlan<PlanValue>, "read" | "locking"> extends never
|
|
53
|
+
? CoreQuery.DialectCompatiblePlan<PlanValue, "sqlite">
|
|
54
|
+
: never
|
|
55
|
+
): Stream.Stream<CoreQuery.ResultRow<PlanValue>, SqliteQueryError<PlanValue>, Context>
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type DriverExecute<Error, Context> = <Row>(
|
|
59
|
+
query: CoreRenderer.RenderedQuery<Row, "sqlite">
|
|
60
|
+
) => Effect.Effect<ReadonlyArray<FlatRow>, Error, Context>
|
|
61
|
+
|
|
62
|
+
type DriverHandlers<Error, Context> = {
|
|
63
|
+
readonly execute: DriverExecute<Error, Context>
|
|
64
|
+
readonly stream: <Row>(
|
|
65
|
+
query: CoreRenderer.RenderedQuery<Row, "sqlite">
|
|
66
|
+
) => Stream.Stream<FlatRow, Error, Context>
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Constructs a SQLite-specialized SQL driver. */
|
|
70
|
+
export function driver<
|
|
71
|
+
Error = never,
|
|
72
|
+
Context = never
|
|
73
|
+
>(
|
|
74
|
+
execute: DriverExecute<Error, Context>
|
|
75
|
+
): Driver<Error, Context>
|
|
76
|
+
export function driver<
|
|
77
|
+
Error = never,
|
|
78
|
+
Context = never
|
|
79
|
+
>(
|
|
80
|
+
handlers: DriverHandlers<Error, Context>
|
|
81
|
+
): Driver<Error, Context>
|
|
82
|
+
export function driver<
|
|
83
|
+
Error = never,
|
|
84
|
+
Context = never
|
|
85
|
+
>(
|
|
86
|
+
dialect: "sqlite",
|
|
87
|
+
execute: DriverExecute<Error, Context>
|
|
88
|
+
): Driver<Error, Context>
|
|
89
|
+
export function driver<
|
|
90
|
+
Error = never,
|
|
91
|
+
Context = never
|
|
92
|
+
>(
|
|
93
|
+
dialect: "sqlite",
|
|
94
|
+
handlers: DriverHandlers<Error, Context>
|
|
95
|
+
): Driver<Error, Context>
|
|
96
|
+
export function driver<
|
|
97
|
+
Error = never,
|
|
98
|
+
Context = never
|
|
99
|
+
>(
|
|
100
|
+
dialectOrExecute: "sqlite" | DriverExecute<Error, Context> | DriverHandlers<Error, Context>,
|
|
101
|
+
maybeExecute?: DriverExecute<Error, Context> | DriverHandlers<Error, Context>
|
|
102
|
+
): Driver<Error, Context> {
|
|
103
|
+
const executeOrHandlers = typeof dialectOrExecute === "string" ? maybeExecute : dialectOrExecute
|
|
104
|
+
return typeof executeOrHandlers === "function"
|
|
105
|
+
? CoreExecutor.driver("sqlite", executeOrHandlers)
|
|
106
|
+
: CoreExecutor.driver("sqlite", executeOrHandlers as DriverHandlers<Error, Context>)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const fromDriver = <
|
|
110
|
+
Error = never,
|
|
111
|
+
Context = never
|
|
112
|
+
>(
|
|
113
|
+
renderer: Renderer,
|
|
114
|
+
sqlDriver: Driver<Error, Context>,
|
|
115
|
+
driverMode: CoreExecutor.DriverMode = "raw",
|
|
116
|
+
valueMappings?: Expression.DriverValueMappings
|
|
117
|
+
): QueryExecutor<Context> => ({
|
|
118
|
+
dialect: "sqlite",
|
|
119
|
+
execute(plan) {
|
|
120
|
+
const rendered = renderer.render(plan)
|
|
121
|
+
return Effect.mapError(
|
|
122
|
+
Effect.flatMap(
|
|
123
|
+
sqlDriver.execute(rendered),
|
|
124
|
+
(rows) => Effect.try({
|
|
125
|
+
try: () => CoreExecutor.decodeRows(rendered, plan, rows, { driverMode, valueMappings }),
|
|
126
|
+
catch: (error) => error as RowDecodeError
|
|
127
|
+
})
|
|
128
|
+
),
|
|
129
|
+
(error) => {
|
|
130
|
+
if (typeof error === "object" && error !== null && "_tag" in error && error._tag === "RowDecodeError") {
|
|
131
|
+
return error as RowDecodeError
|
|
132
|
+
}
|
|
133
|
+
const normalized = normalizeSqliteDriverError(error, rendered)
|
|
134
|
+
return CoreExecutor.hasWriteCapability(plan)
|
|
135
|
+
? normalized
|
|
136
|
+
: narrowSqliteDriverErrorForReadQuery(normalized)
|
|
137
|
+
}
|
|
138
|
+
) as Effect.Effect<any, any, Context>
|
|
139
|
+
},
|
|
140
|
+
stream(plan) {
|
|
141
|
+
const rendered = renderer.render(plan)
|
|
142
|
+
return Stream.mapError(
|
|
143
|
+
Stream.mapChunksEffect(
|
|
144
|
+
sqlDriver.stream(rendered),
|
|
145
|
+
(rows) => Effect.try({
|
|
146
|
+
try: () => CoreExecutor.decodeChunk(rendered, plan, rows, { driverMode, valueMappings }),
|
|
147
|
+
catch: (error) => error as RowDecodeError
|
|
148
|
+
})
|
|
149
|
+
),
|
|
150
|
+
(error) => {
|
|
151
|
+
if (typeof error === "object" && error !== null && "_tag" in error && error._tag === "RowDecodeError") {
|
|
152
|
+
return error as RowDecodeError
|
|
153
|
+
}
|
|
154
|
+
const normalized = normalizeSqliteDriverError(error, rendered)
|
|
155
|
+
return CoreExecutor.hasWriteCapability(plan)
|
|
156
|
+
? normalized
|
|
157
|
+
: narrowSqliteDriverErrorForReadQuery(normalized)
|
|
158
|
+
}
|
|
159
|
+
) as Stream.Stream<any, any, Context>
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
const sqlClientDriver = (): Driver<any, SqlClient.SqlClient> =>
|
|
164
|
+
driver({
|
|
165
|
+
execute: (query: CoreRenderer.RenderedQuery<any, "sqlite">) =>
|
|
166
|
+
Effect.flatMap(SqlClient.SqlClient, (sql) =>
|
|
167
|
+
sql.unsafe<FlatRow>(query.sql, [...query.params])),
|
|
168
|
+
stream: (query: CoreRenderer.RenderedQuery<any, "sqlite">) =>
|
|
169
|
+
Stream.unwrap(
|
|
170
|
+
Effect.map(
|
|
171
|
+
Effect.flatMap(SqlClient.SqlClient, (sql) =>
|
|
172
|
+
sql.unsafe<FlatRow>(query.sql, [...query.params])),
|
|
173
|
+
(rows) => Stream.fromIterable(rows)
|
|
174
|
+
)
|
|
175
|
+
)
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Creates the standard SQLite executor pipeline.
|
|
180
|
+
*
|
|
181
|
+
* By default this uses the built-in SQLite renderer plus the ambient
|
|
182
|
+
* `@effect/sql` `SqlClient`. Advanced callers can override the renderer,
|
|
183
|
+
* driver, or both.
|
|
184
|
+
*/
|
|
185
|
+
export function make(): QueryExecutor<SqlClient.SqlClient>
|
|
186
|
+
export function make(options: {
|
|
187
|
+
readonly renderer?: Renderer
|
|
188
|
+
readonly driverMode?: CoreExecutor.DriverMode
|
|
189
|
+
readonly valueMappings?: Expression.DriverValueMappings
|
|
190
|
+
}): QueryExecutor<SqlClient.SqlClient>
|
|
191
|
+
export function make<Error = never, Context = never>(
|
|
192
|
+
options: {
|
|
193
|
+
readonly renderer?: Renderer
|
|
194
|
+
readonly driver: Driver<Error, Context>
|
|
195
|
+
readonly driverMode?: CoreExecutor.DriverMode
|
|
196
|
+
readonly valueMappings?: Expression.DriverValueMappings
|
|
197
|
+
}
|
|
198
|
+
): QueryExecutor<Context>
|
|
199
|
+
export function make<Error = never, Context = never>(
|
|
200
|
+
options: MakeOptions<Error, Context> = {}
|
|
201
|
+
): QueryExecutor<any> {
|
|
202
|
+
if (options.driver) {
|
|
203
|
+
return fromDriver(
|
|
204
|
+
options.renderer ?? CoreRenderer.make("sqlite", (plan) => renderSqlitePlan(plan, { valueMappings: options.valueMappings })),
|
|
205
|
+
options.driver,
|
|
206
|
+
options.driverMode,
|
|
207
|
+
options.valueMappings
|
|
208
|
+
)
|
|
209
|
+
}
|
|
210
|
+
return fromDriver(
|
|
211
|
+
options.renderer ?? CoreRenderer.make("sqlite", (plan) => renderSqlitePlan(plan, { valueMappings: options.valueMappings })),
|
|
212
|
+
sqlClientDriver(),
|
|
213
|
+
options.driverMode,
|
|
214
|
+
options.valueMappings
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Creates a SQLite-specialized executor from a typed implementation callback. */
|
|
219
|
+
export const custom = <
|
|
220
|
+
Error = never,
|
|
221
|
+
Context = never
|
|
222
|
+
>(
|
|
223
|
+
execute: <PlanValue extends CoreQuery.QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
224
|
+
plan: CoreQuery.DialectCompatiblePlan<PlanValue, "sqlite">
|
|
225
|
+
) => Effect.Effect<CoreQuery.ResultRows<PlanValue>, Error, Context>
|
|
226
|
+
): Executor<Error, Context> =>
|
|
227
|
+
CoreExecutor.make("sqlite", execute as any) as Executor<Error, Context>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * as core from "./core.js"
|
|
2
|
+
export * as string from "./string.js"
|
|
3
|
+
export * as aggregate from "./aggregate.js"
|
|
4
|
+
export * as window from "./window.js"
|
|
5
|
+
export * as temporal from "./temporal.js"
|
|
6
|
+
|
|
7
|
+
export { coalesce } from "./core.js"
|
|
8
|
+
export { call } from "./core.js"
|
|
9
|
+
export { lower, upper, concat } from "./string.js"
|
|
10
|
+
export { count, max, min } from "./aggregate.js"
|
|
11
|
+
export { over, rowNumber, rank, denseRank } from "./window.js"
|
|
12
|
+
export {
|
|
13
|
+
currentDate,
|
|
14
|
+
currentTime,
|
|
15
|
+
currentTimestamp,
|
|
16
|
+
localTime,
|
|
17
|
+
localTimestamp,
|
|
18
|
+
now
|
|
19
|
+
} from "./temporal.js"
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type * as Schema from "effect/Schema"
|
|
2
|
+
|
|
3
|
+
import type * as Expression from "../../internal/scalar.js"
|
|
4
|
+
import type * as ExpressionAst from "../../internal/expression-ast.js"
|
|
5
|
+
import { makeExpression } from "../../internal/query.js"
|
|
6
|
+
import { sqliteDatatypes } from "../datatypes/index.js"
|
|
7
|
+
import {
|
|
8
|
+
LocalDateStringSchema,
|
|
9
|
+
LocalDateTimeStringSchema,
|
|
10
|
+
LocalTimeStringSchema,
|
|
11
|
+
type LocalDateString,
|
|
12
|
+
type LocalDateTimeString,
|
|
13
|
+
type LocalTimeString
|
|
14
|
+
} from "../../internal/runtime/value.js"
|
|
15
|
+
|
|
16
|
+
type TemporalExpression<
|
|
17
|
+
Runtime,
|
|
18
|
+
Db extends Expression.DbType.Any,
|
|
19
|
+
Name extends string
|
|
20
|
+
> = Expression.Scalar<
|
|
21
|
+
Runtime,
|
|
22
|
+
Db,
|
|
23
|
+
"never",
|
|
24
|
+
"sqlite",
|
|
25
|
+
"scalar",
|
|
26
|
+
never
|
|
27
|
+
> & {
|
|
28
|
+
readonly [ExpressionAst.TypeId]: ExpressionAst.FunctionCallNode<Name, readonly []>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const makeTemporal = <
|
|
32
|
+
Runtime,
|
|
33
|
+
Db extends Expression.DbType.Any,
|
|
34
|
+
Name extends string
|
|
35
|
+
>(
|
|
36
|
+
name: Name,
|
|
37
|
+
dbType: Db,
|
|
38
|
+
runtimeSchema: Schema.Schema<Runtime, any, any>
|
|
39
|
+
): TemporalExpression<Runtime, Db, Name> =>
|
|
40
|
+
makeExpression({
|
|
41
|
+
runtime: undefined as unknown as Runtime,
|
|
42
|
+
dbType,
|
|
43
|
+
runtimeSchema,
|
|
44
|
+
nullability: "never",
|
|
45
|
+
dialect: "sqlite",
|
|
46
|
+
kind: "scalar",
|
|
47
|
+
dependencies: {},
|
|
48
|
+
}, {
|
|
49
|
+
kind: "function",
|
|
50
|
+
name,
|
|
51
|
+
args: []
|
|
52
|
+
}) as TemporalExpression<Runtime, Db, Name>
|
|
53
|
+
|
|
54
|
+
/** SQLite current date. */
|
|
55
|
+
export const currentDate = () =>
|
|
56
|
+
makeTemporal(
|
|
57
|
+
"current_date",
|
|
58
|
+
sqliteDatatypes.date(),
|
|
59
|
+
LocalDateStringSchema
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
/** SQLite current time. */
|
|
63
|
+
export const currentTime = () =>
|
|
64
|
+
makeTemporal(
|
|
65
|
+
"current_time",
|
|
66
|
+
sqliteDatatypes.time(),
|
|
67
|
+
LocalTimeStringSchema
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
/** SQLite current timestamp. */
|
|
71
|
+
export const currentTimestamp = () =>
|
|
72
|
+
makeTemporal(
|
|
73
|
+
"current_timestamp",
|
|
74
|
+
sqliteDatatypes.timestamp(),
|
|
75
|
+
LocalDateTimeStringSchema
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
/** SQLite local time. */
|
|
79
|
+
export const localTime = () =>
|
|
80
|
+
makeTemporal(
|
|
81
|
+
"localtime",
|
|
82
|
+
sqliteDatatypes.time(),
|
|
83
|
+
LocalTimeStringSchema
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
/** SQLite local timestamp. */
|
|
87
|
+
export const localTimestamp = () =>
|
|
88
|
+
makeTemporal(
|
|
89
|
+
"localtimestamp",
|
|
90
|
+
sqliteDatatypes.timestamp(),
|
|
91
|
+
LocalDateTimeStringSchema
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
/** SQLite current instant-like timestamp. */
|
|
95
|
+
export const now = () =>
|
|
96
|
+
makeTemporal(
|
|
97
|
+
"now",
|
|
98
|
+
sqliteDatatypes.timestamp(),
|
|
99
|
+
LocalDateTimeStringSchema
|
|
100
|
+
)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { RenderState, RenderValueContext, SqlDialect } from "../../internal/dialect.js"
|
|
2
|
+
import { toDriverValue } from "../../internal/runtime/driver-value-mapping.js"
|
|
3
|
+
|
|
4
|
+
const quoteIdentifier = (value: string): string => `"${value.replaceAll("\"", "\"\"")}"`
|
|
5
|
+
|
|
6
|
+
const renderLiteral = (value: unknown, state: RenderState, context: RenderValueContext = {}): string => {
|
|
7
|
+
const driverValue = toDriverValue(value, {
|
|
8
|
+
dialect: "sqlite",
|
|
9
|
+
valueMappings: state.valueMappings,
|
|
10
|
+
...context
|
|
11
|
+
})
|
|
12
|
+
if (driverValue === null) {
|
|
13
|
+
return "null"
|
|
14
|
+
}
|
|
15
|
+
state.params.push(driverValue)
|
|
16
|
+
return "?"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Built-in runtime dialect implementation for SQLite.
|
|
21
|
+
*/
|
|
22
|
+
export const sqliteDialect: SqlDialect<"sqlite"> = {
|
|
23
|
+
name: "sqlite",
|
|
24
|
+
quoteIdentifier,
|
|
25
|
+
renderLiteral,
|
|
26
|
+
renderTableReference(tableName, baseTableName, schemaName) {
|
|
27
|
+
const renderedBase = schemaName
|
|
28
|
+
? `${quoteIdentifier(schemaName)}.${quoteIdentifier(baseTableName)}`
|
|
29
|
+
: quoteIdentifier(baseTableName)
|
|
30
|
+
return tableName === baseTableName
|
|
31
|
+
? renderedBase
|
|
32
|
+
: `${renderedBase} as ${quoteIdentifier(tableName)}`
|
|
33
|
+
},
|
|
34
|
+
renderConcat(values) {
|
|
35
|
+
return `(${values.join(" || ")})`
|
|
36
|
+
}
|
|
37
|
+
}
|