effect-qb 0.16.0 → 4.0.0-beta.66
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 +7 -0
- package/dist/mysql.js +1858 -715
- package/dist/postgres/metadata.js +2036 -172
- package/dist/postgres.js +8011 -6849
- package/dist/sqlite.js +8433 -0
- package/package.json +7 -4
- package/src/internal/column-state.d.ts +3 -3
- package/src/internal/column-state.ts +3 -3
- package/src/internal/column.ts +8 -8
- package/src/internal/derived-table.ts +29 -3
- package/src/internal/dialect.ts +3 -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 +100 -43
- 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/context.ts +14 -1
- package/src/internal/predicate/key.ts +19 -2
- package/src/internal/predicate/runtime.ts +27 -3
- package/src/internal/query.d.ts +1 -1
- package/src/internal/query.ts +253 -31
- package/src/internal/renderer.ts +35 -2
- package/src/internal/runtime/driver-value-mapping.ts +60 -2
- package/src/internal/runtime/normalize.ts +62 -38
- package/src/internal/runtime/schema.ts +32 -40
- package/src/internal/runtime/value.ts +159 -39
- package/src/internal/scalar.d.ts +1 -1
- package/src/internal/scalar.ts +1 -1
- package/src/internal/schema-derivation.d.ts +12 -61
- package/src/internal/schema-derivation.ts +95 -43
- package/src/internal/table-options.ts +108 -1
- package/src/internal/table.d.ts +29 -22
- package/src/internal/table.ts +260 -53
- package/src/mysql/column.ts +24 -8
- 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 +4 -4
- package/src/mysql/function/temporal.ts +1 -1
- package/src/mysql/internal/dsl.ts +759 -235
- package/src/mysql/internal/renderer.ts +2 -1
- package/src/mysql/internal/sql-expression-renderer.ts +486 -130
- package/src/mysql/query.ts +9 -2
- package/src/mysql/table.ts +64 -35
- package/src/postgres/column.ts +14 -12
- package/src/postgres/errors/normalize.ts +2 -2
- package/src/postgres/executor.ts +52 -9
- package/src/postgres/function/core.ts +19 -1
- package/src/postgres/function/temporal.ts +1 -1
- package/src/postgres/internal/dsl.ts +705 -256
- package/src/postgres/internal/renderer.ts +2 -1
- 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 +420 -91
- package/src/postgres/json.ts +57 -17
- package/src/postgres/query.ts +9 -2
- package/src/postgres/schema-management.ts +92 -6
- package/src/postgres/schema.ts +1 -1
- package/src/postgres/table.ts +203 -75
- 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 +6927 -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 +175 -0
- package/src/sqlite.ts +22 -0
package/src/mysql/query.ts
CHANGED
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
type HavingPredicateInput,
|
|
17
17
|
type OrderDirection,
|
|
18
18
|
type OutputOfSelection,
|
|
19
|
-
type MutationInputOf,
|
|
20
19
|
type MutationTargetLike,
|
|
21
20
|
type NumericExpressionInput,
|
|
22
21
|
type PredicateInput,
|
|
@@ -136,8 +135,17 @@ export {
|
|
|
136
135
|
orderBy,
|
|
137
136
|
groupBy
|
|
138
137
|
} from "./internal/dsl.js"
|
|
138
|
+
import type * as Expression from "../internal/scalar.js"
|
|
139
139
|
export { mysqlType as type }
|
|
140
140
|
|
|
141
|
+
type MysqlMutationValueInput<Value> =
|
|
142
|
+
| Value
|
|
143
|
+
| Expression.Scalar<Value, Expression.DbType.Any, Expression.Nullability, "mysql", Expression.ScalarKind, Expression.BindingId>
|
|
144
|
+
|
|
145
|
+
export type MutationInputOf<Shape> = {
|
|
146
|
+
readonly [K in keyof Shape]: MysqlMutationValueInput<Shape[K]>
|
|
147
|
+
}
|
|
148
|
+
|
|
141
149
|
type StructuredSource = AnyValuesSource | AnyUnnestSource | AnyTableFunctionSource
|
|
142
150
|
|
|
143
151
|
type StructuredFromApi = <CurrentSource extends StructuredSource>(
|
|
@@ -163,7 +171,6 @@ export type {
|
|
|
163
171
|
HavingPredicateInput,
|
|
164
172
|
OrderDirection,
|
|
165
173
|
OutputOfSelection,
|
|
166
|
-
MutationInputOf,
|
|
167
174
|
MutationTargetLike,
|
|
168
175
|
NumericExpressionInput,
|
|
169
176
|
PredicateInput,
|
package/src/mysql/table.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type * as Schema from "effect/Schema"
|
|
2
|
-
|
|
3
1
|
import type * as Expression from "../internal/scalar.js"
|
|
4
2
|
import { ColumnTypeId, type AnyColumnDefinition } from "../internal/column-state.js"
|
|
5
3
|
import * as BaseTable from "../internal/table.js"
|
|
@@ -33,37 +31,43 @@ export type TableClassStatic<
|
|
|
33
31
|
SchemaName extends string | undefined = undefined
|
|
34
32
|
> = BaseTable.TableClassStatic<Name, Fields, PrimaryKeyColumns, SchemaName>
|
|
35
33
|
|
|
36
|
-
export type AnyTable = BaseTable.AnyTable
|
|
34
|
+
export type AnyTable = BaseTable.AnyTable<Dialect>
|
|
37
35
|
|
|
38
|
-
type FieldsOfTable<Table> = Table
|
|
36
|
+
type FieldsOfTable<Table extends BaseTable.AnyTable> = Table[typeof BaseTable.TypeId]["fields"] extends infer Fields extends DialectFieldMap
|
|
39
37
|
? Fields
|
|
40
|
-
:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
type PrimaryKeyOfTable<Table> = Table
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
38
|
+
: never
|
|
39
|
+
|
|
40
|
+
type ColumnNamesOfTable<Table extends BaseTable.AnyTable> = Extract<keyof FieldsOfTable<Table>, string>
|
|
41
|
+
|
|
42
|
+
type PrimaryKeyOfTable<Table extends BaseTable.AnyTable> = Table[typeof BaseTable.TypeId]["primaryKey"][number]
|
|
43
|
+
|
|
44
|
+
type SchemaNameOfTable<Table extends BaseTable.AnyTable> = Table[typeof BaseTable.TypeId]["schemaName"]
|
|
45
|
+
|
|
46
|
+
type ApplySchemaTableOptions<
|
|
47
|
+
Name extends string,
|
|
48
|
+
Fields extends DialectFieldMap,
|
|
49
|
+
PrimaryKeyColumns extends keyof Fields & string,
|
|
50
|
+
SchemaName extends string,
|
|
51
|
+
Options extends BaseTable.DeclaredTableOptions
|
|
52
|
+
> = BaseTable.ApplyDeclaredOptions<
|
|
53
|
+
BaseTable.TableDefinition<Name, Fields, PrimaryKeyColumns, "schema", SchemaName>,
|
|
54
|
+
Options
|
|
55
|
+
> extends BaseTable.TableDefinition<any, any, infer AppliedPrimaryKeyColumns extends keyof Fields & string, "schema", any>
|
|
56
|
+
? TableDefinition<Name, Fields, AppliedPrimaryKeyColumns, "schema", SchemaName>
|
|
57
|
+
: TableDefinition<Name, Fields, PrimaryKeyColumns, "schema", SchemaName>
|
|
55
58
|
|
|
56
59
|
export type TableSchemaNamespace<SchemaName extends string> = {
|
|
57
60
|
readonly schemaName: SchemaName
|
|
58
61
|
readonly table: <
|
|
59
62
|
Name extends string,
|
|
60
63
|
Fields extends DialectFieldMap,
|
|
64
|
+
const Options extends BaseTable.DeclaredTableOptions,
|
|
61
65
|
PrimaryKeyColumns extends keyof Fields & string = InlinePrimaryKeyKeys<Fields>
|
|
62
66
|
>(
|
|
63
67
|
name: Name,
|
|
64
68
|
fields: Fields,
|
|
65
|
-
...options: BaseTable.
|
|
66
|
-
) =>
|
|
69
|
+
...options: Options & BaseTable.ValidateDeclaredOptions<BaseTable.TableDefinition<Name, Fields, PrimaryKeyColumns, "schema", SchemaName>, Options>
|
|
70
|
+
) => ApplySchemaTableOptions<Name, Fields, PrimaryKeyColumns, SchemaName, Options>
|
|
67
71
|
}
|
|
68
72
|
|
|
69
73
|
export type TableOption = BaseTable.TableOption
|
|
@@ -85,23 +89,31 @@ export const make = <
|
|
|
85
89
|
|
|
86
90
|
export const schema = <SchemaName extends string>(
|
|
87
91
|
schemaName: SchemaName
|
|
88
|
-
): TableSchemaNamespace<SchemaName> =>
|
|
89
|
-
|
|
90
|
-
table: <
|
|
92
|
+
): TableSchemaNamespace<SchemaName> => {
|
|
93
|
+
const table = <
|
|
91
94
|
Name extends string,
|
|
92
95
|
Fields extends DialectFieldMap,
|
|
96
|
+
const Options extends BaseTable.DeclaredTableOptions,
|
|
93
97
|
PrimaryKeyColumns extends keyof Fields & string = InlinePrimaryKeyKeys<Fields>
|
|
94
98
|
>(
|
|
95
99
|
name: Name,
|
|
96
100
|
fields: Fields,
|
|
97
|
-
...declaredOptions: BaseTable.
|
|
101
|
+
...declaredOptions: Options & BaseTable.ValidateDeclaredOptions<BaseTable.TableDefinition<Name, Fields, PrimaryKeyColumns, "schema", SchemaName>, Options>
|
|
98
102
|
) =>
|
|
99
|
-
BaseTable.schema(schemaName).table(
|
|
103
|
+
(BaseTable.schema(schemaName).table as (
|
|
104
|
+
name: Name,
|
|
105
|
+
fields: Fields,
|
|
106
|
+
...options: BaseTable.DeclaredTableOptions
|
|
107
|
+
) => BaseTable.TableDefinition<any, any, any, "schema", any>)(
|
|
100
108
|
name,
|
|
101
109
|
fields,
|
|
102
110
|
...declaredOptions
|
|
103
|
-
) as
|
|
104
|
-
|
|
111
|
+
) as ApplySchemaTableOptions<Name, Fields, PrimaryKeyColumns, SchemaName, Options>
|
|
112
|
+
return {
|
|
113
|
+
schemaName,
|
|
114
|
+
table
|
|
115
|
+
} as unknown as TableSchemaNamespace<SchemaName>
|
|
116
|
+
}
|
|
105
117
|
|
|
106
118
|
export const alias = <
|
|
107
119
|
Table extends AnyTable,
|
|
@@ -144,14 +156,31 @@ export const foreignKey = <
|
|
|
144
156
|
TargetTable extends AnyTable,
|
|
145
157
|
TargetColumns extends string | readonly string[]
|
|
146
158
|
>(
|
|
147
|
-
columns: LocalColumns
|
|
159
|
+
columns: LocalColumns & BaseTable.NonEmptyColumnInput<LocalColumns>,
|
|
148
160
|
target: () => TargetTable,
|
|
149
|
-
referencedColumns: TargetColumns
|
|
150
|
-
): BaseTable.TableOption
|
|
151
|
-
|
|
161
|
+
referencedColumns: TargetColumns & BaseTable.NonEmptyColumnInput<TargetColumns> & BaseTable.MatchingColumnArityInput<LocalColumns, TargetColumns>
|
|
162
|
+
): BaseTable.TableOption<{
|
|
163
|
+
readonly kind: "foreignKey"
|
|
164
|
+
readonly columns: BaseTable.NormalizeColumns<LocalColumns>
|
|
165
|
+
readonly references: () => {
|
|
166
|
+
readonly tableName: string
|
|
167
|
+
readonly schemaName?: string
|
|
168
|
+
readonly columns: BaseTable.NormalizeColumns<TargetColumns>
|
|
169
|
+
readonly knownColumns: readonly ColumnNamesOfTable<TargetTable>[]
|
|
170
|
+
}
|
|
171
|
+
}> =>
|
|
172
|
+
BaseTable.foreignKey<LocalColumns, TargetTable, TargetColumns>(
|
|
173
|
+
columns as LocalColumns & BaseTable.NonEmptyColumnInput<LocalColumns>,
|
|
174
|
+
target,
|
|
175
|
+
referencedColumns as TargetColumns & BaseTable.NonEmptyColumnInput<TargetColumns> & BaseTable.MatchingColumnArityInput<LocalColumns, TargetColumns>
|
|
176
|
+
)
|
|
152
177
|
|
|
153
178
|
export const check = BaseTable.check
|
|
154
179
|
|
|
155
|
-
export
|
|
156
|
-
export
|
|
157
|
-
export
|
|
180
|
+
export const selectSchema = BaseTable.selectSchema
|
|
181
|
+
export const insertSchema = BaseTable.insertSchema
|
|
182
|
+
export const updateSchema = BaseTable.updateSchema
|
|
183
|
+
|
|
184
|
+
export type SelectOf<Table extends AnyTable> = BaseTable.SelectOf<Table>
|
|
185
|
+
export type InsertOf<Table extends AnyTable> = BaseTable.InsertOf<Table>
|
|
186
|
+
export type UpdateOf<Table extends AnyTable> = BaseTable.UpdateOf<Table>
|
package/src/postgres/column.ts
CHANGED
|
@@ -29,7 +29,7 @@ const enrichDbType = <Db extends Expression.DbType.Any>(dbType: Db): Db => {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
const primitive = <Type, Db extends Expression.DbType.Any>(
|
|
32
|
-
schema: Schema.Schema<Type
|
|
32
|
+
schema: Schema.Schema<Type>,
|
|
33
33
|
dbType: Db
|
|
34
34
|
): ColumnDefinition<Type, Type, Type, Db, false, false, false, false, false, undefined> =>
|
|
35
35
|
makeColumnDefinition(schema as Schema.Schema<NonNullable<Type>>, {
|
|
@@ -57,13 +57,15 @@ const renderNumericDdlType = (
|
|
|
57
57
|
const boundedString = (length?: number): Schema.Schema<string> =>
|
|
58
58
|
length === undefined
|
|
59
59
|
? Schema.String
|
|
60
|
-
: Schema.String.
|
|
60
|
+
: Schema.String.check(Schema.isMaxLength(length))
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
const finiteNumber = Schema.Number.check(Schema.isFinite())
|
|
63
|
+
|
|
64
|
+
export const custom = <SchemaType extends Schema.Top, Db extends Expression.DbType.Any>(
|
|
63
65
|
schema: SchemaType,
|
|
64
66
|
dbType: Db
|
|
65
67
|
) =>
|
|
66
|
-
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType
|
|
68
|
+
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>>, {
|
|
67
69
|
dbType: enrichDbType(dbType),
|
|
68
70
|
nullable: false,
|
|
69
71
|
hasDefault: false,
|
|
@@ -75,7 +77,7 @@ export const custom = <SchemaType extends Schema.Schema.Any, Db extends Expressi
|
|
|
75
77
|
identity: undefined
|
|
76
78
|
})
|
|
77
79
|
|
|
78
|
-
export const uuid = () => primitive(Schema.
|
|
80
|
+
export const uuid = () => primitive(Schema.String.check(Schema.isUUID()), postgresDatatypes.uuid())
|
|
79
81
|
export const text = () => primitive(Schema.String, postgresDatatypes.text())
|
|
80
82
|
export const int = () => primitive(Schema.Int, postgresDatatypes.int4())
|
|
81
83
|
export const int2 = () => primitive(Schema.Int, postgresDatatypes.int2())
|
|
@@ -92,8 +94,8 @@ export const number = (options?: BaseColumn.NumericOptions) =>
|
|
|
92
94
|
ddlType: renderNumericDdlType("numeric", options),
|
|
93
95
|
identity: undefined
|
|
94
96
|
})
|
|
95
|
-
export const float4 = () => primitive(
|
|
96
|
-
export const float8 = () => primitive(
|
|
97
|
+
export const float4 = () => primitive(finiteNumber, postgresDatatypes.float4())
|
|
98
|
+
export const float8 = () => primitive(finiteNumber, postgresDatatypes.float8())
|
|
97
99
|
export const boolean = () => primitive(Schema.Boolean, postgresDatatypes.boolean())
|
|
98
100
|
export const date = () => primitive(LocalDateStringSchema, postgresDatatypes.date())
|
|
99
101
|
export const timestamp = () => primitive(LocalDateTimeStringSchema, postgresDatatypes.timestamp())
|
|
@@ -101,7 +103,7 @@ export const time = () => primitive(LocalTimeStringSchema, postgresDatatypes.tim
|
|
|
101
103
|
export const timetz = () => primitive(OffsetTimeStringSchema, postgresDatatypes.timetz())
|
|
102
104
|
export const timestamptz = () => primitive(InstantStringSchema, postgresDatatypes.timestamptz())
|
|
103
105
|
export const interval = () => primitive(Schema.String, postgresDatatypes.interval())
|
|
104
|
-
export const bytea = () => primitive(Schema.
|
|
106
|
+
export const bytea = () => primitive(Schema.Uint8Array, postgresDatatypes.bytea())
|
|
105
107
|
export const name = () => primitive(Schema.String, postgresDatatypes.name())
|
|
106
108
|
export const oid = () => primitive(Schema.Int, postgresDatatypes.oid())
|
|
107
109
|
export const regclass = () => primitive(Schema.String, postgresDatatypes.regclass())
|
|
@@ -133,8 +135,8 @@ export const varchar = (length?: number) =>
|
|
|
133
135
|
ddlType: length === undefined ? "varchar" : `varchar(${length})`,
|
|
134
136
|
identity: undefined
|
|
135
137
|
})
|
|
136
|
-
export const json = <SchemaType extends Schema.
|
|
137
|
-
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType
|
|
138
|
+
export const json = <SchemaType extends Schema.Top>(schema: SchemaType) =>
|
|
139
|
+
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>>, {
|
|
138
140
|
dbType: postgresDatatypes.json(),
|
|
139
141
|
nullable: false,
|
|
140
142
|
hasDefault: false,
|
|
@@ -145,8 +147,8 @@ export const json = <SchemaType extends Schema.Schema.Any>(schema: SchemaType) =
|
|
|
145
147
|
ddlType: undefined,
|
|
146
148
|
identity: undefined
|
|
147
149
|
})
|
|
148
|
-
export const jsonb = <SchemaType extends Schema.
|
|
149
|
-
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType
|
|
150
|
+
export const jsonb = <SchemaType extends Schema.Top>(schema: SchemaType) =>
|
|
151
|
+
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>>, {
|
|
150
152
|
dbType: postgresDatatypes.jsonb(),
|
|
151
153
|
nullable: false,
|
|
152
154
|
hasDefault: false,
|
|
@@ -44,8 +44,8 @@ const asNumber = (value: unknown): number | undefined => {
|
|
|
44
44
|
if (typeof value === "number" && Number.isFinite(value)) {
|
|
45
45
|
return value
|
|
46
46
|
}
|
|
47
|
-
if (typeof value === "string" && value.trim()
|
|
48
|
-
const parsed = Number(value)
|
|
47
|
+
if (typeof value === "string" && /^[+-]?\d+$/.test(value.trim())) {
|
|
48
|
+
const parsed = Number(value.trim())
|
|
49
49
|
return Number.isFinite(parsed) ? parsed : undefined
|
|
50
50
|
}
|
|
51
51
|
return undefined
|
package/src/postgres/executor.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect"
|
|
2
|
-
import * as SqlClient from "
|
|
2
|
+
import * as SqlClient from "effect/unstable/sql/SqlClient"
|
|
3
3
|
import * as Stream from "effect/Stream"
|
|
4
4
|
|
|
5
5
|
import * as CoreExecutor from "../internal/executor.js"
|
|
@@ -55,12 +55,55 @@ export interface QueryExecutor<Context = never> {
|
|
|
55
55
|
): Stream.Stream<CoreQuery.ResultRow<PlanValue>, PostgresQueryError<PlanValue>, Context>
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
type DriverExecute<Error, Context> = <Row>(
|
|
59
|
+
query: CoreRenderer.RenderedQuery<Row, "postgres">
|
|
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, "postgres">
|
|
66
|
+
) => Stream.Stream<FlatRow, Error, Context>
|
|
67
|
+
}
|
|
68
|
+
|
|
58
69
|
/** Constructs a Postgres-specialized SQL driver. */
|
|
59
|
-
export function driver
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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: "postgres",
|
|
87
|
+
execute: DriverExecute<Error, Context>
|
|
88
|
+
): Driver<Error, Context>
|
|
89
|
+
export function driver<
|
|
90
|
+
Error = never,
|
|
91
|
+
Context = never
|
|
92
|
+
>(
|
|
93
|
+
dialect: "postgres",
|
|
94
|
+
handlers: DriverHandlers<Error, Context>
|
|
95
|
+
): Driver<Error, Context>
|
|
96
|
+
export function driver<
|
|
97
|
+
Error = never,
|
|
98
|
+
Context = never
|
|
99
|
+
>(
|
|
100
|
+
dialectOrExecute: "postgres" | 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("postgres", executeOrHandlers)
|
|
106
|
+
: CoreExecutor.driver("postgres", executeOrHandlers as DriverHandlers<Error, Context>)
|
|
64
107
|
}
|
|
65
108
|
|
|
66
109
|
const fromDriver = <
|
|
@@ -97,10 +140,10 @@ const fromDriver = <
|
|
|
97
140
|
stream(plan) {
|
|
98
141
|
const rendered = renderer.render(plan)
|
|
99
142
|
return Stream.mapError(
|
|
100
|
-
Stream.
|
|
143
|
+
Stream.mapArrayEffect(
|
|
101
144
|
sqlDriver.stream(rendered),
|
|
102
145
|
(rows) => Effect.try({
|
|
103
|
-
try: () => CoreExecutor.
|
|
146
|
+
try: () => CoreExecutor.decodeRows(rendered, plan, rows, { driverMode, valueMappings }) as never,
|
|
104
147
|
catch: (error) => error as RowDecodeError
|
|
105
148
|
})
|
|
106
149
|
),
|
|
@@ -130,7 +173,7 @@ const sqlClientDriver = (): Driver<any, SqlClient.SqlClient> =>
|
|
|
130
173
|
* Creates the standard Postgres executor pipeline.
|
|
131
174
|
*
|
|
132
175
|
* By default this uses the built-in Postgres renderer plus the ambient
|
|
133
|
-
*
|
|
176
|
+
* `effect/unstable/sql` `SqlClient`. Advanced callers can override the renderer,
|
|
134
177
|
* driver, or both.
|
|
135
178
|
*/
|
|
136
179
|
export function make(): QueryExecutor<SqlClient.SqlClient>
|
|
@@ -12,11 +12,29 @@ import { isSequenceDefinition, type SequenceDefinition } from "../schema-managem
|
|
|
12
12
|
|
|
13
13
|
/** Postgres scalar core functions. */
|
|
14
14
|
export { coalesce, call, uuidGenerateV4 }
|
|
15
|
+
|
|
16
|
+
const safeUnquotedIdentifier = /^[a-z_][a-z0-9_$]*$/
|
|
17
|
+
|
|
18
|
+
const quoteIdentifier = (value: string): string =>
|
|
19
|
+
`"${value.replaceAll("\"", "\"\"")}"`
|
|
20
|
+
|
|
21
|
+
const renderIdentifier = (value: string): string =>
|
|
22
|
+
safeUnquotedIdentifier.test(value)
|
|
23
|
+
? value
|
|
24
|
+
: quoteIdentifier(value)
|
|
25
|
+
|
|
26
|
+
const renderQualifiedSequenceName = (
|
|
27
|
+
value: SequenceDefinition<string, string | undefined>
|
|
28
|
+
): string =>
|
|
29
|
+
value.schemaName === undefined || value.schemaName === "public"
|
|
30
|
+
? renderIdentifier(value.name)
|
|
31
|
+
: `${renderIdentifier(value.schemaName)}.${renderIdentifier(value.name)}`
|
|
32
|
+
|
|
15
33
|
export const nextVal = (
|
|
16
34
|
value: ExpressionInput | SequenceDefinition<string, string | undefined>
|
|
17
35
|
) =>
|
|
18
36
|
nextValInternal(
|
|
19
37
|
isSequenceDefinition(value)
|
|
20
|
-
? cast(literal(value
|
|
38
|
+
? cast(literal(renderQualifiedSequenceName(value)), postgresType.regclass())
|
|
21
39
|
: value
|
|
22
40
|
)
|
|
@@ -39,7 +39,7 @@ const makeTemporal = <
|
|
|
39
39
|
>(
|
|
40
40
|
name: Name,
|
|
41
41
|
dbType: Db,
|
|
42
|
-
runtimeSchema: Schema.Schema<Runtime
|
|
42
|
+
runtimeSchema: Schema.Schema<Runtime>
|
|
43
43
|
): TemporalExpression<Runtime, Db, Name> =>
|
|
44
44
|
makeExpression({
|
|
45
45
|
runtime: undefined as unknown as Runtime,
|