effect-qb 0.17.0 → 0.20.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 +11 -1
- package/dist/index.js +9376 -0
- package/dist/mysql.js +4092 -2671
- package/dist/postgres/metadata.js +2589 -1402
- package/dist/postgres.js +3953 -3583
- package/dist/sqlite.js +5527 -4088
- package/dist/standard.js +9330 -0
- package/package.json +9 -4
- 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.d.ts +3 -3
- package/src/internal/column-state.ts +24 -18
- package/src/internal/column.ts +52 -15
- 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 +36 -1
- 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 +66 -49
- 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 +39 -12
- package/src/internal/query.ts +65 -26
- package/src/internal/renderer.ts +26 -14
- package/src/internal/runtime/driver-value-mapping.ts +3 -3
- package/src/internal/runtime/normalize.ts +12 -5
- package/src/internal/runtime/schema.ts +28 -38
- package/src/internal/runtime/value.ts +20 -23
- package/src/internal/scalar.d.ts +1 -1
- package/src/internal/scalar.ts +8 -2
- package/src/internal/schema-derivation.d.ts +12 -61
- package/src/internal/schema-derivation.ts +95 -43
- 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 +819 -237
- package/src/mysql/column-extension.ts +3 -0
- package/src/mysql/column.ts +14 -15
- 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 +11 -11
- package/src/mysql/function/temporal.ts +1 -1
- package/src/mysql/internal/dialect.ts +9 -4
- package/src/mysql/internal/dsl.ts +334 -170
- 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 +13 -19
- 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 +11 -11
- 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/function/temporal.ts +1 -1
- package/src/postgres/index.ts +1 -0
- package/src/postgres/internal/dialect.ts +9 -4
- package/src/postgres/internal/dsl.ts +328 -179
- 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 +13 -13
- package/src/postgres/schema.ts +106 -15
- package/src/postgres/table.ts +205 -538
- 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 +14 -15
- 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 +11 -11
- package/src/sqlite/function/temporal.ts +1 -1
- package/src/sqlite/internal/dialect.ts +9 -4
- package/src/sqlite/internal/dsl.ts +307 -159
- 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 -173
- package/src/mysql/table.ts +0 -183
- package/src/postgres/cast.ts +0 -45
- package/src/sqlite/table.ts +0 -183
package/src/postgres/executor.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
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"
|
|
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 { PostgresDatatypeFamily, PostgresDatatypeKind } from "./datatypes/spec.js"
|
|
9
10
|
import { renderPostgresPlan } from "./internal/renderer.js"
|
|
10
11
|
import {
|
|
11
12
|
narrowPostgresDriverErrorForReadQuery,
|
|
@@ -24,12 +25,13 @@ export type Driver<Error = never, Context = never> = CoreExecutor.Driver<"postgr
|
|
|
24
25
|
export type Executor<Error = never, Context = never> = CoreExecutor.Executor<"postgres", Error, Context>
|
|
25
26
|
/** Postgres-specialized renderer contract. */
|
|
26
27
|
export type Renderer = CoreRenderer.Renderer<"postgres">
|
|
28
|
+
export type ValueMappings = Expression.DriverValueMappingsFor<PostgresDatatypeKind, PostgresDatatypeFamily>
|
|
27
29
|
/** Optional renderer / driver overrides for the standard Postgres 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 Postgres executors. */
|
|
35
37
|
export type PostgresExecutorError = PostgresDriverError | RowDecodeError
|
|
@@ -39,8 +41,6 @@ export type PostgresQueryError<PlanValue extends CoreQuery.QueryPlan<any, any, a
|
|
|
39
41
|
|
|
40
42
|
/** Runs an effect within the ambient Postgres SQL transaction service. */
|
|
41
43
|
export const withTransaction = CoreExecutor.withTransaction
|
|
42
|
-
/** Runs an effect in a nested Postgres SQL transaction scope. */
|
|
43
|
-
export const withSavepoint = CoreExecutor.withSavepoint
|
|
44
44
|
|
|
45
45
|
/** Postgres executor whose error channel narrows based on the query plan. */
|
|
46
46
|
export interface QueryExecutor<Context = never> {
|
|
@@ -140,10 +140,10 @@ const fromDriver = <
|
|
|
140
140
|
stream(plan) {
|
|
141
141
|
const rendered = renderer.render(plan)
|
|
142
142
|
return Stream.mapError(
|
|
143
|
-
Stream.
|
|
143
|
+
Stream.mapArrayEffect(
|
|
144
144
|
sqlDriver.stream(rendered),
|
|
145
145
|
(rows) => Effect.try({
|
|
146
|
-
try: () => CoreExecutor.
|
|
146
|
+
try: () => CoreExecutor.decodeRows(rendered, plan, rows, { driverMode, valueMappings }) as never,
|
|
147
147
|
catch: (error) => error as RowDecodeError
|
|
148
148
|
})
|
|
149
149
|
),
|
|
@@ -173,7 +173,7 @@ const sqlClientDriver = (): Driver<any, SqlClient.SqlClient> =>
|
|
|
173
173
|
* Creates the standard Postgres executor pipeline.
|
|
174
174
|
*
|
|
175
175
|
* By default this uses the built-in Postgres renderer plus the ambient
|
|
176
|
-
*
|
|
176
|
+
* `effect/unstable/sql` `SqlClient`. Advanced callers can override the renderer,
|
|
177
177
|
* driver, or both.
|
|
178
178
|
*/
|
|
179
179
|
export function make(): QueryExecutor<SqlClient.SqlClient>
|
|
@@ -181,7 +181,7 @@ export function make(
|
|
|
181
181
|
options: {
|
|
182
182
|
readonly renderer?: Renderer
|
|
183
183
|
readonly driverMode?: CoreExecutor.DriverMode
|
|
184
|
-
readonly valueMappings?:
|
|
184
|
+
readonly valueMappings?: ValueMappings
|
|
185
185
|
}
|
|
186
186
|
): QueryExecutor<SqlClient.SqlClient>
|
|
187
187
|
export function make<Error = never, Context = never>(
|
|
@@ -189,7 +189,7 @@ export function make<Error = never, Context = never>(
|
|
|
189
189
|
readonly renderer?: Renderer
|
|
190
190
|
readonly driver: Driver<Error, Context>
|
|
191
191
|
readonly driverMode?: CoreExecutor.DriverMode
|
|
192
|
-
readonly valueMappings?:
|
|
192
|
+
readonly valueMappings?: ValueMappings
|
|
193
193
|
}
|
|
194
194
|
): QueryExecutor<Context>
|
|
195
195
|
export function make<Error = never, Context = never>(
|
|
@@ -197,14 +197,14 @@ export function make<Error = never, Context = never>(
|
|
|
197
197
|
): QueryExecutor<any> {
|
|
198
198
|
if (options.driver) {
|
|
199
199
|
return fromDriver(
|
|
200
|
-
options.renderer ?? CoreRenderer.
|
|
200
|
+
options.renderer ?? CoreRenderer.makeTrusted("postgres", (plan) => renderPostgresPlan(plan, { valueMappings: options.valueMappings })),
|
|
201
201
|
options.driver,
|
|
202
202
|
options.driverMode,
|
|
203
203
|
options.valueMappings
|
|
204
204
|
)
|
|
205
205
|
}
|
|
206
206
|
return fromDriver(
|
|
207
|
-
options.renderer ?? CoreRenderer.
|
|
207
|
+
options.renderer ?? CoreRenderer.makeTrusted("postgres", (plan) => renderPostgresPlan(plan, { valueMappings: options.valueMappings })),
|
|
208
208
|
sqlClientDriver(),
|
|
209
209
|
options.driverMode,
|
|
210
210
|
options.valueMappings
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as BaseTable from "../internal/table.js"
|
|
2
|
+
import type { TableOptionSpec } from "../internal/table-options.js"
|
|
3
|
+
|
|
4
|
+
type ForeignKeySpec = Extract<TableOptionSpec, { readonly kind: "foreignKey" }>
|
|
5
|
+
|
|
6
|
+
export const deferrable = <Spec extends ForeignKeySpec, 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 ForeignKeySpec, 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 }))
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { ExpressionInput } from "../query.js"
|
|
2
2
|
import {
|
|
3
|
-
call,
|
|
4
3
|
cast,
|
|
5
|
-
coalesce,
|
|
6
4
|
literal,
|
|
7
5
|
nextVal as nextValInternal,
|
|
8
6
|
type as postgresType,
|
|
@@ -11,7 +9,7 @@ import {
|
|
|
11
9
|
import { isSequenceDefinition, type SequenceDefinition } from "../schema-management.js"
|
|
12
10
|
|
|
13
11
|
/** Postgres scalar core functions. */
|
|
14
|
-
export {
|
|
12
|
+
export { uuidGenerateV4 }
|
|
15
13
|
|
|
16
14
|
const safeUnquotedIdentifier = /^[a-z_][a-z0-9_$]*$/
|
|
17
15
|
|
|
@@ -1,19 +1,3 @@
|
|
|
1
1
|
export * as core from "./core.js"
|
|
2
|
-
export * as string from "./string.js"
|
|
3
|
-
export * as aggregate from "./aggregate.js"
|
|
4
|
-
export * as window from "./window.js"
|
|
5
|
-
export * as temporal from "./temporal.js"
|
|
6
2
|
|
|
7
|
-
export {
|
|
8
|
-
export { call, uuidGenerateV4, nextVal } from "./core.js"
|
|
9
|
-
export { lower, upper, concat } from "./string.js"
|
|
10
|
-
export { count, max, min } from "./aggregate.js"
|
|
11
|
-
export { over, rowNumber, rank, denseRank } from "./window.js"
|
|
12
|
-
export {
|
|
13
|
-
currentDate,
|
|
14
|
-
currentTime,
|
|
15
|
-
currentTimestamp,
|
|
16
|
-
localTime,
|
|
17
|
-
localTimestamp,
|
|
18
|
-
now
|
|
19
|
-
} from "./temporal.js"
|
|
3
|
+
export { uuidGenerateV4, nextVal } from "./core.js"
|
|
@@ -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,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { include, key, keys, uniqueIndex, using, where } from "./table.js"
|
|
@@ -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/postgres.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, {
|
|
@@ -23,11 +25,12 @@ const renderLiteral = (value: unknown, state: RenderState, context: RenderValueC
|
|
|
23
25
|
* Built-in runtime dialect implementation for Postgres.
|
|
24
26
|
*/
|
|
25
27
|
export const postgresDialect: SqlDialect<"postgres"> = {
|
|
28
|
+
...standardDialect,
|
|
26
29
|
name: "postgres",
|
|
27
30
|
quoteIdentifier,
|
|
28
31
|
renderLiteral,
|
|
29
32
|
renderTableReference(tableName, baseTableName, schemaName) {
|
|
30
|
-
const renderedBase = schemaName
|
|
33
|
+
const renderedBase = schemaName && schemaName !== "public"
|
|
31
34
|
? `${quoteIdentifier(schemaName)}.${quoteIdentifier(baseTableName)}`
|
|
32
35
|
: quoteIdentifier(baseTableName)
|
|
33
36
|
return tableName === baseTableName
|
|
@@ -36,5 +39,7 @@ export const postgresDialect: SqlDialect<"postgres"> = {
|
|
|
36
39
|
},
|
|
37
40
|
renderConcat(values) {
|
|
38
41
|
return `(${values.join(" || ")})`
|
|
39
|
-
}
|
|
42
|
+
},
|
|
43
|
+
renderQueryAst,
|
|
44
|
+
renderExpression
|
|
40
45
|
}
|