effect-qb 0.16.0 → 0.19.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/README.md +4 -0
- package/dist/index.js +8065 -0
- package/dist/mysql.js +4036 -2418
- package/dist/postgres/metadata.js +2536 -625
- package/dist/postgres.js +8248 -7857
- package/dist/sqlite.js +8854 -0
- package/dist/standard.js +8019 -0
- package/package.json +15 -3
- package/src/casing.ts +71 -0
- package/src/index.ts +2 -0
- package/src/internal/casing.ts +89 -0
- package/src/internal/column-state.ts +11 -6
- package/src/internal/column.ts +44 -7
- package/src/internal/datatypes/define.ts +2 -1
- package/src/internal/datatypes/enrich.ts +23 -0
- package/src/internal/datatypes/lookup.ts +14 -7
- package/src/internal/derived-table.ts +7 -13
- package/src/internal/dialect-renderers/mysql.ts +2046 -0
- package/src/{postgres/internal/sql-expression-renderer.ts → internal/dialect-renderers/postgres.ts} +867 -283
- package/src/{mysql/internal/sql-expression-renderer.ts → internal/dialect-renderers/sqlite.ts} +834 -358
- package/src/internal/dialect.ts +37 -0
- package/src/internal/dsl-mutation-runtime.ts +29 -10
- package/src/internal/dsl-plan-runtime.ts +41 -24
- package/src/internal/dsl-query-runtime.ts +11 -31
- package/src/internal/dsl-transaction-ddl-runtime.ts +61 -15
- package/src/internal/executor.ts +57 -15
- package/src/internal/expression-ast.ts +3 -2
- package/src/internal/grouping-key.ts +216 -9
- package/src/internal/implication-runtime.ts +3 -2
- package/src/internal/json/types.ts +155 -40
- package/src/internal/predicate/context.ts +14 -1
- package/src/internal/predicate/key.ts +19 -2
- package/src/internal/predicate/runtime.ts +30 -3
- package/src/internal/query.d.ts +38 -11
- package/src/internal/query.ts +315 -54
- package/src/internal/renderer.ts +51 -6
- package/src/internal/runtime/driver-value-mapping.ts +58 -0
- package/src/internal/runtime/normalize.ts +74 -43
- package/src/internal/runtime/schema.ts +5 -3
- package/src/internal/runtime/value.ts +153 -30
- package/src/internal/scalar.ts +6 -1
- package/src/internal/schema-derivation.d.ts +12 -61
- package/src/internal/schema-derivation.ts +90 -38
- package/src/internal/schema-expression.ts +2 -2
- package/src/internal/sql-expression-renderer.ts +19 -0
- package/src/internal/standard-dsl.ts +6885 -0
- package/src/internal/table-options.ts +229 -62
- package/src/internal/table.d.ts +33 -32
- package/src/internal/table.ts +469 -160
- package/src/mysql/column-extension.ts +3 -0
- package/src/mysql/column.ts +27 -12
- package/src/mysql/datatypes/index.ts +24 -2
- package/src/mysql/errors/catalog.ts +5 -5
- package/src/mysql/errors/normalize.ts +2 -2
- package/src/mysql/executor.ts +7 -5
- package/src/mysql/internal/dialect.ts +9 -4
- package/src/mysql/internal/dsl.ts +906 -324
- package/src/mysql/internal/renderer.ts +7 -2
- package/src/mysql/json.ts +37 -0
- package/src/mysql/query-extension.ts +16 -0
- package/src/mysql/query.ts +9 -2
- package/src/mysql/renderer.ts +31 -4
- package/src/mysql.ts +4 -12
- package/src/postgres/column-extension.ts +28 -0
- package/src/postgres/column.ts +9 -13
- package/src/postgres/datatypes/index.d.ts +2 -1
- package/src/postgres/datatypes/index.ts +3 -2
- package/src/postgres/errors/normalize.ts +2 -2
- package/src/postgres/executor.ts +55 -10
- package/src/postgres/function/core.ts +20 -4
- package/src/postgres/function/index.ts +1 -17
- package/src/postgres/internal/dialect.ts +9 -4
- package/src/postgres/internal/dsl.ts +850 -359
- package/src/postgres/internal/renderer.ts +7 -2
- package/src/postgres/internal/schema-ddl.ts +22 -9
- package/src/postgres/internal/schema-model.ts +244 -10
- package/src/postgres/json.ts +100 -24
- package/src/postgres/jsonb.ts +38 -0
- package/src/postgres/query-extension.ts +2 -0
- package/src/postgres/query.ts +9 -2
- package/src/postgres/renderer.ts +31 -4
- package/src/postgres/schema-management.ts +108 -16
- package/src/postgres/schema.ts +98 -15
- package/src/postgres/table.ts +203 -398
- package/src/postgres/type.ts +8 -7
- package/src/postgres.ts +9 -11
- package/src/sqlite/column-extension.ts +3 -0
- package/src/sqlite/column.ts +127 -0
- package/src/sqlite/datatypes/index.ts +80 -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 +229 -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 +42 -0
- package/src/sqlite/internal/dsl.ts +6979 -0
- package/src/sqlite/internal/renderer.ts +51 -0
- package/src/sqlite/json.ts +39 -0
- package/src/sqlite/query-extension.ts +2 -0
- package/src/sqlite/query.ts +196 -0
- package/src/sqlite/renderer.ts +51 -0
- package/src/sqlite.ts +14 -0
- package/src/standard/column.ts +163 -0
- package/src/standard/datatypes/index.ts +83 -0
- package/src/standard/datatypes/spec.ts +98 -0
- package/src/standard/dialect.ts +40 -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/internal/renderer.ts +45 -0
- package/src/standard/query.ts +152 -0
- package/src/standard/renderer.ts +21 -0
- package/src/standard/table.ts +147 -0
- package/src/standard.ts +18 -0
- package/src/internal/aggregation-validation.ts +0 -57
- package/src/mysql/table.ts +0 -157
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as Query from "../../internal/query.js"
|
|
2
|
+
import type * as Expression from "../../internal/scalar.js"
|
|
3
|
+
import type * as Casing from "../../internal/casing.js"
|
|
4
|
+
import { type RenderState } from "../../internal/dialect.js"
|
|
5
|
+
import { sqliteDialect } from "./dialect.js"
|
|
6
|
+
import { type Projection } from "../../internal/projections.js"
|
|
7
|
+
import { renderQueryAst } from "../../internal/sql-expression-renderer.js"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal rendered-query payload produced by the built-in SQLite renderer.
|
|
11
|
+
*/
|
|
12
|
+
export interface SqliteRenderResult {
|
|
13
|
+
readonly sql: string
|
|
14
|
+
readonly params: readonly unknown[]
|
|
15
|
+
readonly projections: readonly Projection[]
|
|
16
|
+
readonly valueMappings?: Expression.DriverValueMappings
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface SqliteRenderOptions {
|
|
20
|
+
readonly valueMappings?: Expression.DriverValueMappings
|
|
21
|
+
readonly casing?: Casing.Options
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Renders the current query AST into SQLite-shaped SQL plus bind parameters.
|
|
26
|
+
*/
|
|
27
|
+
export const renderSqlitePlan = <PlanValue extends Query.Plan.Any>(
|
|
28
|
+
plan: Query.DialectCompatiblePlan<PlanValue, "sqlite">,
|
|
29
|
+
options: SqliteRenderOptions = {}
|
|
30
|
+
): SqliteRenderResult => {
|
|
31
|
+
const state: RenderState = {
|
|
32
|
+
params: [],
|
|
33
|
+
valueMappings: options.valueMappings,
|
|
34
|
+
casing: options.casing,
|
|
35
|
+
ctes: [],
|
|
36
|
+
cteNames: new Set<string>(),
|
|
37
|
+
cteSources: new Map<string, unknown>(),
|
|
38
|
+
sourceNames: new Map()
|
|
39
|
+
}
|
|
40
|
+
const rendered = renderQueryAst(
|
|
41
|
+
Query.getAst(plan as Query.Plan.Any) as any,
|
|
42
|
+
state,
|
|
43
|
+
sqliteDialect
|
|
44
|
+
)
|
|
45
|
+
return {
|
|
46
|
+
sql: rendered.sql,
|
|
47
|
+
params: state.params,
|
|
48
|
+
projections: rendered.projections,
|
|
49
|
+
valueMappings: state.valueMappings
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** SQLite JSON expression helpers. */
|
|
2
|
+
export { json } from "./internal/dsl.js"
|
|
3
|
+
import { json } from "./internal/dsl.js"
|
|
4
|
+
|
|
5
|
+
export const key = json.key
|
|
6
|
+
export const index = json.index
|
|
7
|
+
export const wildcard = json.wildcard
|
|
8
|
+
export const slice = json.slice
|
|
9
|
+
export const descend = json.descend
|
|
10
|
+
export const path = json.path
|
|
11
|
+
export const get = json.get
|
|
12
|
+
export const access = json.access
|
|
13
|
+
export const traverse = json.traverse
|
|
14
|
+
export const text = json.text
|
|
15
|
+
export const accessText = json.accessText
|
|
16
|
+
export const traverseText = json.traverseText
|
|
17
|
+
export const contains = json.contains
|
|
18
|
+
export const containedBy = json.containedBy
|
|
19
|
+
export const hasKey = json.hasKey
|
|
20
|
+
export const keyExists = json.keyExists
|
|
21
|
+
export const hasAnyKeys = json.hasAnyKeys
|
|
22
|
+
export const hasAllKeys = json.hasAllKeys
|
|
23
|
+
export const delete_ = json.delete
|
|
24
|
+
export { delete_ as delete }
|
|
25
|
+
export const remove = json.remove
|
|
26
|
+
export const set = json.set
|
|
27
|
+
export const insert = json.insert
|
|
28
|
+
export const concat = json.concat
|
|
29
|
+
export const merge = json.merge
|
|
30
|
+
export const buildObject = json.buildObject
|
|
31
|
+
export const buildArray = json.buildArray
|
|
32
|
+
export const toJson = json.toJson
|
|
33
|
+
export const toJsonb = json.toJsonb
|
|
34
|
+
export const typeOf = json.typeOf
|
|
35
|
+
export const length = json.length
|
|
36
|
+
export const keys = json.keys
|
|
37
|
+
export const stripNulls = json.stripNulls
|
|
38
|
+
export const pathExists = json.pathExists
|
|
39
|
+
export const pathMatch = json.pathMatch
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AnyTableFunctionSource,
|
|
3
|
+
type AnyUnnestSource,
|
|
4
|
+
type AnyValuesSource,
|
|
5
|
+
type CapabilitiesOfPlan,
|
|
6
|
+
type CompletePlan,
|
|
7
|
+
type DialectCompatiblePlan,
|
|
8
|
+
type DerivedSourceRequiredError,
|
|
9
|
+
type CteSource,
|
|
10
|
+
type EffectiveNullability,
|
|
11
|
+
type ExpressionInput,
|
|
12
|
+
type ExpressionOutput,
|
|
13
|
+
type GroupByInput,
|
|
14
|
+
type MergeCapabilities,
|
|
15
|
+
type MergeCapabilityTuple,
|
|
16
|
+
type HavingPredicateInput,
|
|
17
|
+
type OrderDirection,
|
|
18
|
+
type OutputOfSelection,
|
|
19
|
+
type MutationTargetLike,
|
|
20
|
+
type NumericExpressionInput,
|
|
21
|
+
type PredicateInput,
|
|
22
|
+
type QueryCapability,
|
|
23
|
+
type QueryPlan,
|
|
24
|
+
type QueryRequirement,
|
|
25
|
+
type SetCompatiblePlan,
|
|
26
|
+
type SetCompatibleRightPlan,
|
|
27
|
+
type SetOperator,
|
|
28
|
+
type QueryStatement,
|
|
29
|
+
type ResultRow,
|
|
30
|
+
type ResultRows,
|
|
31
|
+
type RuntimeResultRow,
|
|
32
|
+
type RuntimeResultRows,
|
|
33
|
+
type SchemaTableLike,
|
|
34
|
+
type SourceCapabilitiesOf,
|
|
35
|
+
type SourceRequiredOf,
|
|
36
|
+
type SourceRequirementError,
|
|
37
|
+
type StatementOfPlan,
|
|
38
|
+
type StringExpressionInput
|
|
39
|
+
} from "../internal/query.js"
|
|
40
|
+
import {
|
|
41
|
+
type PublicNonStructuredFromApi,
|
|
42
|
+
type PublicStructuredFromConstraint,
|
|
43
|
+
type PublicStructuredFromResult,
|
|
44
|
+
type as sqliteType,
|
|
45
|
+
values,
|
|
46
|
+
unnest,
|
|
47
|
+
select,
|
|
48
|
+
insert,
|
|
49
|
+
from as dslFrom
|
|
50
|
+
} from "./internal/dsl.js"
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
literal,
|
|
54
|
+
column,
|
|
55
|
+
cast,
|
|
56
|
+
eq,
|
|
57
|
+
neq,
|
|
58
|
+
lt,
|
|
59
|
+
lte,
|
|
60
|
+
gt,
|
|
61
|
+
gte,
|
|
62
|
+
isNull,
|
|
63
|
+
isNotNull,
|
|
64
|
+
like,
|
|
65
|
+
ilike,
|
|
66
|
+
regexMatch,
|
|
67
|
+
regexIMatch,
|
|
68
|
+
regexNotMatch,
|
|
69
|
+
regexNotIMatch,
|
|
70
|
+
and,
|
|
71
|
+
or,
|
|
72
|
+
not,
|
|
73
|
+
all,
|
|
74
|
+
any,
|
|
75
|
+
case_ as case,
|
|
76
|
+
match,
|
|
77
|
+
in_ as in,
|
|
78
|
+
notIn,
|
|
79
|
+
between,
|
|
80
|
+
contains,
|
|
81
|
+
containedBy,
|
|
82
|
+
overlaps,
|
|
83
|
+
exists,
|
|
84
|
+
isDistinctFrom,
|
|
85
|
+
isNotDistinctFrom,
|
|
86
|
+
excluded,
|
|
87
|
+
as,
|
|
88
|
+
with_ as with,
|
|
89
|
+
withRecursive,
|
|
90
|
+
lateral,
|
|
91
|
+
scalar,
|
|
92
|
+
inSubquery,
|
|
93
|
+
compareAny,
|
|
94
|
+
compareAll,
|
|
95
|
+
generateSeries,
|
|
96
|
+
values,
|
|
97
|
+
unnest,
|
|
98
|
+
select,
|
|
99
|
+
returning,
|
|
100
|
+
onConflict,
|
|
101
|
+
insert,
|
|
102
|
+
update,
|
|
103
|
+
upsert,
|
|
104
|
+
delete_ as delete,
|
|
105
|
+
truncate,
|
|
106
|
+
merge,
|
|
107
|
+
transaction,
|
|
108
|
+
commit,
|
|
109
|
+
rollback,
|
|
110
|
+
savepoint,
|
|
111
|
+
rollbackTo,
|
|
112
|
+
releaseSavepoint,
|
|
113
|
+
createTable,
|
|
114
|
+
dropTable,
|
|
115
|
+
createIndex,
|
|
116
|
+
dropIndex,
|
|
117
|
+
union,
|
|
118
|
+
unionAll,
|
|
119
|
+
intersect,
|
|
120
|
+
intersectAll,
|
|
121
|
+
except,
|
|
122
|
+
exceptAll,
|
|
123
|
+
where,
|
|
124
|
+
having,
|
|
125
|
+
innerJoin,
|
|
126
|
+
leftJoin,
|
|
127
|
+
rightJoin,
|
|
128
|
+
fullJoin,
|
|
129
|
+
crossJoin,
|
|
130
|
+
distinct,
|
|
131
|
+
distinctOn,
|
|
132
|
+
limit,
|
|
133
|
+
offset,
|
|
134
|
+
lock,
|
|
135
|
+
orderBy,
|
|
136
|
+
groupBy
|
|
137
|
+
} from "./internal/dsl.js"
|
|
138
|
+
import type * as Expression from "../internal/scalar.js"
|
|
139
|
+
export { sqliteType as type }
|
|
140
|
+
|
|
141
|
+
type SqliteMutationValueInput<Value> =
|
|
142
|
+
| Value
|
|
143
|
+
| Expression.Scalar<Value, Expression.DbType.Any, Expression.Nullability, "sqlite", Expression.ScalarKind, Expression.BindingId>
|
|
144
|
+
|
|
145
|
+
export type MutationInputOf<Shape> = {
|
|
146
|
+
readonly [K in keyof Shape]: SqliteMutationValueInput<Shape[K]>
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
type StructuredSource = AnyValuesSource | AnyUnnestSource | AnyTableFunctionSource
|
|
150
|
+
|
|
151
|
+
type StructuredFromApi = <CurrentSource extends StructuredSource>(
|
|
152
|
+
source: CurrentSource
|
|
153
|
+
) => <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
154
|
+
plan: PlanValue & PublicStructuredFromConstraint<PlanValue, CurrentSource, "sqlite">
|
|
155
|
+
) => PublicStructuredFromResult<PlanValue, CurrentSource, "sqlite">
|
|
156
|
+
|
|
157
|
+
export const from: StructuredFromApi & PublicNonStructuredFromApi = dslFrom as StructuredFromApi & PublicNonStructuredFromApi
|
|
158
|
+
|
|
159
|
+
export type {
|
|
160
|
+
CapabilitiesOfPlan,
|
|
161
|
+
CompletePlan,
|
|
162
|
+
DialectCompatiblePlan,
|
|
163
|
+
DerivedSourceRequiredError,
|
|
164
|
+
CteSource,
|
|
165
|
+
EffectiveNullability,
|
|
166
|
+
ExpressionInput,
|
|
167
|
+
ExpressionOutput,
|
|
168
|
+
GroupByInput,
|
|
169
|
+
MergeCapabilities,
|
|
170
|
+
MergeCapabilityTuple,
|
|
171
|
+
HavingPredicateInput,
|
|
172
|
+
OrderDirection,
|
|
173
|
+
OutputOfSelection,
|
|
174
|
+
MutationTargetLike,
|
|
175
|
+
NumericExpressionInput,
|
|
176
|
+
PredicateInput,
|
|
177
|
+
QueryCapability,
|
|
178
|
+
QueryPlan,
|
|
179
|
+
QueryStatement,
|
|
180
|
+
QueryRequirement,
|
|
181
|
+
SetCompatiblePlan,
|
|
182
|
+
SetCompatibleRightPlan,
|
|
183
|
+
SetOperator,
|
|
184
|
+
ResultRow,
|
|
185
|
+
ResultRows,
|
|
186
|
+
RuntimeResultRow,
|
|
187
|
+
RuntimeResultRows,
|
|
188
|
+
SchemaTableLike,
|
|
189
|
+
SourceCapabilitiesOf,
|
|
190
|
+
SourceRequiredOf,
|
|
191
|
+
SourceRequirementError,
|
|
192
|
+
StatementOfPlan,
|
|
193
|
+
StringExpressionInput
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export { union_query_capabilities } from "../internal/query.js"
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { pipeArguments, type Pipeable } from "effect/Pipeable"
|
|
2
|
+
|
|
3
|
+
import * as CoreRenderer from "../internal/renderer.js"
|
|
4
|
+
import * as Casing from "../internal/casing.js"
|
|
5
|
+
import type * as Expression from "../internal/scalar.js"
|
|
6
|
+
import type { SqliteDatatypeFamily, SqliteDatatypeKind } from "./datatypes/spec.js"
|
|
7
|
+
import { renderSqlitePlan } from "./internal/renderer.js"
|
|
8
|
+
|
|
9
|
+
/** SQLite-specialized rendered query shape. */
|
|
10
|
+
export type RenderedQuery<Row> = CoreRenderer.RenderedQuery<Row, "sqlite">
|
|
11
|
+
/** Extracts the row type carried by a SQLite rendered query. */
|
|
12
|
+
export type RowOf<Value extends RenderedQuery<any>> = CoreRenderer.RowOf<Value>
|
|
13
|
+
/** SQLite-specialized renderer contract. */
|
|
14
|
+
export type Renderer = CoreRenderer.Renderer<"sqlite"> & Pipeable & {
|
|
15
|
+
readonly [Casing.TypeId]: Casing.State
|
|
16
|
+
readonly withCasing: (options: Casing.Options) => Renderer
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type ValueMappings = Expression.DriverValueMappingsFor<SqliteDatatypeKind | "uuid", SqliteDatatypeFamily | "uuid">
|
|
20
|
+
|
|
21
|
+
export interface MakeOptions {
|
|
22
|
+
readonly valueMappings?: ValueMappings
|
|
23
|
+
readonly casing?: Casing.Options
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { TypeId } from "../internal/renderer.js"
|
|
27
|
+
export type { Projection } from "../internal/renderer.js"
|
|
28
|
+
|
|
29
|
+
const RendererProto = {
|
|
30
|
+
pipe(this: Pipeable) {
|
|
31
|
+
return pipeArguments(this, arguments)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Creates the built-in SQLite renderer. */
|
|
36
|
+
export const make = (options: MakeOptions = {}): Renderer => {
|
|
37
|
+
const renderer = CoreRenderer.makeTrusted("sqlite", (plan) => renderSqlitePlan(plan, options))
|
|
38
|
+
return Object.assign(Object.create(RendererProto), renderer, {
|
|
39
|
+
[Casing.TypeId]: {
|
|
40
|
+
casing: options.casing
|
|
41
|
+
},
|
|
42
|
+
withCasing: (override: Casing.Options) =>
|
|
43
|
+
make({
|
|
44
|
+
...options,
|
|
45
|
+
casing: Casing.merge(options.casing, override)
|
|
46
|
+
})
|
|
47
|
+
}) as Renderer
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Shared built-in SQLite renderer instance. */
|
|
51
|
+
export const sqlite = make()
|
package/src/sqlite.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** SQLite-specific column extensions. Portable columns are exported from `effect-qb`. */
|
|
2
|
+
export * as Column from "./sqlite/column-extension.js"
|
|
3
|
+
/** SQLite datatype witnesses and coercion families. */
|
|
4
|
+
export * as Datatypes from "./sqlite/datatypes/index.js"
|
|
5
|
+
/** SQLite error catalog and error normalization helpers. */
|
|
6
|
+
export * as Errors from "./sqlite/errors/index.js"
|
|
7
|
+
/** SQLite-specialized JSON expression helpers. */
|
|
8
|
+
export * as Json from "./sqlite/json.js"
|
|
9
|
+
/** SQLite-specialized typed query execution contracts. */
|
|
10
|
+
export * as Executor from "./sqlite/executor.js"
|
|
11
|
+
/** SQLite-specific query helpers. Portable queries are exported from the root package. */
|
|
12
|
+
export * as Query from "./sqlite/query-extension.js"
|
|
13
|
+
/** SQLite-specialized built-in renderer entrypoint. */
|
|
14
|
+
export * as Renderer from "./sqlite/renderer.js"
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema"
|
|
2
|
+
|
|
3
|
+
import * as BaseColumn from "../internal/column.js"
|
|
4
|
+
import { makeColumnDefinition, type AnyColumnDefinition, type ColumnDefinition } from "../internal/column-state.js"
|
|
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"
|
|
8
|
+
import {
|
|
9
|
+
BigIntStringSchema,
|
|
10
|
+
DecimalStringSchema,
|
|
11
|
+
LocalDateStringSchema,
|
|
12
|
+
LocalDateTimeStringSchema,
|
|
13
|
+
LocalTimeStringSchema,
|
|
14
|
+
type BigIntString,
|
|
15
|
+
type DecimalString,
|
|
16
|
+
type LocalDateString,
|
|
17
|
+
type LocalDateTimeString,
|
|
18
|
+
type LocalTimeString
|
|
19
|
+
} from "../internal/runtime/value.js"
|
|
20
|
+
import { standardDatatypes } from "./datatypes/index.js"
|
|
21
|
+
|
|
22
|
+
const primitive = <Type, Db extends Expression.DbType.Any>(
|
|
23
|
+
schema: Schema.Schema<Type, any, any>,
|
|
24
|
+
dbType: Db
|
|
25
|
+
): ColumnDefinition<Type, Type, Type, Db, false, false, false, false, false, undefined> =>
|
|
26
|
+
makeColumnDefinition(schema as Schema.Schema<NonNullable<Type>>, {
|
|
27
|
+
dbType,
|
|
28
|
+
nullable: false,
|
|
29
|
+
hasDefault: false,
|
|
30
|
+
generated: false,
|
|
31
|
+
primaryKey: false,
|
|
32
|
+
unique: false,
|
|
33
|
+
references: undefined
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const renderNumericDdlType = (
|
|
37
|
+
kind: string,
|
|
38
|
+
options?: BaseColumn.NumericOptions
|
|
39
|
+
): string | undefined => {
|
|
40
|
+
if (options === undefined || options.precision === undefined) {
|
|
41
|
+
return undefined
|
|
42
|
+
}
|
|
43
|
+
return options.scale === undefined
|
|
44
|
+
? `${kind}(${options.precision})`
|
|
45
|
+
: `${kind}(${options.precision},${options.scale})`
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const boundedString = (length?: number): Schema.Schema<string> =>
|
|
49
|
+
length === undefined
|
|
50
|
+
? Schema.String
|
|
51
|
+
: Schema.String.pipe(Schema.maxLength(length))
|
|
52
|
+
|
|
53
|
+
const finiteNumber = Schema.Number.pipe(Schema.finite())
|
|
54
|
+
|
|
55
|
+
export const custom = <SchemaType extends Schema.Schema.Any, Db extends Expression.DbType.Any>(
|
|
56
|
+
schema: SchemaType,
|
|
57
|
+
dbType: Db
|
|
58
|
+
) =>
|
|
59
|
+
makeColumnDefinition(schema as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>, any, any>, {
|
|
60
|
+
dbType: enrichDbType(standardDatatypes, dbType),
|
|
61
|
+
nullable: false,
|
|
62
|
+
hasDefault: false,
|
|
63
|
+
generated: false,
|
|
64
|
+
primaryKey: false,
|
|
65
|
+
unique: false,
|
|
66
|
+
references: undefined,
|
|
67
|
+
ddlType: undefined,
|
|
68
|
+
identity: undefined
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
export const uuid = () => primitive(Schema.UUID, standardDatatypes.uuid())
|
|
72
|
+
export const text = () => primitive(Schema.String, standardDatatypes.text())
|
|
73
|
+
export const varchar = (length?: number) =>
|
|
74
|
+
makeColumnDefinition(boundedString(length), {
|
|
75
|
+
dbType: standardDatatypes.varchar(),
|
|
76
|
+
nullable: false,
|
|
77
|
+
hasDefault: false,
|
|
78
|
+
generated: false,
|
|
79
|
+
primaryKey: false,
|
|
80
|
+
unique: false,
|
|
81
|
+
references: undefined,
|
|
82
|
+
ddlType: length === undefined ? "varchar" : `varchar(${length})`,
|
|
83
|
+
identity: undefined
|
|
84
|
+
})
|
|
85
|
+
export const char = (length = 1) =>
|
|
86
|
+
makeColumnDefinition(boundedString(length), {
|
|
87
|
+
dbType: standardDatatypes.char(),
|
|
88
|
+
nullable: false,
|
|
89
|
+
hasDefault: false,
|
|
90
|
+
generated: false,
|
|
91
|
+
primaryKey: false,
|
|
92
|
+
unique: false,
|
|
93
|
+
references: undefined,
|
|
94
|
+
ddlType: `char(${length})`,
|
|
95
|
+
identity: undefined
|
|
96
|
+
})
|
|
97
|
+
export const int = () => primitive(Schema.Int, standardDatatypes.int())
|
|
98
|
+
export const bigint = () => primitive(BigIntStringSchema, standardDatatypes.bigint())
|
|
99
|
+
export const number = (options?: BaseColumn.NumericOptions) =>
|
|
100
|
+
makeColumnDefinition(DecimalStringSchema, {
|
|
101
|
+
dbType: standardDatatypes.decimal(),
|
|
102
|
+
nullable: false,
|
|
103
|
+
hasDefault: false,
|
|
104
|
+
generated: false,
|
|
105
|
+
primaryKey: false,
|
|
106
|
+
unique: false,
|
|
107
|
+
references: undefined,
|
|
108
|
+
ddlType: renderNumericDdlType("decimal", options),
|
|
109
|
+
identity: undefined
|
|
110
|
+
})
|
|
111
|
+
export const real = () => primitive(finiteNumber, standardDatatypes.real())
|
|
112
|
+
export const boolean = () => primitive(Schema.Boolean, standardDatatypes.boolean())
|
|
113
|
+
export const date = () => primitive(LocalDateStringSchema, standardDatatypes.date())
|
|
114
|
+
export const time = () => primitive(LocalTimeStringSchema, standardDatatypes.time())
|
|
115
|
+
export const datetime = () => primitive(LocalDateTimeStringSchema, standardDatatypes.datetime())
|
|
116
|
+
export const timestamp = () => primitive(LocalDateTimeStringSchema, standardDatatypes.timestamp())
|
|
117
|
+
export const blob = () => primitive(Schema.Uint8ArrayFromSelf, standardDatatypes.blob())
|
|
118
|
+
export const json = <SchemaType extends Schema.Schema.Any>(schema: SchemaType) =>
|
|
119
|
+
makeColumnDefinition(schema as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>, any, any>, {
|
|
120
|
+
dbType: { ...standardDatatypes.json(), variant: "json" } as Expression.DbType.Json<"standard", "json">,
|
|
121
|
+
nullable: false,
|
|
122
|
+
hasDefault: false,
|
|
123
|
+
generated: false,
|
|
124
|
+
primaryKey: false,
|
|
125
|
+
unique: false,
|
|
126
|
+
references: undefined,
|
|
127
|
+
ddlType: undefined,
|
|
128
|
+
identity: undefined
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
export const nullable = BaseColumn.nullable
|
|
132
|
+
export const brand = BaseColumn.brand
|
|
133
|
+
export const primaryKey = BaseColumn.primaryKey
|
|
134
|
+
type UniqueColumn<Column extends AnyColumnDefinition> = ReturnType<typeof BaseColumn.unique<Column>>
|
|
135
|
+
|
|
136
|
+
type StandardUniqueOptions = {
|
|
137
|
+
readonly name?: string
|
|
138
|
+
readonly nullsNotDistinct?: never
|
|
139
|
+
readonly deferrable?: never
|
|
140
|
+
readonly initiallyDeferred?: never
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
type NonEmptyOptionNameInput<Options> = Options extends { readonly name: infer Name extends string }
|
|
144
|
+
? NonEmptyStringInput<Name> extends never ? never : unknown
|
|
145
|
+
: unknown
|
|
146
|
+
|
|
147
|
+
type UniqueModifier = {
|
|
148
|
+
<Column extends AnyColumnDefinition>(column: Column): UniqueColumn<Column>
|
|
149
|
+
readonly options: <const Options extends StandardUniqueOptions>(
|
|
150
|
+
options: Options & NonEmptyOptionNameInput<Options>
|
|
151
|
+
) => <Column extends AnyColumnDefinition>(column: Column) => UniqueColumn<Column>
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export const unique = BaseColumn.unique as UniqueModifier
|
|
155
|
+
const default_ = BaseColumn.default_
|
|
156
|
+
export const generated = BaseColumn.generated
|
|
157
|
+
export const driverValueMapping = BaseColumn.driverValueMapping
|
|
158
|
+
export const references = BaseColumn.references
|
|
159
|
+
export const schema = BaseColumn.schema
|
|
160
|
+
export { default_ as default }
|
|
161
|
+
|
|
162
|
+
export type Any = BaseColumn.Any
|
|
163
|
+
export type AnyBound = BaseColumn.AnyBound
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { DatatypeModule } from "../../internal/datatypes/define.js"
|
|
2
|
+
import type * as Expression from "../../internal/scalar.js"
|
|
3
|
+
import type { NonEmptyStringInput } from "../../internal/table-options.js"
|
|
4
|
+
import { standardDatatypeFamilies, standardDatatypeKinds } from "./spec.js"
|
|
5
|
+
|
|
6
|
+
const withMetadata = <Kind extends keyof typeof standardDatatypeKinds & string>(
|
|
7
|
+
kind: Kind
|
|
8
|
+
): Expression.DbType.Base<"standard", Kind> => {
|
|
9
|
+
const kindSpec = standardDatatypeKinds[kind]
|
|
10
|
+
const familySpec = standardDatatypeFamilies[kindSpec.family as keyof typeof standardDatatypeFamilies]
|
|
11
|
+
return {
|
|
12
|
+
dialect: "standard",
|
|
13
|
+
kind,
|
|
14
|
+
family: kindSpec.family,
|
|
15
|
+
runtime: kindSpec.runtime,
|
|
16
|
+
compareGroup: familySpec?.compareGroup,
|
|
17
|
+
castTargets: familySpec?.castTargets,
|
|
18
|
+
traits: familySpec?.traits
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const standardDatatypeModule = {
|
|
23
|
+
custom: <Kind extends string>(kind: NonEmptyStringInput<Kind>) => ({
|
|
24
|
+
dialect: "standard",
|
|
25
|
+
kind: kind as Kind
|
|
26
|
+
}),
|
|
27
|
+
uuid: () => ({
|
|
28
|
+
dialect: "standard",
|
|
29
|
+
kind: "uuid",
|
|
30
|
+
family: "uuid",
|
|
31
|
+
runtime: "string",
|
|
32
|
+
compareGroup: "uuid",
|
|
33
|
+
castTargets: ["uuid", "char", "varchar", "text"],
|
|
34
|
+
traits: {
|
|
35
|
+
textual: true
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
} as Record<string, (...args: readonly any[]) => Expression.DbType.Base<"standard", string>>
|
|
39
|
+
|
|
40
|
+
for (const kind of Object.keys(standardDatatypeKinds)) {
|
|
41
|
+
standardDatatypeModule[kind] = () => withMetadata(kind as keyof typeof standardDatatypeKinds & string)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type StandardUuidWitness = Expression.DbType.Base<"standard", "uuid"> & {
|
|
45
|
+
readonly family: "uuid"
|
|
46
|
+
readonly runtime: "string"
|
|
47
|
+
readonly compareGroup: "uuid"
|
|
48
|
+
readonly castTargets: readonly ["uuid", "char", "varchar", "text"]
|
|
49
|
+
readonly traits: {
|
|
50
|
+
readonly textual: true
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type StandardJsonWitness = Expression.DbType.Base<"standard", "json"> & {
|
|
55
|
+
readonly family: "json"
|
|
56
|
+
readonly runtime: "json"
|
|
57
|
+
readonly compareGroup: "json"
|
|
58
|
+
readonly castTargets: readonly ["json", "text"]
|
|
59
|
+
readonly driverValueMapping: {
|
|
60
|
+
readonly toDriver: (value: unknown) => unknown
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
standardDatatypeModule.json = () => ({
|
|
65
|
+
...withMetadata("json"),
|
|
66
|
+
driverValueMapping: {
|
|
67
|
+
toDriver: (value: unknown) => JSON.stringify(value)
|
|
68
|
+
}
|
|
69
|
+
}) as StandardJsonWitness
|
|
70
|
+
|
|
71
|
+
export const standardDatatypes = {
|
|
72
|
+
...(standardDatatypeModule as DatatypeModule<
|
|
73
|
+
"standard",
|
|
74
|
+
typeof standardDatatypeKinds,
|
|
75
|
+
typeof standardDatatypeFamilies
|
|
76
|
+
> & {
|
|
77
|
+
readonly uuid: () => StandardUuidWitness
|
|
78
|
+
readonly json: () => StandardJsonWitness
|
|
79
|
+
}),
|
|
80
|
+
float8: () => withMetadata("real")
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export type StandardDatatypeModule = typeof standardDatatypes
|