effect-qb 0.17.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 +3053 -2505
- package/dist/postgres/metadata.js +1366 -1250
- package/dist/postgres.js +2020 -2719
- package/dist/sqlite.js +3226 -2732
- package/dist/standard.js +8019 -0
- package/package.json +10 -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 +4 -36
- package/src/{mysql/internal/sql-expression-renderer.ts → internal/dialect-renderers/mysql.ts} +548 -359
- package/src/{postgres/internal/sql-expression-renderer.ts → internal/dialect-renderers/postgres.ts} +654 -399
- package/src/{sqlite/internal/sql-expression-renderer.ts → internal/dialect-renderers/sqlite.ts} +501 -345
- package/src/internal/dialect.ts +35 -0
- package/src/internal/dsl-mutation-runtime.ts +12 -162
- package/src/internal/dsl-plan-runtime.ts +10 -138
- package/src/internal/dsl-query-runtime.ts +5 -79
- package/src/internal/dsl-transaction-ddl-runtime.ts +41 -65
- package/src/internal/executor.ts +10 -6
- package/src/internal/grouping-key.ts +87 -20
- package/src/internal/implication-runtime.ts +1 -1
- package/src/internal/predicate/runtime.ts +3 -0
- package/src/internal/query.d.ts +38 -11
- package/src/internal/query.ts +64 -25
- package/src/internal/renderer.ts +26 -14
- package/src/internal/runtime/normalize.ts +12 -5
- package/src/internal/scalar.ts +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 +126 -66
- package/src/internal/table.d.ts +33 -32
- package/src/internal/table.ts +406 -155
- package/src/mysql/column-extension.ts +3 -0
- package/src/mysql/column.ts +10 -11
- package/src/mysql/datatypes/index.ts +3 -2
- package/src/mysql/executor.ts +7 -5
- package/src/mysql/internal/dialect.ts +9 -4
- package/src/mysql/internal/dsl.ts +219 -155
- package/src/mysql/internal/renderer.ts +6 -2
- package/src/mysql/json.ts +37 -0
- package/src/mysql/query-extension.ts +16 -0
- 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 +5 -11
- package/src/postgres/datatypes/index.d.ts +2 -1
- package/src/postgres/datatypes/index.ts +3 -2
- package/src/postgres/executor.ts +7 -5
- package/src/postgres/function/core.ts +1 -3
- package/src/postgres/function/index.ts +1 -17
- package/src/postgres/internal/dialect.ts +9 -4
- package/src/postgres/internal/dsl.ts +208 -160
- 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.ts +43 -7
- package/src/postgres/jsonb.ts +38 -0
- package/src/postgres/query-extension.ts +2 -0
- package/src/postgres/renderer.ts +31 -4
- package/src/postgres/schema-management.ts +17 -12
- package/src/postgres/schema.ts +98 -15
- package/src/postgres/table.ts +193 -524
- 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 +10 -11
- package/src/sqlite/datatypes/index.ts +3 -2
- package/src/sqlite/executor.ts +7 -5
- package/src/sqlite/internal/dialect.ts +9 -4
- package/src/sqlite/internal/dsl.ts +208 -155
- package/src/sqlite/internal/renderer.ts +6 -2
- package/src/sqlite/json.ts +37 -0
- package/src/sqlite/query-extension.ts +2 -0
- package/src/sqlite/renderer.ts +31 -4
- package/src/sqlite.ts +4 -12
- 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 -183
- package/src/sqlite/table.ts +0 -183
package/src/postgres/type.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type * as Expression from "../internal/scalar.js"
|
|
2
|
+
import type { NonEmptyStringInput } from "../internal/table-options.js"
|
|
2
3
|
import { postgresDatatypes } from "./datatypes/index.js"
|
|
3
4
|
import { type as postgresType } from "./internal/dsl.js"
|
|
4
5
|
|
|
@@ -7,24 +8,24 @@ type PostgresTypeNamespace = typeof postgresDatatypes & {
|
|
|
7
8
|
element: Element
|
|
8
9
|
) => Expression.DbType.Array<"postgres", Element, `${Element["kind"]}[]`>
|
|
9
10
|
readonly range: <Kind extends string, Subtype extends Expression.DbType.Any>(
|
|
10
|
-
kind: Kind
|
|
11
|
+
kind: NonEmptyStringInput<Kind>,
|
|
11
12
|
subtype: Subtype
|
|
12
13
|
) => Expression.DbType.Range<"postgres", Subtype, Kind>
|
|
13
14
|
readonly multirange: <Kind extends string, Subtype extends Expression.DbType.Any>(
|
|
14
|
-
kind: Kind
|
|
15
|
+
kind: NonEmptyStringInput<Kind>,
|
|
15
16
|
subtype: Subtype
|
|
16
17
|
) => Expression.DbType.Multirange<"postgres", Subtype, Kind>
|
|
17
18
|
readonly record: <Kind extends string, Fields extends Record<string, Expression.DbType.Any>>(
|
|
18
|
-
kind: Kind
|
|
19
|
+
kind: NonEmptyStringInput<Kind>,
|
|
19
20
|
fields: Fields
|
|
20
21
|
) => Expression.DbType.Composite<"postgres", Fields, Kind>
|
|
21
22
|
readonly domain: <Kind extends string, Base extends Expression.DbType.Any>(
|
|
22
|
-
kind: Kind
|
|
23
|
+
kind: NonEmptyStringInput<Kind>,
|
|
23
24
|
base: Base
|
|
24
25
|
) => Expression.DbType.Domain<"postgres", Base, Kind>
|
|
25
|
-
readonly enum: <Kind extends string>(kind: Kind) => Expression.DbType.Enum<"postgres", Kind>
|
|
26
|
-
readonly set: <Kind extends string>(kind: Kind) => Expression.DbType.Set<"postgres", Kind>
|
|
27
|
-
readonly custom: <Kind extends string>(kind: Kind) => Expression.DbType.Base<"postgres", Kind>
|
|
26
|
+
readonly enum: <Kind extends string>(kind: NonEmptyStringInput<Kind>) => Expression.DbType.Enum<"postgres", Kind>
|
|
27
|
+
readonly set: <Kind extends string>(kind: NonEmptyStringInput<Kind>) => Expression.DbType.Set<"postgres", Kind>
|
|
28
|
+
readonly custom: <Kind extends string>(kind: NonEmptyStringInput<Kind>) => Expression.DbType.Base<"postgres", Kind>
|
|
28
29
|
readonly driverValueMapping: <Db extends Expression.DbType.Any>(
|
|
29
30
|
dbType: Db,
|
|
30
31
|
mapping: Expression.DriverValueMapping
|
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"
|
package/src/sqlite/column.ts
CHANGED
|
@@ -3,6 +3,8 @@ import * as Schema from "effect/Schema"
|
|
|
3
3
|
import * as BaseColumn from "../internal/column.js"
|
|
4
4
|
import { makeColumnDefinition, type AnyColumnDefinition, type ColumnDefinition } from "../internal/column-state.js"
|
|
5
5
|
import type * as Expression from "../internal/scalar.js"
|
|
6
|
+
import type { NonEmptyStringInput } from "../internal/table-options.js"
|
|
7
|
+
import { enrichDbType } from "../internal/datatypes/enrich.js"
|
|
6
8
|
import {
|
|
7
9
|
DecimalStringSchema,
|
|
8
10
|
LocalDateStringSchema,
|
|
@@ -15,13 +17,6 @@ import {
|
|
|
15
17
|
} from "../internal/runtime/value.js"
|
|
16
18
|
import { sqliteDatatypes } from "./datatypes/index.js"
|
|
17
19
|
|
|
18
|
-
const enrichDbType = <Db extends Expression.DbType.Any>(dbType: Db): Db => {
|
|
19
|
-
const candidate = (sqliteDatatypes as unknown as Record<string, (() => Expression.DbType.Any) | undefined>)[dbType.kind]
|
|
20
|
-
return typeof candidate === "function"
|
|
21
|
-
? { ...candidate(), ...dbType } as Db
|
|
22
|
-
: dbType
|
|
23
|
-
}
|
|
24
|
-
|
|
25
20
|
const primitive = <Type, Db extends Expression.DbType.Any>(
|
|
26
21
|
schema: Schema.Schema<Type, any, any>,
|
|
27
22
|
dbType: Db
|
|
@@ -52,8 +47,8 @@ export const custom = <SchemaType extends Schema.Schema.Any, Db extends Expressi
|
|
|
52
47
|
schema: SchemaType,
|
|
53
48
|
dbType: Db
|
|
54
49
|
) =>
|
|
55
|
-
makeColumnDefinition(schema as
|
|
56
|
-
dbType: enrichDbType(dbType),
|
|
50
|
+
makeColumnDefinition(schema as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>, any, any>, {
|
|
51
|
+
dbType: enrichDbType(sqliteDatatypes, dbType),
|
|
57
52
|
nullable: false,
|
|
58
53
|
hasDefault: false,
|
|
59
54
|
generated: false,
|
|
@@ -85,7 +80,7 @@ export const time = () => primitive(LocalTimeStringSchema, sqliteDatatypes.time(
|
|
|
85
80
|
export const datetime = () => primitive(LocalDateTimeStringSchema, sqliteDatatypes.datetime())
|
|
86
81
|
export const timestamp = () => primitive(LocalDateTimeStringSchema, sqliteDatatypes.timestamp())
|
|
87
82
|
export const json = <SchemaType extends Schema.Schema.Any>(schema: SchemaType) =>
|
|
88
|
-
makeColumnDefinition(schema as
|
|
83
|
+
makeColumnDefinition(schema as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>, any, any>, {
|
|
89
84
|
dbType: { ...sqliteDatatypes.json(), variant: "json" } as Expression.DbType.Json<"sqlite", "json">,
|
|
90
85
|
nullable: false,
|
|
91
86
|
hasDefault: false,
|
|
@@ -109,10 +104,14 @@ type SqliteUniqueOptions = {
|
|
|
109
104
|
readonly initiallyDeferred?: never
|
|
110
105
|
}
|
|
111
106
|
|
|
107
|
+
type NonEmptyOptionNameInput<Options> = Options extends { readonly name: infer Name extends string }
|
|
108
|
+
? NonEmptyStringInput<Name> extends never ? never : unknown
|
|
109
|
+
: unknown
|
|
110
|
+
|
|
112
111
|
type UniqueModifier = {
|
|
113
112
|
<Column extends AnyColumnDefinition>(column: Column): UniqueColumn<Column>
|
|
114
113
|
readonly options: <const Options extends SqliteUniqueOptions>(
|
|
115
|
-
options: Options
|
|
114
|
+
options: Options & NonEmptyOptionNameInput<Options>
|
|
116
115
|
) => <Column extends AnyColumnDefinition>(column: Column) => UniqueColumn<Column>
|
|
117
116
|
}
|
|
118
117
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DatatypeModule } from "../../internal/datatypes/define.js"
|
|
2
2
|
import type * as Expression from "../../internal/scalar.js"
|
|
3
|
+
import type { NonEmptyStringInput } from "../../internal/table-options.js"
|
|
3
4
|
import { sqliteDatatypeFamilies, sqliteDatatypeKinds } from "./spec.js"
|
|
4
5
|
|
|
5
6
|
const withMetadata = <Kind extends keyof typeof sqliteDatatypeKinds & string>(
|
|
@@ -19,9 +20,9 @@ const withMetadata = <Kind extends keyof typeof sqliteDatatypeKinds & string>(
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
const sqliteDatatypeModule = {
|
|
22
|
-
custom: (kind:
|
|
23
|
+
custom: <Kind extends string>(kind: NonEmptyStringInput<Kind>) => ({
|
|
23
24
|
dialect: "sqlite",
|
|
24
|
-
kind
|
|
25
|
+
kind: kind as Kind
|
|
25
26
|
}),
|
|
26
27
|
uuid: () => ({
|
|
27
28
|
dialect: "sqlite",
|
package/src/sqlite/executor.ts
CHANGED
|
@@ -6,6 +6,7 @@ import * as CoreExecutor from "../internal/executor.js"
|
|
|
6
6
|
import * as CoreQuery from "../internal/query.js"
|
|
7
7
|
import * as CoreRenderer from "../internal/renderer.js"
|
|
8
8
|
import type * as Expression from "../internal/scalar.js"
|
|
9
|
+
import type { SqliteDatatypeFamily, SqliteDatatypeKind } from "./datatypes/spec.js"
|
|
9
10
|
import { renderSqlitePlan } from "./internal/renderer.js"
|
|
10
11
|
import {
|
|
11
12
|
narrowSqliteDriverErrorForReadQuery,
|
|
@@ -24,12 +25,13 @@ export type Driver<Error = never, Context = never> = CoreExecutor.Driver<"sqlite
|
|
|
24
25
|
export type Executor<Error = never, Context = never> = CoreExecutor.Executor<"sqlite", Error, Context>
|
|
25
26
|
/** SQLite-specialized renderer contract. */
|
|
26
27
|
export type Renderer = CoreRenderer.Renderer<"sqlite">
|
|
28
|
+
export type ValueMappings = Expression.DriverValueMappingsFor<SqliteDatatypeKind | "uuid", SqliteDatatypeFamily | "uuid">
|
|
27
29
|
/** Optional renderer / driver overrides for the standard SQLite executor pipeline. */
|
|
28
30
|
export interface MakeOptions<Error = never, Context = never> {
|
|
29
31
|
readonly renderer?: Renderer
|
|
30
32
|
readonly driver?: Driver<Error, Context>
|
|
31
33
|
readonly driverMode?: CoreExecutor.DriverMode
|
|
32
|
-
readonly valueMappings?:
|
|
34
|
+
readonly valueMappings?: ValueMappings
|
|
33
35
|
}
|
|
34
36
|
/** Standard composed error shape for SQLite executors. */
|
|
35
37
|
export type SqliteExecutorError = SqliteDriverError | RowDecodeError
|
|
@@ -186,14 +188,14 @@ export function make(): QueryExecutor<SqlClient.SqlClient>
|
|
|
186
188
|
export function make(options: {
|
|
187
189
|
readonly renderer?: Renderer
|
|
188
190
|
readonly driverMode?: CoreExecutor.DriverMode
|
|
189
|
-
readonly valueMappings?:
|
|
191
|
+
readonly valueMappings?: ValueMappings
|
|
190
192
|
}): QueryExecutor<SqlClient.SqlClient>
|
|
191
193
|
export function make<Error = never, Context = never>(
|
|
192
194
|
options: {
|
|
193
195
|
readonly renderer?: Renderer
|
|
194
196
|
readonly driver: Driver<Error, Context>
|
|
195
197
|
readonly driverMode?: CoreExecutor.DriverMode
|
|
196
|
-
readonly valueMappings?:
|
|
198
|
+
readonly valueMappings?: ValueMappings
|
|
197
199
|
}
|
|
198
200
|
): QueryExecutor<Context>
|
|
199
201
|
export function make<Error = never, Context = never>(
|
|
@@ -201,14 +203,14 @@ export function make<Error = never, Context = never>(
|
|
|
201
203
|
): QueryExecutor<any> {
|
|
202
204
|
if (options.driver) {
|
|
203
205
|
return fromDriver(
|
|
204
|
-
options.renderer ?? CoreRenderer.
|
|
206
|
+
options.renderer ?? CoreRenderer.makeTrusted("sqlite", (plan) => renderSqlitePlan(plan, { valueMappings: options.valueMappings })),
|
|
205
207
|
options.driver,
|
|
206
208
|
options.driverMode,
|
|
207
209
|
options.valueMappings
|
|
208
210
|
)
|
|
209
211
|
}
|
|
210
212
|
return fromDriver(
|
|
211
|
-
options.renderer ?? CoreRenderer.
|
|
213
|
+
options.renderer ?? CoreRenderer.makeTrusted("sqlite", (plan) => renderSqlitePlan(plan, { valueMappings: options.valueMappings })),
|
|
212
214
|
sqlClientDriver(),
|
|
213
215
|
options.driverMode,
|
|
214
216
|
options.valueMappings
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { quoteDoubleQuotedIdentifier, type RenderState, type RenderValueContext, type SqlDialect } from "../../internal/dialect.js"
|
|
2
|
+
import { renderExpression, renderQueryAst } from "../../internal/dialect-renderers/sqlite.js"
|
|
2
3
|
import { toDriverValue } from "../../internal/runtime/driver-value-mapping.js"
|
|
4
|
+
import { standardDialect } from "../../standard/dialect.js"
|
|
3
5
|
|
|
4
|
-
const quoteIdentifier =
|
|
6
|
+
const quoteIdentifier = quoteDoubleQuotedIdentifier
|
|
5
7
|
|
|
6
8
|
const renderLiteral = (value: unknown, state: RenderState, context: RenderValueContext = {}): string => {
|
|
7
9
|
const driverValue = toDriverValue(value, {
|
|
@@ -20,11 +22,12 @@ const renderLiteral = (value: unknown, state: RenderState, context: RenderValueC
|
|
|
20
22
|
* Built-in runtime dialect implementation for SQLite.
|
|
21
23
|
*/
|
|
22
24
|
export const sqliteDialect: SqlDialect<"sqlite"> = {
|
|
25
|
+
...standardDialect,
|
|
23
26
|
name: "sqlite",
|
|
24
27
|
quoteIdentifier,
|
|
25
28
|
renderLiteral,
|
|
26
29
|
renderTableReference(tableName, baseTableName, schemaName) {
|
|
27
|
-
const renderedBase = schemaName
|
|
30
|
+
const renderedBase = schemaName && schemaName !== "public"
|
|
28
31
|
? `${quoteIdentifier(schemaName)}.${quoteIdentifier(baseTableName)}`
|
|
29
32
|
: quoteIdentifier(baseTableName)
|
|
30
33
|
return tableName === baseTableName
|
|
@@ -33,5 +36,7 @@ export const sqliteDialect: SqlDialect<"sqlite"> = {
|
|
|
33
36
|
},
|
|
34
37
|
renderConcat(values) {
|
|
35
38
|
return `(${values.join(" || ")})`
|
|
36
|
-
}
|
|
39
|
+
},
|
|
40
|
+
renderQueryAst,
|
|
41
|
+
renderExpression
|
|
37
42
|
}
|