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
package/src/postgres.ts
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
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
|
-
/** Shared scalar SQL interfaces and DB-type descriptors. */
|
|
8
|
-
export * as Scalar from "./internal/scalar.js"
|
|
9
7
|
/** Postgres cast helpers. */
|
|
10
8
|
export { cast as Cast } from "./postgres/cast.js"
|
|
11
|
-
/** Postgres-
|
|
9
|
+
/** Postgres-specific SQL function expressions. Portable functions are exported from the root package. */
|
|
12
10
|
export * as Function from "./postgres/function/index.js"
|
|
13
11
|
/** Postgres-specialized JSON expression helpers. */
|
|
14
12
|
export * as Json from "./postgres/json.js"
|
|
13
|
+
/** Postgres jsonb-only expression helpers. */
|
|
14
|
+
export * as Jsonb from "./postgres/jsonb.js"
|
|
15
15
|
/** Postgres-specialized typed query execution contracts. */
|
|
16
16
|
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"
|
|
17
|
+
/** Postgres-specific query helpers. Portable queries are exported from the root package. */
|
|
18
|
+
export * as Query from "./postgres/query-extension.js"
|
|
21
19
|
/** Postgres database-type constructors for casts and typed references. */
|
|
22
20
|
export { type as Type } from "./postgres/type.js"
|
|
23
21
|
/** Postgres normalized table/enum metadata helpers. */
|
|
@@ -25,12 +23,12 @@ export * as Metadata from "./postgres/metadata.js"
|
|
|
25
23
|
/** Postgres schema-expression helpers for DDL-only metadata. */
|
|
26
24
|
export * as SchemaExpression from "./postgres/schema-expression.js"
|
|
27
25
|
/** Postgres schema-scoped table and enum builder helpers. */
|
|
28
|
-
export
|
|
26
|
+
export * as Schema from "./postgres/schema.js"
|
|
29
27
|
export type { SchemaNamespace } from "./postgres/schema.js"
|
|
30
28
|
/** Postgres enum and sequence definition helpers. */
|
|
31
29
|
export { enumType as enum, sequence } from "./postgres/schema-management.js"
|
|
32
30
|
export type { EnumDefinition, SequenceDefinition } from "./postgres/schema-management.js"
|
|
33
|
-
/** Postgres-
|
|
31
|
+
/** Postgres-specific table-option extensions. Portable tables are exported from `effect-qb`. */
|
|
34
32
|
export * as Table from "./postgres/table.js"
|
|
35
33
|
/** Postgres-specialized built-in renderer entrypoint. */
|
|
36
34
|
export * as Renderer from "./postgres/renderer.js"
|
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
DecimalStringSchema,
|
|
10
|
+
LocalDateStringSchema,
|
|
11
|
+
LocalDateTimeStringSchema,
|
|
12
|
+
LocalTimeStringSchema,
|
|
13
|
+
type DecimalString,
|
|
14
|
+
type LocalDateString,
|
|
15
|
+
type LocalDateTimeString,
|
|
16
|
+
type LocalTimeString
|
|
17
|
+
} from "../internal/runtime/value.js"
|
|
18
|
+
import { sqliteDatatypes } from "./datatypes/index.js"
|
|
19
|
+
|
|
20
|
+
const primitive = <Type, Db extends Expression.DbType.Any>(
|
|
21
|
+
schema: Schema.Schema<Type, any, any>,
|
|
22
|
+
dbType: Db
|
|
23
|
+
): ColumnDefinition<Type, Type, Type, Db, false, false, false, false, false, undefined> =>
|
|
24
|
+
makeColumnDefinition(schema as Schema.Schema<NonNullable<Type>>, {
|
|
25
|
+
dbType,
|
|
26
|
+
nullable: false,
|
|
27
|
+
hasDefault: false,
|
|
28
|
+
generated: false,
|
|
29
|
+
primaryKey: false,
|
|
30
|
+
unique: false,
|
|
31
|
+
references: undefined
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const renderNumericDdlType = (
|
|
35
|
+
kind: string,
|
|
36
|
+
options?: BaseColumn.NumericOptions
|
|
37
|
+
): string | undefined => {
|
|
38
|
+
if (options === undefined || options.precision === undefined) {
|
|
39
|
+
return undefined
|
|
40
|
+
}
|
|
41
|
+
return options.scale === undefined
|
|
42
|
+
? `${kind}(${options.precision})`
|
|
43
|
+
: `${kind}(${options.precision},${options.scale})`
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const custom = <SchemaType extends Schema.Schema.Any, Db extends Expression.DbType.Any>(
|
|
47
|
+
schema: SchemaType,
|
|
48
|
+
dbType: Db
|
|
49
|
+
) =>
|
|
50
|
+
makeColumnDefinition(schema as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>, any, any>, {
|
|
51
|
+
dbType: enrichDbType(sqliteDatatypes, dbType),
|
|
52
|
+
nullable: false,
|
|
53
|
+
hasDefault: false,
|
|
54
|
+
generated: false,
|
|
55
|
+
primaryKey: false,
|
|
56
|
+
unique: false,
|
|
57
|
+
references: undefined,
|
|
58
|
+
ddlType: undefined,
|
|
59
|
+
identity: undefined
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
export const uuid = () => primitive(Schema.UUID, sqliteDatatypes.uuid())
|
|
63
|
+
export const text = () => primitive(Schema.String, sqliteDatatypes.text())
|
|
64
|
+
export const int = () => primitive(Schema.Int, sqliteDatatypes.int())
|
|
65
|
+
export const number = (options?: BaseColumn.NumericOptions) =>
|
|
66
|
+
makeColumnDefinition(DecimalStringSchema, {
|
|
67
|
+
dbType: sqliteDatatypes.decimal(),
|
|
68
|
+
nullable: false,
|
|
69
|
+
hasDefault: false,
|
|
70
|
+
generated: false,
|
|
71
|
+
primaryKey: false,
|
|
72
|
+
unique: false,
|
|
73
|
+
references: undefined,
|
|
74
|
+
ddlType: renderNumericDdlType("decimal", options),
|
|
75
|
+
identity: undefined
|
|
76
|
+
})
|
|
77
|
+
export const boolean = () => primitive(Schema.Boolean, sqliteDatatypes.boolean())
|
|
78
|
+
export const date = () => primitive(LocalDateStringSchema, sqliteDatatypes.date())
|
|
79
|
+
export const time = () => primitive(LocalTimeStringSchema, sqliteDatatypes.time())
|
|
80
|
+
export const datetime = () => primitive(LocalDateTimeStringSchema, sqliteDatatypes.datetime())
|
|
81
|
+
export const timestamp = () => primitive(LocalDateTimeStringSchema, sqliteDatatypes.timestamp())
|
|
82
|
+
export const json = <SchemaType extends Schema.Schema.Any>(schema: SchemaType) =>
|
|
83
|
+
makeColumnDefinition(schema as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>, any, any>, {
|
|
84
|
+
dbType: { ...sqliteDatatypes.json(), variant: "json" } as Expression.DbType.Json<"sqlite", "json">,
|
|
85
|
+
nullable: false,
|
|
86
|
+
hasDefault: false,
|
|
87
|
+
generated: false,
|
|
88
|
+
primaryKey: false,
|
|
89
|
+
unique: false,
|
|
90
|
+
references: undefined,
|
|
91
|
+
ddlType: undefined,
|
|
92
|
+
identity: undefined
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
export const nullable = BaseColumn.nullable
|
|
96
|
+
export const brand = BaseColumn.brand
|
|
97
|
+
export const primaryKey = BaseColumn.primaryKey
|
|
98
|
+
type UniqueColumn<Column extends AnyColumnDefinition> = ReturnType<typeof BaseColumn.unique<Column>>
|
|
99
|
+
|
|
100
|
+
type SqliteUniqueOptions = {
|
|
101
|
+
readonly name?: string
|
|
102
|
+
readonly nullsNotDistinct?: never
|
|
103
|
+
readonly deferrable?: never
|
|
104
|
+
readonly initiallyDeferred?: never
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
type NonEmptyOptionNameInput<Options> = Options extends { readonly name: infer Name extends string }
|
|
108
|
+
? NonEmptyStringInput<Name> extends never ? never : unknown
|
|
109
|
+
: unknown
|
|
110
|
+
|
|
111
|
+
type UniqueModifier = {
|
|
112
|
+
<Column extends AnyColumnDefinition>(column: Column): UniqueColumn<Column>
|
|
113
|
+
readonly options: <const Options extends SqliteUniqueOptions>(
|
|
114
|
+
options: Options & NonEmptyOptionNameInput<Options>
|
|
115
|
+
) => <Column extends AnyColumnDefinition>(column: Column) => UniqueColumn<Column>
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export const unique = BaseColumn.unique as UniqueModifier
|
|
119
|
+
const default_ = BaseColumn.default_
|
|
120
|
+
export const generated = BaseColumn.generated
|
|
121
|
+
export const driverValueMapping = BaseColumn.driverValueMapping
|
|
122
|
+
export const references = BaseColumn.references
|
|
123
|
+
export const schema = BaseColumn.schema
|
|
124
|
+
export { default_ as default }
|
|
125
|
+
|
|
126
|
+
export type Any = BaseColumn.Any
|
|
127
|
+
export type AnyBound = BaseColumn.AnyBound
|
|
@@ -0,0 +1,80 @@
|
|
|
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 { sqliteDatatypeFamilies, sqliteDatatypeKinds } from "./spec.js"
|
|
5
|
+
|
|
6
|
+
const withMetadata = <Kind extends keyof typeof sqliteDatatypeKinds & string>(
|
|
7
|
+
kind: Kind
|
|
8
|
+
): Expression.DbType.Base<"sqlite", Kind> => {
|
|
9
|
+
const kindSpec = sqliteDatatypeKinds[kind]
|
|
10
|
+
const familySpec = sqliteDatatypeFamilies[kindSpec.family as keyof typeof sqliteDatatypeFamilies]
|
|
11
|
+
return {
|
|
12
|
+
dialect: "sqlite",
|
|
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 sqliteDatatypeModule = {
|
|
23
|
+
custom: <Kind extends string>(kind: NonEmptyStringInput<Kind>) => ({
|
|
24
|
+
dialect: "sqlite",
|
|
25
|
+
kind: kind as Kind
|
|
26
|
+
}),
|
|
27
|
+
uuid: () => ({
|
|
28
|
+
dialect: "sqlite",
|
|
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<"sqlite", string>>
|
|
39
|
+
|
|
40
|
+
for (const kind of Object.keys(sqliteDatatypeKinds)) {
|
|
41
|
+
sqliteDatatypeModule[kind] = () => withMetadata(kind as keyof typeof sqliteDatatypeKinds & string)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type SqliteUuidWitness = Expression.DbType.Base<"sqlite", "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 SqliteJsonWitness = Expression.DbType.Base<"sqlite", "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
|
+
sqliteDatatypeModule.json = () => ({
|
|
65
|
+
...withMetadata("json"),
|
|
66
|
+
driverValueMapping: {
|
|
67
|
+
toDriver: (value: unknown) => JSON.stringify(value)
|
|
68
|
+
}
|
|
69
|
+
}) as SqliteJsonWitness
|
|
70
|
+
|
|
71
|
+
export const sqliteDatatypes = sqliteDatatypeModule as DatatypeModule<
|
|
72
|
+
"sqlite",
|
|
73
|
+
typeof sqliteDatatypeKinds,
|
|
74
|
+
typeof sqliteDatatypeFamilies
|
|
75
|
+
> & {
|
|
76
|
+
readonly uuid: () => SqliteUuidWitness
|
|
77
|
+
readonly json: () => SqliteJsonWitness
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export type SqliteDatatypeModule = typeof sqliteDatatypes
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { DatatypeFamilySpec, DatatypeKindSpec } from "../../internal/datatypes/shape.js"
|
|
2
|
+
|
|
3
|
+
export const sqliteDatatypeFamilies = {
|
|
4
|
+
text: {
|
|
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>
|
|
96
|
+
|
|
97
|
+
export type SqliteDatatypeFamily = keyof typeof sqliteDatatypeFamilies
|
|
98
|
+
export type SqliteDatatypeKind = keyof typeof sqliteDatatypeKinds
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
export const sqliteErrorCategories = {
|
|
2
|
+
sqlite: "sqlite"
|
|
3
|
+
} as const
|
|
4
|
+
|
|
5
|
+
export type SqliteErrorCategory = keyof typeof sqliteErrorCategories
|
|
6
|
+
|
|
7
|
+
type SqliteErrorDescriptorShape<Symbol extends string = string> = {
|
|
8
|
+
readonly category: "sqlite"
|
|
9
|
+
readonly number: `${number}`
|
|
10
|
+
readonly symbol: Symbol
|
|
11
|
+
readonly tag: `@sqlite/${Lowercase<Symbol>}`
|
|
12
|
+
readonly messageTemplate: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const descriptor = <Symbol extends string>(
|
|
16
|
+
number: `${number}`,
|
|
17
|
+
symbol: Symbol,
|
|
18
|
+
messageTemplate: string
|
|
19
|
+
): SqliteErrorDescriptorShape<Symbol> => ({
|
|
20
|
+
category: "sqlite",
|
|
21
|
+
number,
|
|
22
|
+
symbol,
|
|
23
|
+
tag: `@sqlite/${symbol.toLowerCase()}` as `@sqlite/${Lowercase<Symbol>}`,
|
|
24
|
+
messageTemplate
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
export const sqliteErrorCatalogBySymbol = {
|
|
28
|
+
SQLITE_ERROR: descriptor("1", "SQLITE_ERROR", "SQL error or missing database"),
|
|
29
|
+
SQLITE_INTERNAL: descriptor("2", "SQLITE_INTERNAL", "Internal SQLite logic error"),
|
|
30
|
+
SQLITE_PERM: descriptor("3", "SQLITE_PERM", "Access permission denied"),
|
|
31
|
+
SQLITE_ABORT: descriptor("4", "SQLITE_ABORT", "Callback routine requested an abort"),
|
|
32
|
+
SQLITE_BUSY: descriptor("5", "SQLITE_BUSY", "Database file is locked"),
|
|
33
|
+
SQLITE_LOCKED: descriptor("6", "SQLITE_LOCKED", "Database table is locked"),
|
|
34
|
+
SQLITE_NOMEM: descriptor("7", "SQLITE_NOMEM", "Out of memory"),
|
|
35
|
+
SQLITE_READONLY: descriptor("8", "SQLITE_READONLY", "Attempt to write a readonly database"),
|
|
36
|
+
SQLITE_INTERRUPT: descriptor("9", "SQLITE_INTERRUPT", "Operation terminated by sqlite3_interrupt"),
|
|
37
|
+
SQLITE_IOERR: descriptor("10", "SQLITE_IOERR", "Disk I/O error"),
|
|
38
|
+
SQLITE_CORRUPT: descriptor("11", "SQLITE_CORRUPT", "Database disk image is malformed"),
|
|
39
|
+
SQLITE_NOTFOUND: descriptor("12", "SQLITE_NOTFOUND", "Unknown opcode"),
|
|
40
|
+
SQLITE_FULL: descriptor("13", "SQLITE_FULL", "Insertion failed because database is full"),
|
|
41
|
+
SQLITE_CANTOPEN: descriptor("14", "SQLITE_CANTOPEN", "Unable to open the database file"),
|
|
42
|
+
SQLITE_PROTOCOL: descriptor("15", "SQLITE_PROTOCOL", "Database lock protocol error"),
|
|
43
|
+
SQLITE_EMPTY: descriptor("16", "SQLITE_EMPTY", "Database is empty"),
|
|
44
|
+
SQLITE_SCHEMA: descriptor("17", "SQLITE_SCHEMA", "Database schema changed"),
|
|
45
|
+
SQLITE_TOOBIG: descriptor("18", "SQLITE_TOOBIG", "String or blob exceeds size limit"),
|
|
46
|
+
SQLITE_CONSTRAINT: descriptor("19", "SQLITE_CONSTRAINT", "Constraint violation"),
|
|
47
|
+
SQLITE_MISMATCH: descriptor("20", "SQLITE_MISMATCH", "Data type mismatch"),
|
|
48
|
+
SQLITE_MISUSE: descriptor("21", "SQLITE_MISUSE", "Library used incorrectly"),
|
|
49
|
+
SQLITE_NOLFS: descriptor("22", "SQLITE_NOLFS", "Uses OS features not supported on host"),
|
|
50
|
+
SQLITE_AUTH: descriptor("23", "SQLITE_AUTH", "Authorization denied"),
|
|
51
|
+
SQLITE_FORMAT: descriptor("24", "SQLITE_FORMAT", "Auxiliary database format error"),
|
|
52
|
+
SQLITE_RANGE: descriptor("25", "SQLITE_RANGE", "Bind parameter index out of range"),
|
|
53
|
+
SQLITE_NOTADB: descriptor("26", "SQLITE_NOTADB", "File is not a database"),
|
|
54
|
+
SQLITE_NOTICE: descriptor("27", "SQLITE_NOTICE", "Notifications from sqlite3_log"),
|
|
55
|
+
SQLITE_WARNING: descriptor("28", "SQLITE_WARNING", "Warnings from sqlite3_log"),
|
|
56
|
+
SQLITE_ROW: descriptor("100", "SQLITE_ROW", "sqlite3_step has another row ready"),
|
|
57
|
+
SQLITE_DONE: descriptor("101", "SQLITE_DONE", "sqlite3_step has finished executing"),
|
|
58
|
+
SQLITE_BUSY_RECOVERY: descriptor("261", "SQLITE_BUSY_RECOVERY", "Database is busy recovering"),
|
|
59
|
+
SQLITE_BUSY_SNAPSHOT: descriptor("517", "SQLITE_BUSY_SNAPSHOT", "Database snapshot is busy"),
|
|
60
|
+
SQLITE_BUSY_TIMEOUT: descriptor("773", "SQLITE_BUSY_TIMEOUT", "Blocking POSIX advisory lock timed out"),
|
|
61
|
+
SQLITE_CONSTRAINT_CHECK: descriptor("275", "SQLITE_CONSTRAINT_CHECK", "CHECK constraint failed"),
|
|
62
|
+
SQLITE_CONSTRAINT_FOREIGNKEY: descriptor("787", "SQLITE_CONSTRAINT_FOREIGNKEY", "FOREIGN KEY constraint failed"),
|
|
63
|
+
SQLITE_CONSTRAINT_NOTNULL: descriptor("1299", "SQLITE_CONSTRAINT_NOTNULL", "NOT NULL constraint failed"),
|
|
64
|
+
SQLITE_CONSTRAINT_PRIMARYKEY: descriptor("1555", "SQLITE_CONSTRAINT_PRIMARYKEY", "PRIMARY KEY constraint failed"),
|
|
65
|
+
SQLITE_CONSTRAINT_UNIQUE: descriptor("2067", "SQLITE_CONSTRAINT_UNIQUE", "UNIQUE constraint failed")
|
|
66
|
+
} as const
|
|
67
|
+
|
|
68
|
+
export type SqliteErrorSymbol = keyof typeof sqliteErrorCatalogBySymbol
|
|
69
|
+
|
|
70
|
+
export type SqliteErrorDescriptor = (typeof sqliteErrorCatalogBySymbol)[SqliteErrorSymbol]
|
|
71
|
+
|
|
72
|
+
export type SqliteErrorNumber = SqliteErrorDescriptor["number"]
|
|
73
|
+
|
|
74
|
+
export type SqliteErrorTag = SqliteErrorDescriptor["tag"]
|
|
75
|
+
|
|
76
|
+
const sqliteErrorDescriptors = Object.values(sqliteErrorCatalogBySymbol)
|
|
77
|
+
|
|
78
|
+
export const sqliteErrorCatalogByNumber = sqliteErrorDescriptors.reduce(
|
|
79
|
+
(acc, entry) => ({
|
|
80
|
+
...acc,
|
|
81
|
+
[entry.number]: [...(acc[entry.number as SqliteErrorNumber] ?? []), entry]
|
|
82
|
+
}),
|
|
83
|
+
{} as Record<SqliteErrorNumber, readonly SqliteErrorDescriptor[]>
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
export const isSqliteErrorSymbol = (value: string): value is SqliteErrorSymbol =>
|
|
87
|
+
value in sqliteErrorCatalogBySymbol
|
|
88
|
+
|
|
89
|
+
export const isSqliteErrorNumber = (value: string): value is SqliteErrorNumber =>
|
|
90
|
+
value in sqliteErrorCatalogByNumber
|
|
91
|
+
|
|
92
|
+
export const getSqliteErrorDescriptor = (
|
|
93
|
+
symbol: SqliteErrorSymbol
|
|
94
|
+
): SqliteErrorDescriptor => sqliteErrorCatalogBySymbol[symbol]
|
|
95
|
+
|
|
96
|
+
export const findSqliteErrorDescriptorsByNumber = (
|
|
97
|
+
number: SqliteErrorNumber
|
|
98
|
+
): readonly SqliteErrorDescriptor[] => sqliteErrorCatalogByNumber[number] ?? []
|
|
99
|
+
|
|
100
|
+
export const findSqliteErrorDescriptorsByNumberLoose = (
|
|
101
|
+
number: string
|
|
102
|
+
): readonly SqliteErrorDescriptor[] | undefined =>
|
|
103
|
+
isSqliteErrorNumber(number) ? sqliteErrorCatalogByNumber[number] : undefined
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Common SQLite driver error fields surfaced by the normalizer when present. */
|
|
2
|
+
export interface SqliteErrorFields {
|
|
3
|
+
readonly code?: string
|
|
4
|
+
readonly errno?: number
|
|
5
|
+
readonly sqlState?: string
|
|
6
|
+
readonly sqlMessage?: string
|
|
7
|
+
readonly fatal?: boolean
|
|
8
|
+
readonly sql?: string
|
|
9
|
+
readonly syscall?: string
|
|
10
|
+
readonly address?: string
|
|
11
|
+
readonly port?: number
|
|
12
|
+
readonly hostname?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Rendered SQL context attached to normalized SQLite execution failures. */
|
|
16
|
+
export interface SqliteQueryContext {
|
|
17
|
+
readonly sql: string
|
|
18
|
+
readonly params: readonly unknown[]
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * from "./catalog.js"
|
|
2
|
+
export * from "./fields.js"
|
|
3
|
+
export * from "./normalize.js"
|
|
4
|
+
export * from "./requirements.js"
|
|
5
|
+
export * from "./types.js"
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
findSqliteErrorDescriptorsByNumber as findSqliteErrorDescriptorsByNumber,
|
|
9
|
+
getSqliteErrorDescriptor as getSqliteErrorDescriptor,
|
|
10
|
+
isSqliteErrorNumber as isSqliteErrorNumber,
|
|
11
|
+
isSqliteErrorSymbol as isSqliteErrorSymbol
|
|
12
|
+
} from "./catalog.js"
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
hasNumber as hasErrorNumber,
|
|
16
|
+
hasSymbol as hasErrorSymbol,
|
|
17
|
+
isSqliteErrorLike as isSqliteErrorLike,
|
|
18
|
+
normalizeSqliteDriverError as normalizeSqliteDriverError
|
|
19
|
+
} from "./normalize.js"
|