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,98 @@
|
|
|
1
|
+
import type { DatatypeFamilySpec, DatatypeKindSpec } from "../../internal/datatypes/shape.js"
|
|
2
|
+
|
|
3
|
+
export const standardDatatypeFamilies = {
|
|
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 standardDatatypeKinds = {
|
|
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 StandardDatatypeFamily = keyof typeof standardDatatypeFamilies
|
|
98
|
+
export type StandardDatatypeKind = keyof typeof standardDatatypeKinds
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { quoteDoubleQuotedIdentifier, type RenderState, type RenderValueContext, type SqlDialect } from "../internal/dialect.js"
|
|
2
|
+
import { renderExpression, renderQueryAst } from "../internal/dialect-renderers/postgres.js"
|
|
3
|
+
import { toDriverValue } from "../internal/runtime/driver-value-mapping.js"
|
|
4
|
+
|
|
5
|
+
const quoteIdentifier = quoteDoubleQuotedIdentifier
|
|
6
|
+
|
|
7
|
+
const renderLiteral = (value: unknown, state: RenderState, context: RenderValueContext = {}): string => {
|
|
8
|
+
const driverValue = toDriverValue(value, {
|
|
9
|
+
dialect: "standard",
|
|
10
|
+
valueMappings: state.valueMappings,
|
|
11
|
+
...context
|
|
12
|
+
})
|
|
13
|
+
if (driverValue === null) {
|
|
14
|
+
return "null"
|
|
15
|
+
}
|
|
16
|
+
if (typeof driverValue === "boolean") {
|
|
17
|
+
return driverValue ? "true" : "false"
|
|
18
|
+
}
|
|
19
|
+
state.params.push(driverValue)
|
|
20
|
+
return "?"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const standardDialect: SqlDialect<"standard"> = {
|
|
24
|
+
name: "standard",
|
|
25
|
+
quoteIdentifier,
|
|
26
|
+
renderLiteral,
|
|
27
|
+
renderTableReference(tableName, baseTableName, schemaName) {
|
|
28
|
+
const renderedBase = schemaName && schemaName !== "public"
|
|
29
|
+
? `${quoteIdentifier(schemaName)}.${quoteIdentifier(baseTableName)}`
|
|
30
|
+
: quoteIdentifier(baseTableName)
|
|
31
|
+
return tableName === baseTableName
|
|
32
|
+
? renderedBase
|
|
33
|
+
: `${renderedBase} as ${quoteIdentifier(tableName)}`
|
|
34
|
+
},
|
|
35
|
+
renderConcat(values) {
|
|
36
|
+
return `(${values.join(" || ")})`
|
|
37
|
+
},
|
|
38
|
+
renderQueryAst,
|
|
39
|
+
renderExpression
|
|
40
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
|
|
7
|
+
export { coalesce, call } from "./core.js"
|
|
8
|
+
export { lower, upper, concat } from "./string.js"
|
|
9
|
+
export { count, max, min } from "./aggregate.js"
|
|
10
|
+
export { over, rowNumber, rank, denseRank } from "./window.js"
|
|
11
|
+
export {
|
|
12
|
+
currentDate,
|
|
13
|
+
currentTime,
|
|
14
|
+
currentTimestamp,
|
|
15
|
+
localTime,
|
|
16
|
+
localTimestamp,
|
|
17
|
+
now
|
|
18
|
+
} from "./temporal.js"
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type * as Schema from "effect/Schema"
|
|
2
|
+
|
|
3
|
+
import type * as Expression from "../../internal/scalar.js"
|
|
4
|
+
import type * as ExpressionAst from "../../internal/expression-ast.js"
|
|
5
|
+
import { makeExpression } from "../../internal/query.js"
|
|
6
|
+
import {
|
|
7
|
+
InstantStringSchema,
|
|
8
|
+
LocalDateStringSchema,
|
|
9
|
+
LocalDateTimeStringSchema,
|
|
10
|
+
LocalTimeStringSchema,
|
|
11
|
+
type InstantString,
|
|
12
|
+
type LocalDateString,
|
|
13
|
+
type LocalDateTimeString,
|
|
14
|
+
type LocalTimeString
|
|
15
|
+
} from "../../internal/runtime/value.js"
|
|
16
|
+
import { standardDatatypes } from "../datatypes/index.js"
|
|
17
|
+
|
|
18
|
+
type TemporalExpression<
|
|
19
|
+
Runtime,
|
|
20
|
+
Db extends Expression.DbType.Any,
|
|
21
|
+
Name extends string
|
|
22
|
+
> = Expression.Scalar<
|
|
23
|
+
Runtime,
|
|
24
|
+
Db,
|
|
25
|
+
"never",
|
|
26
|
+
"standard",
|
|
27
|
+
"scalar",
|
|
28
|
+
never
|
|
29
|
+
> & {
|
|
30
|
+
readonly [ExpressionAst.TypeId]: ExpressionAst.FunctionCallNode<Name, readonly []>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const makeTemporal = <
|
|
34
|
+
Runtime,
|
|
35
|
+
Db extends Expression.DbType.Any,
|
|
36
|
+
Name extends string
|
|
37
|
+
>(
|
|
38
|
+
name: Name,
|
|
39
|
+
dbType: Db,
|
|
40
|
+
runtimeSchema: Schema.Schema<Runtime, any, any>
|
|
41
|
+
): TemporalExpression<Runtime, Db, Name> =>
|
|
42
|
+
makeExpression({
|
|
43
|
+
runtime: undefined as unknown as Runtime,
|
|
44
|
+
dbType,
|
|
45
|
+
runtimeSchema,
|
|
46
|
+
nullability: "never",
|
|
47
|
+
dialect: "standard",
|
|
48
|
+
kind: "scalar",
|
|
49
|
+
dependencies: {}
|
|
50
|
+
}, {
|
|
51
|
+
kind: "function",
|
|
52
|
+
name,
|
|
53
|
+
args: []
|
|
54
|
+
}) as TemporalExpression<Runtime, Db, Name>
|
|
55
|
+
|
|
56
|
+
/** Standard current instant. */
|
|
57
|
+
export const now = (): TemporalExpression<InstantString, ReturnType<typeof standardDatatypes.timestamp>, "now"> =>
|
|
58
|
+
makeTemporal("now", standardDatatypes.timestamp(), InstantStringSchema)
|
|
59
|
+
|
|
60
|
+
/** Standard current date. */
|
|
61
|
+
export const currentDate = (): TemporalExpression<LocalDateString, ReturnType<typeof standardDatatypes.date>, "current_date"> =>
|
|
62
|
+
makeTemporal("current_date", standardDatatypes.date(), LocalDateStringSchema)
|
|
63
|
+
|
|
64
|
+
/** Standard current time. */
|
|
65
|
+
export const currentTime = (): TemporalExpression<LocalTimeString, ReturnType<typeof standardDatatypes.time>, "current_time"> =>
|
|
66
|
+
makeTemporal("current_time", standardDatatypes.time(), LocalTimeStringSchema)
|
|
67
|
+
|
|
68
|
+
/** Standard current timestamp. */
|
|
69
|
+
export const currentTimestamp = (): TemporalExpression<LocalDateTimeString, ReturnType<typeof standardDatatypes.timestamp>, "current_timestamp"> =>
|
|
70
|
+
makeTemporal("current_timestamp", standardDatatypes.timestamp(), LocalDateTimeStringSchema)
|
|
71
|
+
|
|
72
|
+
/** Standard local time. */
|
|
73
|
+
export const localTime = (): TemporalExpression<LocalTimeString, ReturnType<typeof standardDatatypes.time>, "localtime"> =>
|
|
74
|
+
makeTemporal("localtime", standardDatatypes.time(), LocalTimeStringSchema)
|
|
75
|
+
|
|
76
|
+
/** Standard local timestamp. */
|
|
77
|
+
export const localTimestamp = (): TemporalExpression<LocalDateTimeString, ReturnType<typeof standardDatatypes.timestamp>, "localtimestamp"> =>
|
|
78
|
+
makeTemporal("localtimestamp", standardDatatypes.timestamp(), LocalDateTimeStringSchema)
|
|
@@ -0,0 +1,45 @@
|
|
|
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 { type Projection } from "../../internal/projections.js"
|
|
6
|
+
import { renderQueryAst } from "../../internal/sql-expression-renderer.js"
|
|
7
|
+
import { standardDialect } from "../dialect.js"
|
|
8
|
+
|
|
9
|
+
export interface StandardRenderResult {
|
|
10
|
+
readonly sql: string
|
|
11
|
+
readonly params: readonly unknown[]
|
|
12
|
+
readonly projections: readonly Projection[]
|
|
13
|
+
readonly valueMappings?: Expression.DriverValueMappings
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface StandardRenderOptions {
|
|
17
|
+
readonly valueMappings?: Expression.DriverValueMappings
|
|
18
|
+
readonly casing?: Casing.Options
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const renderStandardPlan = <PlanValue extends Query.Plan.Any>(
|
|
22
|
+
plan: Query.DialectCompatiblePlan<PlanValue, "standard">,
|
|
23
|
+
options: StandardRenderOptions = {}
|
|
24
|
+
): StandardRenderResult => {
|
|
25
|
+
const state: RenderState = {
|
|
26
|
+
params: [],
|
|
27
|
+
valueMappings: options.valueMappings,
|
|
28
|
+
casing: options.casing,
|
|
29
|
+
ctes: [],
|
|
30
|
+
cteNames: new Set<string>(),
|
|
31
|
+
cteSources: new Map<string, unknown>(),
|
|
32
|
+
sourceNames: new Map()
|
|
33
|
+
}
|
|
34
|
+
const rendered = renderQueryAst(
|
|
35
|
+
Query.getAst(plan as Query.Plan.Any) as any,
|
|
36
|
+
state,
|
|
37
|
+
standardDialect
|
|
38
|
+
)
|
|
39
|
+
return {
|
|
40
|
+
sql: rendered.sql,
|
|
41
|
+
params: state.params,
|
|
42
|
+
projections: rendered.projections,
|
|
43
|
+
valueMappings: state.valueMappings
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type as standardType
|
|
3
|
+
} from "../internal/standard-dsl.js"
|
|
4
|
+
import type * as Expression from "../internal/scalar.js"
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
literal,
|
|
8
|
+
column,
|
|
9
|
+
cast,
|
|
10
|
+
eq,
|
|
11
|
+
neq,
|
|
12
|
+
lt,
|
|
13
|
+
lte,
|
|
14
|
+
gt,
|
|
15
|
+
gte,
|
|
16
|
+
isNull,
|
|
17
|
+
isNotNull,
|
|
18
|
+
like,
|
|
19
|
+
ilike,
|
|
20
|
+
collate,
|
|
21
|
+
regexMatch,
|
|
22
|
+
regexIMatch,
|
|
23
|
+
regexNotMatch,
|
|
24
|
+
regexNotIMatch,
|
|
25
|
+
and,
|
|
26
|
+
or,
|
|
27
|
+
not,
|
|
28
|
+
all,
|
|
29
|
+
any,
|
|
30
|
+
case_ as case,
|
|
31
|
+
match,
|
|
32
|
+
in_ as in,
|
|
33
|
+
notIn,
|
|
34
|
+
between,
|
|
35
|
+
contains,
|
|
36
|
+
containedBy,
|
|
37
|
+
overlaps,
|
|
38
|
+
exists,
|
|
39
|
+
isDistinctFrom,
|
|
40
|
+
isNotDistinctFrom,
|
|
41
|
+
excluded,
|
|
42
|
+
as,
|
|
43
|
+
with_ as with,
|
|
44
|
+
withRecursive,
|
|
45
|
+
lateral,
|
|
46
|
+
scalar,
|
|
47
|
+
inSubquery,
|
|
48
|
+
compareAny,
|
|
49
|
+
compareAll,
|
|
50
|
+
values,
|
|
51
|
+
unnest,
|
|
52
|
+
select,
|
|
53
|
+
returning,
|
|
54
|
+
onConflict,
|
|
55
|
+
insert,
|
|
56
|
+
update,
|
|
57
|
+
upsert,
|
|
58
|
+
delete_ as delete,
|
|
59
|
+
truncate,
|
|
60
|
+
merge,
|
|
61
|
+
transaction,
|
|
62
|
+
commit,
|
|
63
|
+
rollback,
|
|
64
|
+
savepoint,
|
|
65
|
+
rollbackTo,
|
|
66
|
+
releaseSavepoint,
|
|
67
|
+
createTable,
|
|
68
|
+
dropTable,
|
|
69
|
+
createIndex,
|
|
70
|
+
dropIndex,
|
|
71
|
+
union,
|
|
72
|
+
unionAll,
|
|
73
|
+
intersect,
|
|
74
|
+
intersectAll,
|
|
75
|
+
except,
|
|
76
|
+
exceptAll,
|
|
77
|
+
where,
|
|
78
|
+
having,
|
|
79
|
+
from,
|
|
80
|
+
innerJoin,
|
|
81
|
+
leftJoin,
|
|
82
|
+
rightJoin,
|
|
83
|
+
fullJoin,
|
|
84
|
+
crossJoin,
|
|
85
|
+
distinct,
|
|
86
|
+
limit,
|
|
87
|
+
offset,
|
|
88
|
+
lock,
|
|
89
|
+
orderBy,
|
|
90
|
+
groupBy,
|
|
91
|
+
lower,
|
|
92
|
+
upper,
|
|
93
|
+
concat,
|
|
94
|
+
coalesce,
|
|
95
|
+
call,
|
|
96
|
+
count,
|
|
97
|
+
max,
|
|
98
|
+
min,
|
|
99
|
+
over,
|
|
100
|
+
rowNumber,
|
|
101
|
+
rank,
|
|
102
|
+
denseRank
|
|
103
|
+
} from "../internal/standard-dsl.js"
|
|
104
|
+
|
|
105
|
+
export { standardType as type }
|
|
106
|
+
export { union_query_capabilities } from "../internal/query.js"
|
|
107
|
+
|
|
108
|
+
export type MutationInputOf<Shape> = {
|
|
109
|
+
readonly [K in keyof Shape]:
|
|
110
|
+
| Shape[K]
|
|
111
|
+
| Expression.Scalar<Shape[K], Expression.DbType.Any, Expression.Nullability, "standard", Expression.ScalarKind, Expression.BindingId>
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export type {
|
|
115
|
+
AnyTableFunctionSource,
|
|
116
|
+
AnyUnnestSource,
|
|
117
|
+
AnyValuesSource,
|
|
118
|
+
CapabilitiesOfPlan,
|
|
119
|
+
CompletePlan,
|
|
120
|
+
CteSource,
|
|
121
|
+
DialectCompatiblePlan,
|
|
122
|
+
DerivedSourceRequiredError,
|
|
123
|
+
EffectiveNullability,
|
|
124
|
+
ExpressionInput,
|
|
125
|
+
ExpressionOutput,
|
|
126
|
+
GroupByInput,
|
|
127
|
+
HavingPredicateInput,
|
|
128
|
+
MergeCapabilities,
|
|
129
|
+
MergeCapabilityTuple,
|
|
130
|
+
MutationTargetLike,
|
|
131
|
+
NumericExpressionInput,
|
|
132
|
+
OrderDirection,
|
|
133
|
+
OutputOfSelection,
|
|
134
|
+
PredicateInput,
|
|
135
|
+
QueryCapability,
|
|
136
|
+
QueryPlan,
|
|
137
|
+
QueryRequirement,
|
|
138
|
+
QueryStatement,
|
|
139
|
+
ResultRow,
|
|
140
|
+
ResultRows,
|
|
141
|
+
RuntimeResultRow,
|
|
142
|
+
RuntimeResultRows,
|
|
143
|
+
SchemaTableLike,
|
|
144
|
+
SetCompatiblePlan,
|
|
145
|
+
SetCompatibleRightPlan,
|
|
146
|
+
SetOperator,
|
|
147
|
+
SourceCapabilitiesOf,
|
|
148
|
+
SourceRequiredOf,
|
|
149
|
+
SourceRequirementError,
|
|
150
|
+
StatementOfPlan,
|
|
151
|
+
StringExpressionInput
|
|
152
|
+
} from "../internal/query.js"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as CoreRenderer from "../internal/renderer.js"
|
|
2
|
+
import type * as Casing from "../internal/casing.js"
|
|
3
|
+
import type * as Expression from "../internal/scalar.js"
|
|
4
|
+
import type { StandardDatatypeFamily, StandardDatatypeKind } from "./datatypes/spec.js"
|
|
5
|
+
import { renderStandardPlan } from "./internal/renderer.js"
|
|
6
|
+
|
|
7
|
+
export type RenderedQuery<Row> = CoreRenderer.RenderedQuery<Row, "standard">
|
|
8
|
+
|
|
9
|
+
export type RowOf<Value extends RenderedQuery<any>> = CoreRenderer.RowOf<Value>
|
|
10
|
+
|
|
11
|
+
export type Renderer = CoreRenderer.Renderer<"standard">
|
|
12
|
+
|
|
13
|
+
export type ValueMappings = Expression.DriverValueMappingsFor<StandardDatatypeKind | "uuid", StandardDatatypeFamily | "uuid">
|
|
14
|
+
|
|
15
|
+
export interface MakeOptions {
|
|
16
|
+
readonly valueMappings?: ValueMappings
|
|
17
|
+
readonly casing?: Casing.Options
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const make = (options: MakeOptions = {}): Renderer =>
|
|
21
|
+
CoreRenderer.makeTrusted("standard", (plan) => renderStandardPlan(plan, options))
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { AnyColumnDefinition } from "../internal/column-state.js"
|
|
2
|
+
import * as BaseTable from "../internal/table.js"
|
|
3
|
+
|
|
4
|
+
type Dialect = string
|
|
5
|
+
|
|
6
|
+
type DialectColumn = AnyColumnDefinition
|
|
7
|
+
|
|
8
|
+
type DialectFieldMap = Record<string, DialectColumn>
|
|
9
|
+
|
|
10
|
+
type InlinePrimaryKeyKeys<Fields extends DialectFieldMap> = Extract<{
|
|
11
|
+
[K in keyof Fields]: Fields[K]["metadata"]["primaryKey"] extends true ? K : never
|
|
12
|
+
}[keyof Fields], string>
|
|
13
|
+
|
|
14
|
+
export type TableDefinition<
|
|
15
|
+
Name extends string,
|
|
16
|
+
Fields extends DialectFieldMap,
|
|
17
|
+
PrimaryKeyColumns extends keyof Fields & string = InlinePrimaryKeyKeys<Fields>,
|
|
18
|
+
Kind extends "schema" | "alias" = "schema",
|
|
19
|
+
SchemaName extends string = "public"
|
|
20
|
+
> = BaseTable.TableDefinition<Name, Fields, PrimaryKeyColumns, Kind, SchemaName>
|
|
21
|
+
|
|
22
|
+
export type TableClassStatic<
|
|
23
|
+
Name extends string,
|
|
24
|
+
Fields extends DialectFieldMap,
|
|
25
|
+
PrimaryKeyColumns extends keyof Fields & string = InlinePrimaryKeyKeys<Fields>,
|
|
26
|
+
SchemaName extends string = "public"
|
|
27
|
+
> = BaseTable.TableClassStatic<Name, Fields, PrimaryKeyColumns, SchemaName>
|
|
28
|
+
|
|
29
|
+
export type AnyTable = BaseTable.AnyTable<Dialect>
|
|
30
|
+
|
|
31
|
+
type FieldsOfTable<Table extends BaseTable.AnyTable> = Table[typeof BaseTable.TypeId]["fields"] extends infer Fields extends DialectFieldMap
|
|
32
|
+
? Fields
|
|
33
|
+
: never
|
|
34
|
+
|
|
35
|
+
type PrimaryKeyOfTable<Table extends BaseTable.AnyTable> = Table[typeof BaseTable.TypeId]["primaryKey"][number]
|
|
36
|
+
|
|
37
|
+
type SchemaNameOfTable<Table extends BaseTable.AnyTable> =
|
|
38
|
+
Table[typeof BaseTable.TypeId]["schemaName"] extends infer SchemaName extends string ? SchemaName : "public"
|
|
39
|
+
|
|
40
|
+
export type TableOption = BaseTable.TableOption
|
|
41
|
+
|
|
42
|
+
export const TypeId = BaseTable.TypeId
|
|
43
|
+
export const OptionsSymbol = BaseTable.OptionsSymbol
|
|
44
|
+
export const options = BaseTable.options
|
|
45
|
+
export const option = BaseTable.option
|
|
46
|
+
|
|
47
|
+
export function make<
|
|
48
|
+
Name extends string,
|
|
49
|
+
Fields extends DialectFieldMap
|
|
50
|
+
>(
|
|
51
|
+
name: BaseTable.NonEmptyStringInput<Name>,
|
|
52
|
+
fields: Fields & BaseTable.NonEmptyFieldMap<Fields>
|
|
53
|
+
): TableDefinition<Name, Fields, InlinePrimaryKeyKeys<Fields>, "schema", "public">
|
|
54
|
+
export function make<
|
|
55
|
+
Name extends string,
|
|
56
|
+
Fields extends DialectFieldMap,
|
|
57
|
+
const SchemaName extends string
|
|
58
|
+
>(
|
|
59
|
+
name: BaseTable.NonEmptyStringInput<Name>,
|
|
60
|
+
fields: Fields & BaseTable.NonEmptyFieldMap<Fields>,
|
|
61
|
+
schemaName: BaseTable.NonEmptySchemaNameInput<SchemaName>
|
|
62
|
+
): TableDefinition<Name, Fields, InlinePrimaryKeyKeys<Fields>, "schema", SchemaName>
|
|
63
|
+
export function make(
|
|
64
|
+
name: string,
|
|
65
|
+
fields: DialectFieldMap,
|
|
66
|
+
schemaName?: string
|
|
67
|
+
): TableDefinition<string, DialectFieldMap, string, "schema", string> {
|
|
68
|
+
return arguments.length >= 3
|
|
69
|
+
? BaseTable.make(name, fields, schemaName as string) as TableDefinition<string, DialectFieldMap, string, "schema", string>
|
|
70
|
+
: BaseTable.make(name, fields) as TableDefinition<string, DialectFieldMap, string, "schema", string>
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const alias = <
|
|
74
|
+
Table extends AnyTable,
|
|
75
|
+
AliasName extends string
|
|
76
|
+
>(
|
|
77
|
+
table: Table,
|
|
78
|
+
aliasName: BaseTable.LiteralStringInput<AliasName>
|
|
79
|
+
): TableDefinition<
|
|
80
|
+
AliasName,
|
|
81
|
+
FieldsOfTable<Table>,
|
|
82
|
+
PrimaryKeyOfTable<Table>,
|
|
83
|
+
"alias",
|
|
84
|
+
SchemaNameOfTable<Table>
|
|
85
|
+
> =>
|
|
86
|
+
BaseTable.alias(table as any, aliasName) as TableDefinition<
|
|
87
|
+
AliasName,
|
|
88
|
+
FieldsOfTable<Table>,
|
|
89
|
+
PrimaryKeyOfTable<Table>,
|
|
90
|
+
"alias",
|
|
91
|
+
SchemaNameOfTable<Table>
|
|
92
|
+
>
|
|
93
|
+
|
|
94
|
+
type ClassApi = {
|
|
95
|
+
<Self = never>(
|
|
96
|
+
name: "",
|
|
97
|
+
schemaName?: string | undefined
|
|
98
|
+
): never
|
|
99
|
+
<Self = never>(
|
|
100
|
+
name: string,
|
|
101
|
+
schemaName: ""
|
|
102
|
+
): never
|
|
103
|
+
<Self = never, const SchemaName extends string = "public", const Name extends string = string>(
|
|
104
|
+
name: BaseTable.NonEmptyStringInput<Name>,
|
|
105
|
+
schemaName?: BaseTable.NonEmptySchemaNameInput<SchemaName>
|
|
106
|
+
): <
|
|
107
|
+
Fields extends DialectFieldMap
|
|
108
|
+
>(fields: Fields & BaseTable.NonEmptyFieldMap<Fields>) => [Self] extends [never]
|
|
109
|
+
? BaseTable.MissingSelfGeneric
|
|
110
|
+
: TableClassStatic<Name, Fields, InlinePrimaryKeyKeys<Fields>, SchemaName>
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export const Class: ClassApi = ((
|
|
114
|
+
name: string,
|
|
115
|
+
schemaName: string | undefined = undefined
|
|
116
|
+
) => {
|
|
117
|
+
const base = BaseTable.Class(name as never, schemaName)
|
|
118
|
+
return base
|
|
119
|
+
}) as ClassApi
|
|
120
|
+
|
|
121
|
+
export const primaryKey = BaseTable.primaryKey
|
|
122
|
+
export const unique = BaseTable.unique
|
|
123
|
+
export const index = BaseTable.index
|
|
124
|
+
export const foreignKey = <
|
|
125
|
+
LocalColumns extends string | readonly string[],
|
|
126
|
+
TargetTable extends AnyTable,
|
|
127
|
+
TargetColumns extends string | readonly string[]
|
|
128
|
+
>(
|
|
129
|
+
columns: LocalColumns & BaseTable.NonEmptyColumnInput<LocalColumns>,
|
|
130
|
+
target: () => TargetTable,
|
|
131
|
+
referencedColumns: TargetColumns & BaseTable.NonEmptyColumnInput<TargetColumns> & BaseTable.MatchingColumnArityInput<LocalColumns, TargetColumns>
|
|
132
|
+
) =>
|
|
133
|
+
BaseTable.foreignKey<LocalColumns, TargetTable, TargetColumns>(
|
|
134
|
+
columns as LocalColumns & BaseTable.NonEmptyColumnInput<LocalColumns>,
|
|
135
|
+
target,
|
|
136
|
+
referencedColumns as TargetColumns & BaseTable.NonEmptyColumnInput<TargetColumns> & BaseTable.MatchingColumnArityInput<LocalColumns, TargetColumns>
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
export const check = BaseTable.check
|
|
140
|
+
|
|
141
|
+
export const selectSchema = BaseTable.selectSchema
|
|
142
|
+
export const insertSchema = BaseTable.insertSchema
|
|
143
|
+
export const updateSchema = BaseTable.updateSchema
|
|
144
|
+
|
|
145
|
+
export type SelectOf<Table extends AnyTable> = BaseTable.SelectOf<Table>
|
|
146
|
+
export type InsertOf<Table extends AnyTable> = BaseTable.InsertOf<Table>
|
|
147
|
+
export type UpdateOf<Table extends AnyTable> = BaseTable.UpdateOf<Table>
|
package/src/standard.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Standard SQL column-definition DSL. */
|
|
2
|
+
export * as Column from "./standard/column.js"
|
|
3
|
+
/** Standard SQL datatype witnesses and coercion families. */
|
|
4
|
+
export * as Datatypes from "./standard/datatypes/index.js"
|
|
5
|
+
/** Shared scalar SQL interfaces and DB-type descriptors. */
|
|
6
|
+
export * as Scalar from "./internal/scalar.js"
|
|
7
|
+
/** Standard SQL function expressions. */
|
|
8
|
+
export * as Function from "./standard/function/index.js"
|
|
9
|
+
/** Standard SQL typed query execution contracts. */
|
|
10
|
+
export * as Executor from "./internal/executor.js"
|
|
11
|
+
/** Shared logical row-set interfaces. */
|
|
12
|
+
export * as RowSet from "./internal/row-set.js"
|
|
13
|
+
/** Standard SQL query-construction DSL. */
|
|
14
|
+
export * as Query from "./standard/query.js"
|
|
15
|
+
/** Standard SQL table-definition DSL. */
|
|
16
|
+
export * as Table from "./standard/table.js"
|
|
17
|
+
/** Standard SQL built-in renderer entrypoint. */
|
|
18
|
+
export * as Renderer from "./standard/renderer.js"
|