effect-qb 0.21.0 → 0.22.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/dist/index.js +663 -261
- package/dist/mysql.js +2840 -492
- package/dist/postgres/metadata.js +113 -14
- package/dist/postgres.js +2596 -285
- package/dist/sqlite.js +2783 -450
- package/dist/standard.js +663 -261
- package/package.json +1 -1
- package/src/internal/analytics.ts +264 -0
- package/src/internal/coercion/errors.d.ts +1 -1
- package/src/internal/coercion/errors.ts +1 -1
- package/src/internal/custom-sql-renderer.ts +20 -0
- package/src/internal/dialect-numeric.ts +332 -0
- package/src/internal/dialect-renderers/mysql.ts +68 -13
- package/src/internal/dialect-renderers/postgres.ts +83 -13
- package/src/internal/dialect-renderers/sqlite.ts +57 -13
- package/src/internal/dynamic.ts +131 -0
- package/src/internal/executor.ts +198 -7
- package/src/internal/expression-ast.ts +62 -1
- package/src/internal/fragment.ts +120 -0
- package/src/internal/function-constraints.ts +105 -0
- package/src/internal/grouping-key.ts +26 -0
- package/src/internal/numeric.ts +204 -0
- package/src/internal/query.ts +13 -1
- package/src/internal/runtime/normalize.ts +5 -2
- package/src/internal/runtime/schema.ts +2 -1
- package/src/internal/standard-dsl.ts +43 -20
- package/src/internal/window-frame.ts +30 -0
- package/src/internal/window-renderer.ts +25 -0
- package/src/mysql/executor.ts +126 -45
- package/src/mysql/function/aggregate.ts +87 -1
- package/src/mysql/function/index.ts +5 -2
- package/src/mysql/function/numeric.ts +185 -0
- package/src/mysql/function/temporal.ts +6 -6
- package/src/mysql/function/window.ts +12 -0
- package/src/mysql/internal/dsl.ts +38 -20
- package/src/mysql.ts +2 -0
- package/src/postgres/executor.ts +111 -45
- package/src/postgres/function/aggregate.ts +124 -1
- package/src/postgres/function/core.ts +2 -1
- package/src/postgres/function/index.ts +19 -1
- package/src/postgres/function/numeric.ts +246 -0
- package/src/postgres/function/window.ts +12 -0
- package/src/postgres/internal/dsl.ts +38 -20
- package/src/sqlite/executor.ts +96 -45
- package/src/sqlite/function/aggregate.ts +90 -1
- package/src/sqlite/function/index.ts +5 -2
- package/src/sqlite/function/numeric.ts +139 -0
- package/src/sqlite/function/window.ts +12 -0
- package/src/sqlite/internal/dsl.ts +38 -20
- package/src/sqlite.ts +2 -0
- package/src/standard/function/core.ts +8 -1
- package/src/standard/function/index.ts +18 -11
- package/src/standard/function/string.ts +1 -1
- package/src/standard/function/window.ts +10 -1
- package/src/standard/query.ts +19 -7
- package/src/standard/type.ts +16 -0
- package/src/standard.ts +4 -0
- package/src/standard/function/temporal.ts +0 -78
|
@@ -1,2 +1,91 @@
|
|
|
1
|
-
|
|
1
|
+
import * as Numeric from "../../internal/dialect-numeric.js"
|
|
2
|
+
import * as Expression from "../../internal/scalar.js"
|
|
3
|
+
import { sqliteDatatypes } from "../datatypes/index.js"
|
|
4
|
+
|
|
2
5
|
export { count, max, min } from "../internal/dsl.js"
|
|
6
|
+
|
|
7
|
+
type SqInteger = ReturnType<typeof sqliteDatatypes.integer>
|
|
8
|
+
type SqBigInt = ReturnType<typeof sqliteDatatypes.bigint>
|
|
9
|
+
type SqDouble = ReturnType<typeof sqliteDatatypes.double>
|
|
10
|
+
|
|
11
|
+
type IsAny<Value> = 0 extends (1 & Value) ? true : false
|
|
12
|
+
|
|
13
|
+
type BaseDb<Db extends Expression.DbType.Any> =
|
|
14
|
+
Db extends Expression.DbType.Domain<any, infer Base extends Expression.DbType.Any, any>
|
|
15
|
+
? BaseDb<Base>
|
|
16
|
+
: Db
|
|
17
|
+
|
|
18
|
+
type SqAggregateCategory<Db extends Expression.DbType.Any> =
|
|
19
|
+
BaseDb<Db> extends infer Base extends Expression.DbType.Any
|
|
20
|
+
? Base["dialect"] extends "standard" | "sqlite"
|
|
21
|
+
? Base["kind"] extends "int" | "integer" ? "integer"
|
|
22
|
+
: Base["kind"] extends "bigint" ? "bigint"
|
|
23
|
+
: Base["kind"] extends "numeric" | "decimal" | "real" | "double"
|
|
24
|
+
? "approximate"
|
|
25
|
+
: never
|
|
26
|
+
: never
|
|
27
|
+
: never
|
|
28
|
+
|
|
29
|
+
type AggregateInputError<
|
|
30
|
+
Operation extends "sum" | "avg",
|
|
31
|
+
Db extends Expression.DbType.Any
|
|
32
|
+
> = {
|
|
33
|
+
readonly __effect_qb_error__: "effect-qb: unsupported sqlite aggregate input"
|
|
34
|
+
readonly __effect_qb_operation__: Operation
|
|
35
|
+
readonly __effect_qb_db_type__: Db
|
|
36
|
+
readonly __effect_qb_expected__: "an integer, numeric, decimal, real, or double database type"
|
|
37
|
+
readonly __effect_qb_hint__: "Use Cast.to(...) with a supported Type or Sq.Type witness"
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type SqAggregateConstraint<
|
|
41
|
+
Value extends Numeric.Input,
|
|
42
|
+
Operation extends "sum" | "avg"
|
|
43
|
+
> = IsAny<Value> extends true ? unknown
|
|
44
|
+
: Numeric.DialectConstraint<Value, SqDouble, "sqlite"> & (
|
|
45
|
+
SqAggregateCategory<Numeric.DbTypeOfInput<Value, SqDouble, "sqlite">> extends never
|
|
46
|
+
? AggregateInputError<
|
|
47
|
+
Operation,
|
|
48
|
+
Numeric.DbTypeOfInput<Value, SqDouble, "sqlite">
|
|
49
|
+
>
|
|
50
|
+
: unknown
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
type SqSumResultDb<Value extends Numeric.Input> =
|
|
54
|
+
SqAggregateCategory<Numeric.DbTypeOfInput<Value, SqDouble, "sqlite">> extends "integer"
|
|
55
|
+
? SqInteger
|
|
56
|
+
: SqAggregateCategory<Numeric.DbTypeOfInput<Value, SqDouble, "sqlite">> extends "bigint"
|
|
57
|
+
? SqBigInt
|
|
58
|
+
: SqDouble
|
|
59
|
+
|
|
60
|
+
const baseDb = (db: Expression.DbType.Any): Expression.DbType.Any =>
|
|
61
|
+
"base" in db ? baseDb(db.base) : db
|
|
62
|
+
|
|
63
|
+
const sumResultDb = (value: Numeric.Input): SqInteger | SqBigInt | SqDouble => {
|
|
64
|
+
if (typeof value === "number") return sqliteDatatypes.double()
|
|
65
|
+
const db = baseDb(value[Expression.TypeId].dbType)
|
|
66
|
+
if (db.kind === "int" || db.kind === "integer") {
|
|
67
|
+
return sqliteDatatypes.integer()
|
|
68
|
+
}
|
|
69
|
+
if (db.kind === "bigint") {
|
|
70
|
+
return sqliteDatatypes.bigint()
|
|
71
|
+
}
|
|
72
|
+
return sqliteDatatypes.double()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const sum = <Value extends Numeric.Input>(
|
|
76
|
+
value: Value & SqAggregateConstraint<NoInfer<Value>, "sum">
|
|
77
|
+
): Numeric.AggregateResult<"sum", Value, SqDouble, SqSumResultDb<Value>, "sqlite"> =>
|
|
78
|
+
(Numeric.aggregate as any)("sum", value, {
|
|
79
|
+
dialect: "sqlite",
|
|
80
|
+
literalDb: sqliteDatatypes.double(),
|
|
81
|
+
resultDb: sumResultDb(value)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
export const avg = <Value extends Numeric.Input>(
|
|
85
|
+
value: Value & SqAggregateConstraint<NoInfer<Value>, "avg">
|
|
86
|
+
): Numeric.AggregateResult<"avg", Value, SqDouble, SqDouble, "sqlite"> =>
|
|
87
|
+
(Numeric.aggregate as any)("avg", value, {
|
|
88
|
+
dialect: "sqlite",
|
|
89
|
+
literalDb: sqliteDatatypes.double(),
|
|
90
|
+
resultDb: sqliteDatatypes.double()
|
|
91
|
+
})
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
export * as core from "./core.js"
|
|
2
2
|
export * as string from "./string.js"
|
|
3
3
|
export * as aggregate from "./aggregate.js"
|
|
4
|
+
export * as numeric from "./numeric.js"
|
|
4
5
|
export * as window from "./window.js"
|
|
5
6
|
export * as temporal from "./temporal.js"
|
|
6
7
|
|
|
7
8
|
export { coalesce } from "./core.js"
|
|
8
9
|
export { call } from "./core.js"
|
|
9
10
|
export { lower, upper, concat } from "./string.js"
|
|
10
|
-
export { count, max, min } from "./aggregate.js"
|
|
11
|
-
export {
|
|
11
|
+
export { avg, count, max, min, sum } from "./aggregate.js"
|
|
12
|
+
export { modulo, round } from "./numeric.js"
|
|
13
|
+
export { firstValue, lastValue, over, rowNumber, rank, denseRank } from "./window.js"
|
|
14
|
+
export type { WindowSpec } from "./window.js"
|
|
12
15
|
export {
|
|
13
16
|
currentDate,
|
|
14
17
|
currentTime,
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import * as Numeric from "../../internal/dialect-numeric.js"
|
|
2
|
+
import * as Expression from "../../internal/scalar.js"
|
|
3
|
+
import { sqliteDatatypes } from "../datatypes/index.js"
|
|
4
|
+
|
|
5
|
+
type SqInteger = ReturnType<typeof sqliteDatatypes.integer>
|
|
6
|
+
type SqBigInt = ReturnType<typeof sqliteDatatypes.bigint>
|
|
7
|
+
type SqDouble = ReturnType<typeof sqliteDatatypes.double>
|
|
8
|
+
|
|
9
|
+
type IsAny<Value> = 0 extends (1 & Value) ? true : false
|
|
10
|
+
|
|
11
|
+
type BaseDb<Db extends Expression.DbType.Any> =
|
|
12
|
+
Db extends Expression.DbType.Domain<any, infer Base extends Expression.DbType.Any, any>
|
|
13
|
+
? BaseDb<Base>
|
|
14
|
+
: Db
|
|
15
|
+
|
|
16
|
+
type SqNumericCategory<Db extends Expression.DbType.Any> =
|
|
17
|
+
BaseDb<Db> extends infer Base extends Expression.DbType.Any
|
|
18
|
+
? Base["dialect"] extends "standard" | "sqlite"
|
|
19
|
+
? Base["kind"] extends "int" | "integer" ? "integer"
|
|
20
|
+
: Base["kind"] extends "bigint" ? "bigint"
|
|
21
|
+
: Base["kind"] extends "numeric" | "decimal" ? "exact"
|
|
22
|
+
: Base["kind"] extends "real" | "double" ? "approximate"
|
|
23
|
+
: never
|
|
24
|
+
: never
|
|
25
|
+
: never
|
|
26
|
+
|
|
27
|
+
type NumericInputError<
|
|
28
|
+
Operation extends "modulo" | "round",
|
|
29
|
+
Db extends Expression.DbType.Any
|
|
30
|
+
> = {
|
|
31
|
+
readonly __effect_qb_error__: "effect-qb: unsupported sqlite numeric input"
|
|
32
|
+
readonly __effect_qb_operation__: Operation
|
|
33
|
+
readonly __effect_qb_db_type__: Db
|
|
34
|
+
readonly __effect_qb_expected__: "an integer, numeric, decimal, real, or double database type"
|
|
35
|
+
readonly __effect_qb_hint__: "Use Cast.to(...) with a supported Type or Sq.Type witness"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type SqNumericConstraint<
|
|
39
|
+
Value extends Numeric.Input,
|
|
40
|
+
Operation extends "modulo" | "round"
|
|
41
|
+
> =
|
|
42
|
+
IsAny<Value> extends true ? unknown
|
|
43
|
+
: Numeric.DialectConstraint<Value, SqDouble, "sqlite"> & (
|
|
44
|
+
SqNumericCategory<Numeric.DbTypeOfInput<Value, SqDouble, "sqlite">> extends never
|
|
45
|
+
? NumericInputError<Operation, Numeric.DbTypeOfInput<Value, SqDouble, "sqlite">>
|
|
46
|
+
: unknown
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
type SqModuloResultDb<
|
|
50
|
+
Left extends Numeric.Input,
|
|
51
|
+
Right extends Numeric.Input
|
|
52
|
+
> =
|
|
53
|
+
SqNumericCategory<Numeric.DbTypeOfInput<Left, SqDouble, "sqlite">> extends infer LeftCategory
|
|
54
|
+
? SqNumericCategory<Numeric.DbTypeOfInput<Right, SqDouble, "sqlite">> extends infer RightCategory
|
|
55
|
+
? Exclude<LeftCategory | RightCategory, "integer" | "bigint"> extends never
|
|
56
|
+
? "bigint" extends LeftCategory | RightCategory ? SqBigInt : SqInteger
|
|
57
|
+
: SqDouble
|
|
58
|
+
: never
|
|
59
|
+
: never
|
|
60
|
+
|
|
61
|
+
type SqModuloResult<
|
|
62
|
+
Left extends Numeric.Input,
|
|
63
|
+
Right extends Numeric.Input
|
|
64
|
+
> = Numeric.BinaryResult<
|
|
65
|
+
Left,
|
|
66
|
+
Right,
|
|
67
|
+
SqDouble,
|
|
68
|
+
SqModuloResultDb<Left, Right>,
|
|
69
|
+
Numeric.ZeroDivisorNullability<Left, Right, SqDouble, "sqlite">,
|
|
70
|
+
"sqlite"
|
|
71
|
+
>
|
|
72
|
+
|
|
73
|
+
type SqRoundResult<
|
|
74
|
+
Value extends Numeric.Input,
|
|
75
|
+
WithScale extends boolean
|
|
76
|
+
> = Numeric.RoundResult<
|
|
77
|
+
Value,
|
|
78
|
+
SqDouble,
|
|
79
|
+
SqDouble,
|
|
80
|
+
Value extends Expression.Any ? Expression.NullabilityOf<Value> : "never",
|
|
81
|
+
"sqlite",
|
|
82
|
+
WithScale
|
|
83
|
+
>
|
|
84
|
+
|
|
85
|
+
const baseDb = (db: Expression.DbType.Any): Expression.DbType.Any =>
|
|
86
|
+
"base" in db ? baseDb(db.base) : db
|
|
87
|
+
|
|
88
|
+
const category = (value: Numeric.Input): "integer" | "bigint" | "exact" | "approximate" => {
|
|
89
|
+
if (typeof value === "number") return "approximate"
|
|
90
|
+
const db = baseDb(value[Expression.TypeId].dbType)
|
|
91
|
+
if (db.kind === "int" || db.kind === "integer") return "integer"
|
|
92
|
+
if (db.kind === "bigint") return "bigint"
|
|
93
|
+
if (db.kind === "numeric" || db.kind === "decimal") return "exact"
|
|
94
|
+
return "approximate"
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const moduloResultDb = (left: Numeric.Input, right: Numeric.Input) => {
|
|
98
|
+
const categories = [category(left), category(right)]
|
|
99
|
+
if (categories.every((value) => value === "integer" || value === "bigint")) {
|
|
100
|
+
return categories.includes("bigint")
|
|
101
|
+
? sqliteDatatypes.bigint()
|
|
102
|
+
: sqliteDatatypes.integer()
|
|
103
|
+
}
|
|
104
|
+
return sqliteDatatypes.double()
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export const modulo = <
|
|
108
|
+
Left extends Numeric.Input,
|
|
109
|
+
Right extends Numeric.Input
|
|
110
|
+
>(
|
|
111
|
+
left: Left & SqNumericConstraint<NoInfer<Left>, "modulo">,
|
|
112
|
+
right: Right & SqNumericConstraint<NoInfer<Right>, "modulo">
|
|
113
|
+
): SqModuloResult<Left, Right> =>
|
|
114
|
+
(Numeric.modulo as any)(left, right, {
|
|
115
|
+
dialect: "sqlite",
|
|
116
|
+
literalDb: sqliteDatatypes.double(),
|
|
117
|
+
resultDb: moduloResultDb(left, right) as SqModuloResultDb<Left, Right>,
|
|
118
|
+
nullability: Numeric.nullableForZeroDivisor(left, right) as Numeric.ZeroDivisorNullability<Left, Right, SqDouble, "sqlite">
|
|
119
|
+
}) as SqModuloResult<Left, Right>
|
|
120
|
+
|
|
121
|
+
export function round<Value extends Numeric.Input>(
|
|
122
|
+
value: Value & SqNumericConstraint<NoInfer<Value>, "round">
|
|
123
|
+
): SqRoundResult<Value, false>
|
|
124
|
+
export function round<Value extends Numeric.Input>(
|
|
125
|
+
value: Value & SqNumericConstraint<NoInfer<Value>, "round">,
|
|
126
|
+
scale: number
|
|
127
|
+
): SqRoundResult<Value, true>
|
|
128
|
+
export function round(
|
|
129
|
+
value: Numeric.Input,
|
|
130
|
+
scale?: number
|
|
131
|
+
): SqRoundResult<Numeric.Input, boolean> {
|
|
132
|
+
return Numeric.round(value, scale, {
|
|
133
|
+
dialect: "sqlite",
|
|
134
|
+
literalDb: sqliteDatatypes.double(),
|
|
135
|
+
scaleDb: sqliteDatatypes.integer(),
|
|
136
|
+
resultDb: sqliteDatatypes.double(),
|
|
137
|
+
nullability: typeof value === "number" ? "never" : value[Expression.TypeId].nullability
|
|
138
|
+
}) as SqRoundResult<Numeric.Input, boolean>
|
|
139
|
+
}
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
makeDialectFirstValue,
|
|
3
|
+
makeDialectLastValue
|
|
4
|
+
} from "../../internal/analytics.js"
|
|
5
|
+
export type { WindowSpec } from "../../internal/analytics.js"
|
|
6
|
+
|
|
1
7
|
/** SQLite window functions. */
|
|
2
8
|
export { over, rowNumber, rank, denseRank } from "../internal/dsl.js"
|
|
9
|
+
|
|
10
|
+
/** First value in a SQLite window frame. */
|
|
11
|
+
export const firstValue = makeDialectFirstValue("sqlite")
|
|
12
|
+
|
|
13
|
+
/** Last value in a SQLite window frame. */
|
|
14
|
+
export const lastValue = makeDialectLastValue("sqlite")
|
|
@@ -4,6 +4,7 @@ import * as Schema from "effect/Schema"
|
|
|
4
4
|
import { sqliteDatatypes } from "../datatypes/index.js"
|
|
5
5
|
|
|
6
6
|
import * as Expression from "../../internal/scalar.js"
|
|
7
|
+
import type * as FunctionConstraint from "../../internal/function-constraints.js"
|
|
7
8
|
import * as Plan from "../../internal/row-set.js"
|
|
8
9
|
import * as Table from "../../internal/table.js"
|
|
9
10
|
import type {
|
|
@@ -133,6 +134,7 @@ import type { FormulaOfPredicate } from "../../internal/predicate/normalize.js"
|
|
|
133
134
|
import type { TrueFormula } from "../../internal/predicate/formula.js"
|
|
134
135
|
import { assumeFormulaTrue, formulaOfExpression as formulaOfExpressionRuntime, trueFormula } from "../../internal/predicate/runtime.js"
|
|
135
136
|
import { dedupeGroupedExpressions } from "../../internal/grouping-key.js"
|
|
137
|
+
import { validateWindowFrame } from "../../internal/window-frame.js"
|
|
136
138
|
import { makeDslMutationRuntime } from "../../internal/dsl-mutation-runtime.js"
|
|
137
139
|
import { makeDslPlanRuntime } from "../../internal/dsl-plan-runtime.js"
|
|
138
140
|
import { makeDslQueryRuntime } from "../../internal/dsl-query-runtime.js"
|
|
@@ -1457,6 +1459,7 @@ type WindowSpecInput<
|
|
|
1457
1459
|
> = {
|
|
1458
1460
|
readonly partitionBy?: PartitionBy
|
|
1459
1461
|
readonly orderBy?: OrderBy
|
|
1462
|
+
readonly frame?: ExpressionAst.WindowFrameNode
|
|
1460
1463
|
}
|
|
1461
1464
|
|
|
1462
1465
|
type OrderedWindowSpecInput<
|
|
@@ -1465,6 +1468,7 @@ type OrderedWindowSpecInput<
|
|
|
1465
1468
|
> = {
|
|
1466
1469
|
readonly partitionBy?: PartitionBy
|
|
1467
1470
|
readonly orderBy: OrderBy
|
|
1471
|
+
readonly frame?: never
|
|
1468
1472
|
}
|
|
1469
1473
|
|
|
1470
1474
|
type WindowOrderExpressionTuple<
|
|
@@ -1537,8 +1541,8 @@ type NumberWindowExpression<
|
|
|
1537
1541
|
PartitionBy extends readonly WindowPartitionInput[],
|
|
1538
1542
|
OrderBy extends NonEmptyWindowOrderTerms
|
|
1539
1543
|
> = AstBackedExpression<
|
|
1540
|
-
|
|
1541
|
-
|
|
1544
|
+
RuntimeOfDbType<ReturnType<typeof sqliteDatatypes.bigint>>,
|
|
1545
|
+
ReturnType<typeof sqliteDatatypes.bigint>,
|
|
1542
1546
|
"never",
|
|
1543
1547
|
NumberWindowDialectOf<PartitionBy, OrderBy>,
|
|
1544
1548
|
"window",
|
|
@@ -1829,6 +1833,7 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
|
|
|
1829
1833
|
>(
|
|
1830
1834
|
spec: WindowSpecInput<PartitionBy, OrderBy> | OrderedWindowSpecInput<PartitionBy, Extract<OrderBy, NonEmptyWindowOrderTerms>> | undefined
|
|
1831
1835
|
) => {
|
|
1836
|
+
validateWindowFrame(spec?.frame)
|
|
1832
1837
|
const partitionBy = [...(spec?.partitionBy ?? [])] as unknown as PartitionBy
|
|
1833
1838
|
const orderBy = (spec?.orderBy ?? []).map((term) => {
|
|
1834
1839
|
const direction = term.direction ?? "asc"
|
|
@@ -1843,7 +1848,8 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
|
|
|
1843
1848
|
} & readonly { readonly value: WindowOrderInput; readonly direction: OrderDirection }[]
|
|
1844
1849
|
return {
|
|
1845
1850
|
partitionBy,
|
|
1846
|
-
orderBy
|
|
1851
|
+
orderBy,
|
|
1852
|
+
frame: spec?.frame
|
|
1847
1853
|
}
|
|
1848
1854
|
}
|
|
1849
1855
|
|
|
@@ -2173,12 +2179,17 @@ type BinaryPredicateExpression<
|
|
|
2173
2179
|
}
|
|
2174
2180
|
|
|
2175
2181
|
const upper = <Value extends ExpressionInput>(
|
|
2176
|
-
value: Value
|
|
2182
|
+
value: Value & FunctionConstraint.CaseConversionInput<
|
|
2183
|
+
NoInfer<Value>,
|
|
2184
|
+
DialectDbTypeOfInput<NoInfer<Value>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
2185
|
+
Dialect,
|
|
2186
|
+
"upper"
|
|
2187
|
+
>
|
|
2177
2188
|
): AstBackedExpression<
|
|
2178
2189
|
string,
|
|
2179
2190
|
TextDb,
|
|
2180
2191
|
NullabilityOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
2181
|
-
|
|
2192
|
+
Dialect,
|
|
2182
2193
|
KindOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
2183
2194
|
DependenciesOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
2184
2195
|
ExpressionAst.UnaryNode<"upper", DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
|
|
@@ -2188,7 +2199,7 @@ type BinaryPredicateExpression<
|
|
|
2188
2199
|
runtime: "" as string,
|
|
2189
2200
|
dbType: profile.textDb as TextDb,
|
|
2190
2201
|
nullability: expression[Expression.TypeId].nullability as NullabilityOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
2191
|
-
dialect:
|
|
2202
|
+
dialect: profile.dialect as Dialect,
|
|
2192
2203
|
kind: expression[Expression.TypeId].kind as KindOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
2193
2204
|
|
|
2194
2205
|
dependencies: expression[Expression.TypeId].dependencies
|
|
@@ -2199,12 +2210,17 @@ type BinaryPredicateExpression<
|
|
|
2199
2210
|
}
|
|
2200
2211
|
|
|
2201
2212
|
const lower = <Value extends ExpressionInput>(
|
|
2202
|
-
value: Value
|
|
2213
|
+
value: Value & FunctionConstraint.CaseConversionInput<
|
|
2214
|
+
NoInfer<Value>,
|
|
2215
|
+
DialectDbTypeOfInput<NoInfer<Value>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
2216
|
+
Dialect,
|
|
2217
|
+
"lower"
|
|
2218
|
+
>
|
|
2203
2219
|
): AstBackedExpression<
|
|
2204
2220
|
string,
|
|
2205
2221
|
TextDb,
|
|
2206
2222
|
NullabilityOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
2207
|
-
|
|
2223
|
+
Dialect,
|
|
2208
2224
|
KindOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
2209
2225
|
DependenciesOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
2210
2226
|
ExpressionAst.UnaryNode<"lower", DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>
|
|
@@ -2214,7 +2230,7 @@ type BinaryPredicateExpression<
|
|
|
2214
2230
|
runtime: "" as string,
|
|
2215
2231
|
dbType: profile.textDb as TextDb,
|
|
2216
2232
|
nullability: expression[Expression.TypeId].nullability as NullabilityOfDialectStringInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
2217
|
-
dialect:
|
|
2233
|
+
dialect: profile.dialect as Dialect,
|
|
2218
2234
|
kind: expression[Expression.TypeId].kind as KindOf<DialectAsStringExpression<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
2219
2235
|
|
|
2220
2236
|
dependencies: expression[Expression.TypeId].dependencies
|
|
@@ -3493,8 +3509,8 @@ type BinaryPredicateExpression<
|
|
|
3493
3509
|
const count = <Value extends ExpressionInput>(
|
|
3494
3510
|
value: Value
|
|
3495
3511
|
): AstBackedExpression<
|
|
3496
|
-
|
|
3497
|
-
|
|
3512
|
+
RuntimeOfDbType<ReturnType<typeof sqliteDatatypes.bigint>>,
|
|
3513
|
+
ReturnType<typeof sqliteDatatypes.bigint>,
|
|
3498
3514
|
"never",
|
|
3499
3515
|
DialectOfDialectInput<Value, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
3500
3516
|
"aggregate",
|
|
@@ -3503,8 +3519,8 @@ type BinaryPredicateExpression<
|
|
|
3503
3519
|
> => {
|
|
3504
3520
|
const expression = toDialectExpression(value)
|
|
3505
3521
|
return makeExpression({
|
|
3506
|
-
runtime:
|
|
3507
|
-
dbType:
|
|
3522
|
+
runtime: undefined as unknown as RuntimeOfDbType<ReturnType<typeof sqliteDatatypes.bigint>>,
|
|
3523
|
+
dbType: sqliteDatatypes.bigint(),
|
|
3508
3524
|
nullability: "never",
|
|
3509
3525
|
dialect: expression[Expression.TypeId].dialect,
|
|
3510
3526
|
kind: "aggregate",
|
|
@@ -3716,7 +3732,8 @@ type BinaryPredicateExpression<
|
|
|
3716
3732
|
function: "over",
|
|
3717
3733
|
value,
|
|
3718
3734
|
partitionBy: normalized.partitionBy,
|
|
3719
|
-
orderBy: normalized.orderBy
|
|
3735
|
+
orderBy: normalized.orderBy,
|
|
3736
|
+
frame: normalized.frame
|
|
3720
3737
|
})
|
|
3721
3738
|
}
|
|
3722
3739
|
|
|
@@ -3731,8 +3748,8 @@ type BinaryPredicateExpression<
|
|
|
3731
3748
|
const normalized = normalizeWindowSpec(spec)
|
|
3732
3749
|
const expressions = mergeWindowExpressions(undefined, normalized.partitionBy, normalized.orderBy)
|
|
3733
3750
|
return makeExpression({
|
|
3734
|
-
runtime:
|
|
3735
|
-
dbType:
|
|
3751
|
+
runtime: undefined as unknown as RuntimeOfDbType<ReturnType<typeof sqliteDatatypes.bigint>>,
|
|
3752
|
+
dbType: sqliteDatatypes.bigint(),
|
|
3736
3753
|
nullability: "never",
|
|
3737
3754
|
dialect: (expressions.find((expression) => expression[Expression.TypeId].dialect !== undefined)?.[Expression.TypeId].dialect ?? profile.dialect) as NumberWindowDialectOf<PartitionBy, OrderBy>,
|
|
3738
3755
|
kind: "window",
|
|
@@ -3742,7 +3759,8 @@ type BinaryPredicateExpression<
|
|
|
3742
3759
|
kind: "window",
|
|
3743
3760
|
function: kind,
|
|
3744
3761
|
partitionBy: normalized.partitionBy,
|
|
3745
|
-
orderBy: normalized.orderBy
|
|
3762
|
+
orderBy: normalized.orderBy,
|
|
3763
|
+
frame: normalized.frame
|
|
3746
3764
|
})
|
|
3747
3765
|
}
|
|
3748
3766
|
|
|
@@ -3771,7 +3789,7 @@ type BinaryPredicateExpression<
|
|
|
3771
3789
|
buildNumberWindow("denseRank", spec)
|
|
3772
3790
|
|
|
3773
3791
|
const max = <Value extends Expression.Any>(
|
|
3774
|
-
value: Value
|
|
3792
|
+
value: Value & FunctionConstraint.OrderedInput<NoInfer<Value>, Dialect, "max">
|
|
3775
3793
|
): AstBackedExpression<
|
|
3776
3794
|
Expression.RuntimeOf<Value>,
|
|
3777
3795
|
Expression.DbTypeOf<Value>,
|
|
@@ -3795,7 +3813,7 @@ type BinaryPredicateExpression<
|
|
|
3795
3813
|
})
|
|
3796
3814
|
|
|
3797
3815
|
const min = <Value extends Expression.Any>(
|
|
3798
|
-
value: Value
|
|
3816
|
+
value: Value & FunctionConstraint.OrderedInput<NoInfer<Value>, Dialect, "min">
|
|
3799
3817
|
): AstBackedExpression<
|
|
3800
3818
|
Expression.RuntimeOf<Value>,
|
|
3801
3819
|
Expression.DbTypeOf<Value>,
|
|
@@ -3830,7 +3848,7 @@ type BinaryPredicateExpression<
|
|
|
3830
3848
|
const coalesce = <
|
|
3831
3849
|
Values extends readonly [ExpressionInput, ExpressionInput, ...ExpressionInput[]]
|
|
3832
3850
|
>(
|
|
3833
|
-
...values: Values
|
|
3851
|
+
...values: Values & FunctionConstraint.CoalesceConstraint<DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>, Dialect>
|
|
3834
3852
|
): AstBackedExpression<
|
|
3835
3853
|
CoalesceRuntimeTuple<DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>>,
|
|
3836
3854
|
Expression.DbTypeOf<DialectExpressionTuple<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>[number]>,
|
package/src/sqlite.ts
CHANGED
|
@@ -4,6 +4,8 @@ export * as Column from "./sqlite/column-extension.js"
|
|
|
4
4
|
export * as Datatypes from "./sqlite/datatypes/index.js"
|
|
5
5
|
/** SQLite error catalog and error normalization helpers. */
|
|
6
6
|
export * as Errors from "./sqlite/errors/index.js"
|
|
7
|
+
/** SQLite-specific SQL function expressions. */
|
|
8
|
+
export * as Function from "./sqlite/function/index.js"
|
|
7
9
|
/** SQLite-specific JSON expression helpers. Portable JSON helpers are exported from the root package. */
|
|
8
10
|
export * as Json from "./sqlite/json.js"
|
|
9
11
|
/** SQLite-specialized typed query execution contracts. */
|
|
@@ -2,17 +2,24 @@ export * as core from "./core.js"
|
|
|
2
2
|
export * as string from "./string.js"
|
|
3
3
|
export * as aggregate from "./aggregate.js"
|
|
4
4
|
export * as window from "./window.js"
|
|
5
|
-
export * as temporal from "./temporal.js"
|
|
6
5
|
|
|
7
|
-
export {
|
|
8
|
-
|
|
6
|
+
export {
|
|
7
|
+
abs,
|
|
8
|
+
add,
|
|
9
|
+
coalesce,
|
|
10
|
+
multiply,
|
|
11
|
+
negate,
|
|
12
|
+
subtract,
|
|
13
|
+
} from "./core.js"
|
|
14
|
+
export { concat } from "./string.js"
|
|
9
15
|
export { count, max, min } from "./aggregate.js"
|
|
10
|
-
export { over, rowNumber, rank, denseRank } from "./window.js"
|
|
11
16
|
export {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
denseRank,
|
|
18
|
+
firstValue,
|
|
19
|
+
lag,
|
|
20
|
+
lastValue,
|
|
21
|
+
lead,
|
|
22
|
+
over,
|
|
23
|
+
rank,
|
|
24
|
+
rowNumber
|
|
25
|
+
} from "./window.js"
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Standard string functions. */
|
|
2
|
-
export {
|
|
2
|
+
export { concat } from "../query.js"
|
package/src/standard/query.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type as standardType
|
|
3
|
-
} from "../internal/standard-dsl.js"
|
|
4
1
|
import type * as Expression from "../internal/scalar.js"
|
|
5
2
|
|
|
6
3
|
export {
|
|
@@ -88,11 +85,8 @@ export {
|
|
|
88
85
|
lock,
|
|
89
86
|
orderBy,
|
|
90
87
|
groupBy,
|
|
91
|
-
lower,
|
|
92
|
-
upper,
|
|
93
88
|
concat,
|
|
94
89
|
coalesce,
|
|
95
|
-
call,
|
|
96
90
|
count,
|
|
97
91
|
max,
|
|
98
92
|
min,
|
|
@@ -102,7 +96,25 @@ export {
|
|
|
102
96
|
denseRank
|
|
103
97
|
} from "../internal/standard-dsl.js"
|
|
104
98
|
|
|
105
|
-
export {
|
|
99
|
+
export {
|
|
100
|
+
abs,
|
|
101
|
+
add,
|
|
102
|
+
multiply,
|
|
103
|
+
negate,
|
|
104
|
+
subtract
|
|
105
|
+
} from "../internal/numeric.js"
|
|
106
|
+
|
|
107
|
+
export { andAll, includeIf, orAll, when } from "../internal/dynamic.js"
|
|
108
|
+
export {
|
|
109
|
+
firstValue,
|
|
110
|
+
lag,
|
|
111
|
+
lastValue,
|
|
112
|
+
lead,
|
|
113
|
+
type OffsetOptions,
|
|
114
|
+
type WindowOrderSpec,
|
|
115
|
+
type WindowOrderTerm
|
|
116
|
+
} from "../internal/analytics.js"
|
|
117
|
+
|
|
106
118
|
export { union_query_capabilities } from "../internal/query.js"
|
|
107
119
|
|
|
108
120
|
export type MutationInputOf<Shape> = {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type * as Expression from "../internal/scalar.js"
|
|
2
|
+
import { standardDatatypes } from "./datatypes/index.js"
|
|
3
|
+
|
|
4
|
+
const driverValueMapping = <Db extends Expression.DbType.Any>(
|
|
5
|
+
dbType: Db,
|
|
6
|
+
mapping: Expression.DriverValueMapping
|
|
7
|
+
): Db => ({
|
|
8
|
+
...dbType,
|
|
9
|
+
driverValueMapping: mapping
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
/** Portable database-type constructors for casts and typed references. */
|
|
13
|
+
export const type = {
|
|
14
|
+
...standardDatatypes,
|
|
15
|
+
driverValueMapping
|
|
16
|
+
}
|
package/src/standard.ts
CHANGED
|
@@ -4,8 +4,12 @@ export * as Column from "./standard/column.js"
|
|
|
4
4
|
export * as Cast from "./standard/cast.js"
|
|
5
5
|
/** Standard SQL datatype witnesses and coercion families. */
|
|
6
6
|
export * as Datatypes from "./standard/datatypes/index.js"
|
|
7
|
+
/** Portable database-type constructors for casts and typed references. */
|
|
8
|
+
export { type as Type } from "./standard/type.js"
|
|
7
9
|
/** Shared scalar SQL interfaces and DB-type descriptors. */
|
|
8
10
|
export * as Scalar from "./internal/scalar.js"
|
|
11
|
+
/** Typed custom SQL expressions and safely quoted identifiers. */
|
|
12
|
+
export * as Fragment from "./internal/fragment.js"
|
|
9
13
|
/** Standard SQL function expressions. */
|
|
10
14
|
export * as Function from "./standard/function/index.js"
|
|
11
15
|
/** Standard SQL JSON expression helpers and path segments. */
|