effect-qb 4.0.0-beta.66 → 4.0.0-beta.98
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/README.md +5 -2
- package/dist/index.js +9376 -0
- package/dist/mysql.js +3921 -2573
- package/dist/postgres/metadata.js +2491 -1373
- package/dist/postgres.js +5453 -5155
- package/dist/sqlite.js +6895 -5529
- package/dist/standard.js +9330 -0
- package/package.json +9 -2
- package/src/casing.ts +71 -0
- package/src/index.ts +2 -0
- package/src/internal/casing.ts +89 -0
- package/src/internal/coercion/rules.ts +13 -1
- package/src/internal/column-state.ts +21 -15
- package/src/internal/column.ts +44 -7
- package/src/internal/datatypes/define.ts +7 -1
- package/src/internal/datatypes/enrich.ts +23 -0
- package/src/internal/datatypes/lookup.ts +81 -25
- package/src/internal/datatypes/matrix.ts +903 -0
- package/src/internal/datatypes/shape.ts +2 -0
- package/src/internal/derived-table.ts +4 -36
- package/src/{mysql/internal/sql-expression-renderer.ts → internal/dialect-renderers/mysql.ts} +552 -361
- package/src/{postgres/internal/sql-expression-renderer.ts → internal/dialect-renderers/postgres.ts} +657 -400
- package/src/{sqlite/internal/sql-expression-renderer.ts → internal/dialect-renderers/sqlite.ts} +505 -347
- package/src/internal/dialect.ts +35 -0
- package/src/internal/dsl-mutation-runtime.ts +12 -162
- package/src/internal/dsl-plan-runtime.ts +10 -138
- package/src/internal/dsl-query-runtime.ts +5 -79
- package/src/internal/dsl-transaction-ddl-runtime.ts +41 -65
- package/src/internal/executor.ts +14 -16
- package/src/internal/grouping-key.ts +87 -20
- package/src/internal/implication-runtime.ts +1 -1
- package/src/internal/json/path-access.ts +351 -0
- package/src/internal/predicate/runtime.ts +3 -0
- package/src/internal/query.d.ts +38 -11
- package/src/internal/query.ts +64 -25
- package/src/internal/renderer.ts +26 -14
- package/src/internal/runtime/normalize.ts +12 -5
- package/src/internal/scalar.ts +7 -1
- package/src/internal/schema-derivation.d.ts +7 -7
- package/src/internal/schema-derivation.ts +9 -9
- package/src/internal/schema-expression.ts +2 -2
- package/src/internal/sql-expression-renderer.ts +19 -0
- package/src/internal/standard-dsl.ts +6978 -0
- package/src/internal/table-options.ts +126 -66
- package/src/internal/table.ts +652 -219
- package/src/mysql/column-extension.ts +3 -0
- package/src/mysql/column.ts +8 -9
- package/src/mysql/datatypes/index.ts +4 -2
- package/src/mysql/datatypes/spec.ts +6 -176
- package/src/mysql/errors/normalize.ts +0 -1
- package/src/mysql/executor.ts +7 -7
- package/src/mysql/internal/dialect.ts +9 -4
- package/src/mysql/internal/dsl.ts +312 -154
- package/src/mysql/internal/renderer.ts +6 -2
- package/src/mysql/json.ts +7 -2
- package/src/mysql/query-extension.ts +16 -0
- package/src/mysql/renderer.ts +37 -3
- package/src/mysql/type.ts +60 -0
- package/src/mysql.ts +7 -13
- package/src/postgres/check.ts +1 -0
- package/src/postgres/column-extension.ts +28 -0
- package/src/postgres/column.ts +2 -8
- package/src/postgres/datatypes/index.d.ts +2 -1
- package/src/postgres/datatypes/index.ts +4 -2
- package/src/postgres/datatypes/spec.ts +6 -260
- package/src/postgres/errors/normalize.ts +0 -1
- package/src/postgres/executor.ts +7 -7
- package/src/postgres/foreign-key.ts +24 -0
- package/src/postgres/function/core.ts +1 -3
- package/src/postgres/function/index.ts +1 -17
- package/src/postgres/index.ts +1 -0
- package/src/postgres/internal/dialect.ts +9 -4
- package/src/postgres/internal/dsl.ts +306 -163
- package/src/postgres/internal/renderer.ts +6 -2
- package/src/postgres/internal/schema-ddl.ts +22 -10
- package/src/postgres/internal/schema-model.ts +238 -7
- package/src/postgres/json-extension.ts +7 -0
- package/src/postgres/json.ts +762 -173
- package/src/postgres/jsonb.ts +37 -0
- package/src/postgres/primary-key.ts +24 -0
- package/src/postgres/query-extension.ts +2 -0
- package/src/postgres/renderer.ts +37 -3
- package/src/postgres/schema-management.ts +12 -11
- package/src/postgres/schema.ts +106 -15
- package/src/postgres/table.ts +205 -530
- package/src/postgres/type.ts +93 -10
- package/src/postgres/unique.ts +32 -0
- package/src/postgres.ts +20 -16
- package/src/sqlite/column-extension.ts +3 -0
- package/src/sqlite/column.ts +8 -9
- package/src/sqlite/datatypes/index.ts +4 -2
- package/src/sqlite/datatypes/spec.ts +6 -94
- package/src/sqlite/errors/normalize.ts +0 -1
- package/src/sqlite/executor.ts +7 -7
- package/src/sqlite/internal/dialect.ts +9 -4
- package/src/sqlite/internal/dsl.ts +301 -154
- package/src/sqlite/internal/renderer.ts +6 -2
- package/src/sqlite/json.ts +8 -2
- package/src/sqlite/query-extension.ts +2 -0
- package/src/sqlite/renderer.ts +37 -3
- package/src/sqlite/type.ts +40 -0
- package/src/sqlite.ts +7 -13
- package/src/standard/cast.ts +113 -0
- package/src/standard/check.ts +17 -0
- package/src/standard/column.ts +163 -0
- package/src/standard/datatypes/index.ts +83 -0
- package/src/standard/datatypes/spec.ts +12 -0
- package/src/standard/dialect.ts +40 -0
- package/src/standard/foreign-key.ts +37 -0
- package/src/standard/function/aggregate.ts +2 -0
- package/src/standard/function/core.ts +2 -0
- package/src/standard/function/index.ts +18 -0
- package/src/standard/function/string.ts +2 -0
- package/src/standard/function/temporal.ts +78 -0
- package/src/standard/function/window.ts +2 -0
- package/src/standard/index.ts +17 -0
- package/src/standard/internal/renderer.ts +45 -0
- package/src/standard/json.ts +883 -0
- package/src/standard/primary-key.ts +17 -0
- package/src/standard/query.ts +152 -0
- package/src/standard/renderer.ts +49 -0
- package/src/standard/table.ts +151 -0
- package/src/standard/unique.ts +17 -0
- package/src/standard.ts +32 -0
- package/src/internal/aggregation-validation.ts +0 -57
- package/src/internal/table.d.ts +0 -180
- package/src/mysql/table.ts +0 -186
- package/src/postgres/cast.ts +0 -45
- package/src/sqlite/table.ts +0 -175
package/src/postgres/type.ts
CHANGED
|
@@ -1,35 +1,118 @@
|
|
|
1
1
|
import type * as Expression from "../internal/scalar.js"
|
|
2
|
+
import type { NonEmptyStringInput } from "../internal/table-options.js"
|
|
3
|
+
import {
|
|
4
|
+
pickDatatypeConstructors,
|
|
5
|
+
postgresSpecificDatatypeKeys,
|
|
6
|
+
type PostgresSpecificDatatypeKey
|
|
7
|
+
} from "../internal/datatypes/matrix.js"
|
|
2
8
|
import { postgresDatatypes } from "./datatypes/index.js"
|
|
3
|
-
import { type as postgresType } from "./internal/dsl.js"
|
|
4
9
|
|
|
5
|
-
type
|
|
10
|
+
type PostgresSpecificDatatypes = Pick<typeof postgresDatatypes, PostgresSpecificDatatypeKey>
|
|
11
|
+
|
|
12
|
+
type PostgresTypeNamespace = PostgresSpecificDatatypes & {
|
|
6
13
|
readonly array: <Element extends Expression.DbType.Any>(
|
|
7
14
|
element: Element
|
|
8
15
|
) => Expression.DbType.Array<"postgres", Element, `${Element["kind"]}[]`>
|
|
9
16
|
readonly range: <Kind extends string, Subtype extends Expression.DbType.Any>(
|
|
10
|
-
kind: Kind
|
|
17
|
+
kind: NonEmptyStringInput<Kind>,
|
|
11
18
|
subtype: Subtype
|
|
12
19
|
) => Expression.DbType.Range<"postgres", Subtype, Kind>
|
|
13
20
|
readonly multirange: <Kind extends string, Subtype extends Expression.DbType.Any>(
|
|
14
|
-
kind: Kind
|
|
21
|
+
kind: NonEmptyStringInput<Kind>,
|
|
15
22
|
subtype: Subtype
|
|
16
23
|
) => Expression.DbType.Multirange<"postgres", Subtype, Kind>
|
|
17
24
|
readonly record: <Kind extends string, Fields extends Record<string, Expression.DbType.Any>>(
|
|
18
|
-
kind: Kind
|
|
25
|
+
kind: NonEmptyStringInput<Kind>,
|
|
19
26
|
fields: Fields
|
|
20
27
|
) => Expression.DbType.Composite<"postgres", Fields, Kind>
|
|
21
28
|
readonly domain: <Kind extends string, Base extends Expression.DbType.Any>(
|
|
22
|
-
kind: Kind
|
|
29
|
+
kind: NonEmptyStringInput<Kind>,
|
|
23
30
|
base: Base
|
|
24
31
|
) => Expression.DbType.Domain<"postgres", Base, Kind>
|
|
25
|
-
readonly enum: <Kind extends string>(kind: Kind) => Expression.DbType.Enum<"postgres", Kind>
|
|
26
|
-
readonly
|
|
27
|
-
readonly custom: <Kind extends string>(kind: Kind) => Expression.DbType.Base<"postgres", Kind>
|
|
32
|
+
readonly enum: <Kind extends string>(kind: NonEmptyStringInput<Kind>) => Expression.DbType.Enum<"postgres", Kind>
|
|
33
|
+
readonly custom: <Kind extends string>(kind: NonEmptyStringInput<Kind>) => Expression.DbType.Base<"postgres", Kind>
|
|
28
34
|
readonly driverValueMapping: <Db extends Expression.DbType.Any>(
|
|
29
35
|
dbType: Db,
|
|
30
36
|
mapping: Expression.DriverValueMapping
|
|
31
37
|
) => Db
|
|
32
38
|
}
|
|
33
39
|
|
|
40
|
+
const array = <Element extends Expression.DbType.Any>(
|
|
41
|
+
element: Element
|
|
42
|
+
): Expression.DbType.Array<"postgres", Element, `${Element["kind"]}[]`> => ({
|
|
43
|
+
dialect: "postgres",
|
|
44
|
+
kind: `${element.kind}[]`,
|
|
45
|
+
element
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const range = <Kind extends string, Subtype extends Expression.DbType.Any>(
|
|
49
|
+
kind: NonEmptyStringInput<Kind>,
|
|
50
|
+
subtype: Subtype
|
|
51
|
+
): Expression.DbType.Range<"postgres", Subtype, Kind> => ({
|
|
52
|
+
dialect: "postgres",
|
|
53
|
+
kind: kind as Kind,
|
|
54
|
+
subtype
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const multirange = <Kind extends string, Subtype extends Expression.DbType.Any>(
|
|
58
|
+
kind: NonEmptyStringInput<Kind>,
|
|
59
|
+
subtype: Subtype
|
|
60
|
+
): Expression.DbType.Multirange<"postgres", Subtype, Kind> => ({
|
|
61
|
+
dialect: "postgres",
|
|
62
|
+
kind: kind as Kind,
|
|
63
|
+
subtype
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
const record = <Kind extends string, Fields extends Record<string, Expression.DbType.Any>>(
|
|
67
|
+
kind: NonEmptyStringInput<Kind>,
|
|
68
|
+
fields: Fields
|
|
69
|
+
): Expression.DbType.Composite<"postgres", Fields, Kind> => ({
|
|
70
|
+
dialect: "postgres",
|
|
71
|
+
kind: kind as Kind,
|
|
72
|
+
fields
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
const domain = <Kind extends string, Base extends Expression.DbType.Any>(
|
|
76
|
+
kind: NonEmptyStringInput<Kind>,
|
|
77
|
+
base: Base
|
|
78
|
+
): Expression.DbType.Domain<"postgres", Base, Kind> => ({
|
|
79
|
+
dialect: "postgres",
|
|
80
|
+
kind: kind as Kind,
|
|
81
|
+
base
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
const enum_ = <Kind extends string>(
|
|
85
|
+
kind: NonEmptyStringInput<Kind>
|
|
86
|
+
): Expression.DbType.Enum<"postgres", Kind> => ({
|
|
87
|
+
dialect: "postgres",
|
|
88
|
+
kind: kind as Kind,
|
|
89
|
+
variant: "enum"
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
const custom = <Kind extends string>(
|
|
93
|
+
kind: NonEmptyStringInput<Kind>
|
|
94
|
+
): Expression.DbType.Base<"postgres", Kind> => ({
|
|
95
|
+
dialect: "postgres",
|
|
96
|
+
kind: kind as Kind
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
const driverValueMapping = <Db extends Expression.DbType.Any>(
|
|
100
|
+
dbType: Db,
|
|
101
|
+
mapping: Expression.DriverValueMapping
|
|
102
|
+
): Db => ({
|
|
103
|
+
...dbType,
|
|
104
|
+
driverValueMapping: mapping
|
|
105
|
+
})
|
|
106
|
+
|
|
34
107
|
/** Postgres database-type constructors for casts and typed column references. */
|
|
35
|
-
export const type: PostgresTypeNamespace =
|
|
108
|
+
export const type: PostgresTypeNamespace = {
|
|
109
|
+
...pickDatatypeConstructors(postgresDatatypes, postgresSpecificDatatypeKeys),
|
|
110
|
+
array,
|
|
111
|
+
range,
|
|
112
|
+
multirange,
|
|
113
|
+
record,
|
|
114
|
+
domain,
|
|
115
|
+
enum: enum_,
|
|
116
|
+
custom,
|
|
117
|
+
driverValueMapping
|
|
118
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as BaseTable from "../internal/table.js"
|
|
2
|
+
import type { TableOptionSpec } from "../internal/table-options.js"
|
|
3
|
+
|
|
4
|
+
type UniqueSpec = Extract<TableOptionSpec, { readonly kind: "unique" }>
|
|
5
|
+
|
|
6
|
+
export const deferrable = <Spec extends UniqueSpec, TableContext extends BaseTable.TableDefinition<any, any, any, "schema", any>>(
|
|
7
|
+
option: BaseTable.TableOption<Spec, TableContext>
|
|
8
|
+
): BaseTable.TableOption<Spec & { readonly deferrable: true }, TableContext> =>
|
|
9
|
+
BaseTable.mapOption(option, (spec) => ({
|
|
10
|
+
...spec,
|
|
11
|
+
deferrable: true
|
|
12
|
+
} as Spec & { readonly deferrable: true }))
|
|
13
|
+
|
|
14
|
+
export const initiallyDeferred = <Spec extends UniqueSpec, TableContext extends BaseTable.TableDefinition<any, any, any, "schema", any>>(
|
|
15
|
+
option: BaseTable.TableOption<Spec, TableContext>
|
|
16
|
+
): BaseTable.TableOption<Spec & {
|
|
17
|
+
readonly deferrable: true
|
|
18
|
+
readonly initiallyDeferred: true
|
|
19
|
+
}, TableContext> =>
|
|
20
|
+
BaseTable.mapOption(option, (spec) => ({
|
|
21
|
+
...spec,
|
|
22
|
+
deferrable: true,
|
|
23
|
+
initiallyDeferred: true
|
|
24
|
+
} as Spec & { readonly deferrable: true; readonly initiallyDeferred: true }))
|
|
25
|
+
|
|
26
|
+
export const nullsNotDistinct = <Spec extends UniqueSpec, TableContext extends BaseTable.TableDefinition<any, any, any, "schema", any>>(
|
|
27
|
+
option: BaseTable.TableOption<Spec, TableContext>
|
|
28
|
+
): BaseTable.TableOption<Spec & { readonly nullsNotDistinct: true }, TableContext> =>
|
|
29
|
+
BaseTable.mapOption(option, (spec) => ({
|
|
30
|
+
...spec,
|
|
31
|
+
nullsNotDistinct: true
|
|
32
|
+
} as Spec & { readonly nullsNotDistinct: true }))
|
package/src/postgres.ts
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
/** Postgres-
|
|
2
|
-
export * as Column from "./postgres/column.js"
|
|
1
|
+
/** Postgres-specific column extensions. Portable columns are exported from `effect-qb`. */
|
|
2
|
+
export * as Column from "./postgres/column-extension.js"
|
|
3
3
|
/** Postgres datatype witnesses and coercion families. */
|
|
4
4
|
export * as Datatypes from "./postgres/datatypes/index.js"
|
|
5
5
|
/** Postgres SQLSTATE catalog and error normalization helpers. */
|
|
6
6
|
export * as Errors from "./postgres/errors/index.js"
|
|
7
|
-
/**
|
|
8
|
-
export * as Scalar from "./internal/scalar.js"
|
|
9
|
-
/** Postgres cast helpers. */
|
|
10
|
-
export { cast as Cast } from "./postgres/cast.js"
|
|
11
|
-
/** Postgres-specialized SQL function expressions. */
|
|
7
|
+
/** Postgres-specific SQL function expressions. Portable functions are exported from the root package. */
|
|
12
8
|
export * as Function from "./postgres/function/index.js"
|
|
13
|
-
/** Postgres-
|
|
14
|
-
export * as Json from "./postgres/json.js"
|
|
9
|
+
/** Postgres-specific JSON expression helpers. Portable JSON helpers are exported from the root package. */
|
|
10
|
+
export * as Json from "./postgres/json-extension.js"
|
|
11
|
+
/** Postgres jsonb-only expression helpers. */
|
|
12
|
+
export * as Jsonb from "./postgres/jsonb.js"
|
|
15
13
|
/** Postgres-specialized typed query execution contracts. */
|
|
16
14
|
export * as Executor from "./postgres/executor.js"
|
|
17
|
-
/**
|
|
18
|
-
export * as
|
|
19
|
-
/** Postgres-specialized query-construction DSL. */
|
|
20
|
-
export * as Query from "./postgres/query.js"
|
|
15
|
+
/** Postgres-specific query helpers. Portable queries are exported from the root package. */
|
|
16
|
+
export * as Query from "./postgres/query-extension.js"
|
|
21
17
|
/** Postgres database-type constructors for casts and typed references. */
|
|
22
18
|
export { type as Type } from "./postgres/type.js"
|
|
23
19
|
/** Postgres normalized table/enum metadata helpers. */
|
|
@@ -25,12 +21,20 @@ export * as Metadata from "./postgres/metadata.js"
|
|
|
25
21
|
/** Postgres schema-expression helpers for DDL-only metadata. */
|
|
26
22
|
export * as SchemaExpression from "./postgres/schema-expression.js"
|
|
27
23
|
/** Postgres schema-scoped table and enum builder helpers. */
|
|
28
|
-
export
|
|
24
|
+
export * as Schema from "./postgres/schema.js"
|
|
29
25
|
export type { SchemaNamespace } from "./postgres/schema.js"
|
|
30
26
|
/** Postgres enum and sequence definition helpers. */
|
|
31
27
|
export { enumType as enum, sequence } from "./postgres/schema-management.js"
|
|
32
28
|
export type { EnumDefinition, SequenceDefinition } from "./postgres/schema-management.js"
|
|
33
|
-
/** Postgres-
|
|
34
|
-
export * as
|
|
29
|
+
/** Postgres-specific primary-key option modifiers. */
|
|
30
|
+
export * as PrimaryKey from "./postgres/primary-key.js"
|
|
31
|
+
/** Postgres-specific unique-constraint option modifiers. */
|
|
32
|
+
export * as Unique from "./postgres/unique.js"
|
|
33
|
+
/** Postgres-specific index option modifiers. */
|
|
34
|
+
export * as Index from "./postgres/index.js"
|
|
35
|
+
/** Postgres-specific foreign-key option modifiers. */
|
|
36
|
+
export * as ForeignKey from "./postgres/foreign-key.js"
|
|
37
|
+
/** Postgres-specific check-constraint option modifiers. */
|
|
38
|
+
export * as Check from "./postgres/check.js"
|
|
35
39
|
/** Postgres-specialized built-in renderer entrypoint. */
|
|
36
40
|
export * as Renderer from "./postgres/renderer.js"
|
package/src/sqlite/column.ts
CHANGED
|
@@ -3,6 +3,8 @@ import * as Schema from "effect/Schema"
|
|
|
3
3
|
import * as BaseColumn from "../internal/column.js"
|
|
4
4
|
import { makeColumnDefinition, type AnyColumnDefinition, type ColumnDefinition } from "../internal/column-state.js"
|
|
5
5
|
import type * as Expression from "../internal/scalar.js"
|
|
6
|
+
import type { NonEmptyStringInput } from "../internal/table-options.js"
|
|
7
|
+
import { enrichDbType } from "../internal/datatypes/enrich.js"
|
|
6
8
|
import {
|
|
7
9
|
DecimalStringSchema,
|
|
8
10
|
LocalDateStringSchema,
|
|
@@ -15,13 +17,6 @@ import {
|
|
|
15
17
|
} from "../internal/runtime/value.js"
|
|
16
18
|
import { sqliteDatatypes } from "./datatypes/index.js"
|
|
17
19
|
|
|
18
|
-
const enrichDbType = <Db extends Expression.DbType.Any>(dbType: Db): Db => {
|
|
19
|
-
const candidate = (sqliteDatatypes as unknown as Record<string, (() => Expression.DbType.Any) | undefined>)[dbType.kind]
|
|
20
|
-
return typeof candidate === "function"
|
|
21
|
-
? { ...candidate(), ...dbType } as Db
|
|
22
|
-
: dbType
|
|
23
|
-
}
|
|
24
|
-
|
|
25
20
|
const primitive = <Type, Db extends Expression.DbType.Any>(
|
|
26
21
|
schema: Schema.Schema<Type>,
|
|
27
22
|
dbType: Db
|
|
@@ -53,7 +48,7 @@ export const custom = <SchemaType extends Schema.Top, Db extends Expression.DbTy
|
|
|
53
48
|
dbType: Db
|
|
54
49
|
) =>
|
|
55
50
|
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>>, {
|
|
56
|
-
dbType: enrichDbType(dbType),
|
|
51
|
+
dbType: enrichDbType(sqliteDatatypes, dbType),
|
|
57
52
|
nullable: false,
|
|
58
53
|
hasDefault: false,
|
|
59
54
|
generated: false,
|
|
@@ -109,10 +104,14 @@ type SqliteUniqueOptions = {
|
|
|
109
104
|
readonly initiallyDeferred?: never
|
|
110
105
|
}
|
|
111
106
|
|
|
107
|
+
type NonEmptyOptionNameInput<Options> = Options extends { readonly name: infer Name extends string }
|
|
108
|
+
? NonEmptyStringInput<Name> extends never ? never : unknown
|
|
109
|
+
: unknown
|
|
110
|
+
|
|
112
111
|
type UniqueModifier = {
|
|
113
112
|
<Column extends AnyColumnDefinition>(column: Column): UniqueColumn<Column>
|
|
114
113
|
readonly options: <const Options extends SqliteUniqueOptions>(
|
|
115
|
-
options: Options
|
|
114
|
+
options: Options & NonEmptyOptionNameInput<Options>
|
|
116
115
|
) => <Column extends AnyColumnDefinition>(column: Column) => UniqueColumn<Column>
|
|
117
116
|
}
|
|
118
117
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DatatypeModule } from "../../internal/datatypes/define.js"
|
|
2
2
|
import type * as Expression from "../../internal/scalar.js"
|
|
3
|
+
import type { NonEmptyStringInput } from "../../internal/table-options.js"
|
|
3
4
|
import { sqliteDatatypeFamilies, sqliteDatatypeKinds } from "./spec.js"
|
|
4
5
|
|
|
5
6
|
const withMetadata = <Kind extends keyof typeof sqliteDatatypeKinds & string>(
|
|
@@ -14,14 +15,15 @@ const withMetadata = <Kind extends keyof typeof sqliteDatatypeKinds & string>(
|
|
|
14
15
|
runtime: kindSpec.runtime,
|
|
15
16
|
compareGroup: familySpec?.compareGroup,
|
|
16
17
|
castTargets: familySpec?.castTargets,
|
|
18
|
+
implicitTargets: (familySpec as { readonly implicitTargets?: readonly string[] }).implicitTargets,
|
|
17
19
|
traits: familySpec?.traits
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
const sqliteDatatypeModule = {
|
|
22
|
-
custom: (kind:
|
|
24
|
+
custom: <Kind extends string>(kind: NonEmptyStringInput<Kind>) => ({
|
|
23
25
|
dialect: "sqlite",
|
|
24
|
-
kind
|
|
26
|
+
kind: kind as Kind
|
|
25
27
|
}),
|
|
26
28
|
uuid: () => ({
|
|
27
29
|
dialect: "sqlite",
|
|
@@ -1,98 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
sqliteDatatypeFamilies as matrixSqliteDatatypeFamilies,
|
|
3
|
+
sqliteDatatypeKinds as matrixSqliteDatatypeKinds
|
|
4
|
+
} from "../../internal/datatypes/matrix.js"
|
|
2
5
|
|
|
3
|
-
export const sqliteDatatypeFamilies =
|
|
4
|
-
|
|
5
|
-
compareGroup: "text",
|
|
6
|
-
castTargets: ["text", "numeric", "integer", "real", "boolean", "date", "time", "datetime", "json", "blob", "null"],
|
|
7
|
-
traits: {
|
|
8
|
-
textual: true,
|
|
9
|
-
ordered: true
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
numeric: {
|
|
13
|
-
compareGroup: "numeric",
|
|
14
|
-
castTargets: ["numeric", "integer", "real", "text", "boolean", "date", "time", "datetime"],
|
|
15
|
-
traits: {
|
|
16
|
-
ordered: true
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
integer: {
|
|
20
|
-
compareGroup: "numeric",
|
|
21
|
-
castTargets: ["integer", "numeric", "real", "text", "boolean", "date", "time", "datetime"],
|
|
22
|
-
traits: {
|
|
23
|
-
ordered: true
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
real: {
|
|
27
|
-
compareGroup: "numeric",
|
|
28
|
-
castTargets: ["real", "numeric", "integer", "text", "boolean"],
|
|
29
|
-
traits: {
|
|
30
|
-
ordered: true
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
boolean: {
|
|
34
|
-
compareGroup: "boolean",
|
|
35
|
-
castTargets: ["boolean", "integer", "numeric", "text"],
|
|
36
|
-
traits: {}
|
|
37
|
-
},
|
|
38
|
-
date: {
|
|
39
|
-
compareGroup: "date",
|
|
40
|
-
castTargets: ["date", "time", "datetime", "text", "numeric", "integer"],
|
|
41
|
-
traits: {
|
|
42
|
-
ordered: true
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
time: {
|
|
46
|
-
compareGroup: "time",
|
|
47
|
-
castTargets: ["time", "date", "datetime", "text", "numeric", "integer"],
|
|
48
|
-
traits: {
|
|
49
|
-
ordered: true
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
datetime: {
|
|
53
|
-
compareGroup: "datetime",
|
|
54
|
-
castTargets: ["datetime", "date", "time", "text", "numeric", "integer"],
|
|
55
|
-
traits: {
|
|
56
|
-
ordered: true
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
json: {
|
|
60
|
-
compareGroup: "json",
|
|
61
|
-
castTargets: ["json", "text"],
|
|
62
|
-
traits: {}
|
|
63
|
-
},
|
|
64
|
-
blob: {
|
|
65
|
-
compareGroup: "blob",
|
|
66
|
-
castTargets: ["blob", "text"],
|
|
67
|
-
traits: {}
|
|
68
|
-
},
|
|
69
|
-
null: {
|
|
70
|
-
compareGroup: "null",
|
|
71
|
-
castTargets: ["text", "numeric", "integer", "real", "boolean", "date", "time", "datetime", "json", "blob", "null"],
|
|
72
|
-
traits: {}
|
|
73
|
-
}
|
|
74
|
-
} as const satisfies Record<string, DatatypeFamilySpec>
|
|
75
|
-
|
|
76
|
-
export const sqliteDatatypeKinds = {
|
|
77
|
-
text: { family: "text", runtime: "string" },
|
|
78
|
-
varchar: { family: "text", runtime: "string" },
|
|
79
|
-
char: { family: "text", runtime: "string" },
|
|
80
|
-
clob: { family: "text", runtime: "string" },
|
|
81
|
-
int: { family: "integer", runtime: "number" },
|
|
82
|
-
integer: { family: "integer", runtime: "number" },
|
|
83
|
-
bigint: { family: "integer", runtime: "bigintString" },
|
|
84
|
-
numeric: { family: "numeric", runtime: "decimalString" },
|
|
85
|
-
decimal: { family: "numeric", runtime: "decimalString" },
|
|
86
|
-
real: { family: "real", runtime: "number" },
|
|
87
|
-
double: { family: "real", runtime: "number" },
|
|
88
|
-
boolean: { family: "boolean", runtime: "boolean" },
|
|
89
|
-
date: { family: "date", runtime: "localDate" },
|
|
90
|
-
time: { family: "time", runtime: "localTime" },
|
|
91
|
-
datetime: { family: "datetime", runtime: "localDateTime" },
|
|
92
|
-
timestamp: { family: "datetime", runtime: "localDateTime" },
|
|
93
|
-
json: { family: "json", runtime: "json" },
|
|
94
|
-
blob: { family: "blob", runtime: "bytes" }
|
|
95
|
-
} as const satisfies Record<string, DatatypeKindSpec>
|
|
6
|
+
export const sqliteDatatypeFamilies = matrixSqliteDatatypeFamilies
|
|
7
|
+
export const sqliteDatatypeKinds = matrixSqliteDatatypeKinds
|
|
96
8
|
|
|
97
9
|
export type SqliteDatatypeFamily = keyof typeof sqliteDatatypeFamilies
|
|
98
10
|
export type SqliteDatatypeKind = keyof typeof sqliteDatatypeKinds
|
package/src/sqlite/executor.ts
CHANGED
|
@@ -6,6 +6,7 @@ import * as CoreExecutor from "../internal/executor.js"
|
|
|
6
6
|
import * as CoreQuery from "../internal/query.js"
|
|
7
7
|
import * as CoreRenderer from "../internal/renderer.js"
|
|
8
8
|
import type * as Expression from "../internal/scalar.js"
|
|
9
|
+
import type { SqliteDatatypeFamily, SqliteDatatypeKind } from "./datatypes/spec.js"
|
|
9
10
|
import { renderSqlitePlan } from "./internal/renderer.js"
|
|
10
11
|
import {
|
|
11
12
|
narrowSqliteDriverErrorForReadQuery,
|
|
@@ -24,12 +25,13 @@ export type Driver<Error = never, Context = never> = CoreExecutor.Driver<"sqlite
|
|
|
24
25
|
export type Executor<Error = never, Context = never> = CoreExecutor.Executor<"sqlite", Error, Context>
|
|
25
26
|
/** SQLite-specialized renderer contract. */
|
|
26
27
|
export type Renderer = CoreRenderer.Renderer<"sqlite">
|
|
28
|
+
export type ValueMappings = Expression.DriverValueMappingsFor<SqliteDatatypeKind | "uuid", SqliteDatatypeFamily | "uuid">
|
|
27
29
|
/** Optional renderer / driver overrides for the standard SQLite executor pipeline. */
|
|
28
30
|
export interface MakeOptions<Error = never, Context = never> {
|
|
29
31
|
readonly renderer?: Renderer
|
|
30
32
|
readonly driver?: Driver<Error, Context>
|
|
31
33
|
readonly driverMode?: CoreExecutor.DriverMode
|
|
32
|
-
readonly valueMappings?:
|
|
34
|
+
readonly valueMappings?: ValueMappings
|
|
33
35
|
}
|
|
34
36
|
/** Standard composed error shape for SQLite executors. */
|
|
35
37
|
export type SqliteExecutorError = SqliteDriverError | RowDecodeError
|
|
@@ -39,8 +41,6 @@ export type SqliteQueryError<PlanValue extends CoreQuery.QueryPlan<any, any, any
|
|
|
39
41
|
|
|
40
42
|
/** Runs an effect within the ambient SQLite SQL transaction service. */
|
|
41
43
|
export const withTransaction = CoreExecutor.withTransaction
|
|
42
|
-
/** Runs an effect in a nested SQLite SQL transaction scope. */
|
|
43
|
-
export const withSavepoint = CoreExecutor.withSavepoint
|
|
44
44
|
|
|
45
45
|
/** SQLite executor whose error channel narrows based on the query plan. */
|
|
46
46
|
export interface QueryExecutor<Context = never> {
|
|
@@ -186,14 +186,14 @@ export function make(): QueryExecutor<SqlClient.SqlClient>
|
|
|
186
186
|
export function make(options: {
|
|
187
187
|
readonly renderer?: Renderer
|
|
188
188
|
readonly driverMode?: CoreExecutor.DriverMode
|
|
189
|
-
readonly valueMappings?:
|
|
189
|
+
readonly valueMappings?: ValueMappings
|
|
190
190
|
}): QueryExecutor<SqlClient.SqlClient>
|
|
191
191
|
export function make<Error = never, Context = never>(
|
|
192
192
|
options: {
|
|
193
193
|
readonly renderer?: Renderer
|
|
194
194
|
readonly driver: Driver<Error, Context>
|
|
195
195
|
readonly driverMode?: CoreExecutor.DriverMode
|
|
196
|
-
readonly valueMappings?:
|
|
196
|
+
readonly valueMappings?: ValueMappings
|
|
197
197
|
}
|
|
198
198
|
): QueryExecutor<Context>
|
|
199
199
|
export function make<Error = never, Context = never>(
|
|
@@ -201,14 +201,14 @@ export function make<Error = never, Context = never>(
|
|
|
201
201
|
): QueryExecutor<any> {
|
|
202
202
|
if (options.driver) {
|
|
203
203
|
return fromDriver(
|
|
204
|
-
options.renderer ?? CoreRenderer.
|
|
204
|
+
options.renderer ?? CoreRenderer.makeTrusted("sqlite", (plan) => renderSqlitePlan(plan, { valueMappings: options.valueMappings })),
|
|
205
205
|
options.driver,
|
|
206
206
|
options.driverMode,
|
|
207
207
|
options.valueMappings
|
|
208
208
|
)
|
|
209
209
|
}
|
|
210
210
|
return fromDriver(
|
|
211
|
-
options.renderer ?? CoreRenderer.
|
|
211
|
+
options.renderer ?? CoreRenderer.makeTrusted("sqlite", (plan) => renderSqlitePlan(plan, { valueMappings: options.valueMappings })),
|
|
212
212
|
sqlClientDriver(),
|
|
213
213
|
options.driverMode,
|
|
214
214
|
options.valueMappings
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { quoteDoubleQuotedIdentifier, type RenderState, type RenderValueContext, type SqlDialect } from "../../internal/dialect.js"
|
|
2
|
+
import { renderExpression, renderQueryAst } from "../../internal/dialect-renderers/sqlite.js"
|
|
2
3
|
import { toDriverValue } from "../../internal/runtime/driver-value-mapping.js"
|
|
4
|
+
import { standardDialect } from "../../standard/dialect.js"
|
|
3
5
|
|
|
4
|
-
const quoteIdentifier =
|
|
6
|
+
const quoteIdentifier = quoteDoubleQuotedIdentifier
|
|
5
7
|
|
|
6
8
|
const renderLiteral = (value: unknown, state: RenderState, context: RenderValueContext = {}): string => {
|
|
7
9
|
const driverValue = toDriverValue(value, {
|
|
@@ -20,11 +22,12 @@ const renderLiteral = (value: unknown, state: RenderState, context: RenderValueC
|
|
|
20
22
|
* Built-in runtime dialect implementation for SQLite.
|
|
21
23
|
*/
|
|
22
24
|
export const sqliteDialect: SqlDialect<"sqlite"> = {
|
|
25
|
+
...standardDialect,
|
|
23
26
|
name: "sqlite",
|
|
24
27
|
quoteIdentifier,
|
|
25
28
|
renderLiteral,
|
|
26
29
|
renderTableReference(tableName, baseTableName, schemaName) {
|
|
27
|
-
const renderedBase = schemaName
|
|
30
|
+
const renderedBase = schemaName && schemaName !== "public"
|
|
28
31
|
? `${quoteIdentifier(schemaName)}.${quoteIdentifier(baseTableName)}`
|
|
29
32
|
: quoteIdentifier(baseTableName)
|
|
30
33
|
return tableName === baseTableName
|
|
@@ -33,5 +36,7 @@ export const sqliteDialect: SqlDialect<"sqlite"> = {
|
|
|
33
36
|
},
|
|
34
37
|
renderConcat(values) {
|
|
35
38
|
return `(${values.join(" || ")})`
|
|
36
|
-
}
|
|
39
|
+
},
|
|
40
|
+
renderQueryAst,
|
|
41
|
+
renderExpression
|
|
37
42
|
}
|