effect-qb 0.14.0 → 0.15.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/mysql.js +61270 -4259
- package/dist/postgres/metadata.js +176 -82
- package/dist/postgres.js +5903 -3316
- package/package.json +14 -1
- package/src/internal/aggregation-validation.ts +3 -3
- package/src/internal/case-analysis.d.ts +18 -0
- package/src/internal/case-analysis.ts +4 -4
- package/src/internal/coercion/analysis.d.ts +7 -0
- package/src/internal/{coercion-analysis.ts → coercion/analysis.ts} +3 -3
- package/src/internal/coercion/errors.d.ts +17 -0
- package/src/internal/{coercion-errors.ts → coercion/errors.ts} +1 -1
- package/src/internal/coercion/kind.d.ts +4 -0
- package/src/internal/{coercion-kind.ts → coercion/kind.ts} +2 -2
- package/src/internal/{coercion-normalize.ts → coercion/normalize.ts} +1 -1
- package/src/internal/coercion/rules.d.ts +6 -0
- package/src/internal/{coercion-rules.ts → coercion/rules.ts} +2 -2
- package/src/internal/column-state.d.ts +190 -0
- package/src/internal/column-state.ts +36 -47
- package/src/internal/column.ts +21 -305
- package/src/internal/datatypes/define.d.ts +17 -0
- package/src/internal/datatypes/define.ts +18 -4
- package/src/internal/datatypes/lookup.d.ts +44 -0
- package/src/internal/datatypes/lookup.ts +61 -152
- package/src/internal/datatypes/shape.d.ts +16 -0
- package/src/internal/datatypes/shape.ts +1 -1
- package/src/internal/derived-table.d.ts +4 -0
- package/src/internal/derived-table.ts +21 -16
- package/src/internal/dsl-mutation-runtime.ts +378 -0
- package/src/internal/dsl-plan-runtime.ts +387 -0
- package/src/internal/dsl-query-runtime.ts +160 -0
- package/src/internal/dsl-transaction-ddl-runtime.ts +263 -0
- package/src/internal/executor.ts +132 -31
- package/src/internal/expression-ast.ts +15 -5
- package/src/internal/grouping-key.d.ts +3 -0
- package/src/internal/grouping-key.ts +1 -1
- package/src/internal/implication-runtime.d.ts +15 -0
- package/src/internal/implication-runtime.ts +4 -4
- package/src/internal/json/ast.d.ts +30 -0
- package/src/internal/json/ast.ts +1 -1
- package/src/internal/json/errors.d.ts +8 -0
- package/src/internal/json/path.d.ts +75 -0
- package/src/internal/json/path.ts +1 -1
- package/src/internal/json/types.d.ts +62 -0
- package/src/internal/predicate/analysis.d.ts +20 -0
- package/src/internal/{predicate-analysis.ts → predicate/analysis.ts} +3 -3
- package/src/internal/predicate/atom.d.ts +28 -0
- package/src/internal/{predicate-branches.ts → predicate/branches.ts} +2 -2
- package/src/internal/predicate/context.d.ts +67 -0
- package/src/internal/{predicate-context.ts → predicate/context.ts} +8 -5
- package/src/internal/predicate/formula.d.ts +35 -0
- package/src/internal/{predicate-formula.ts → predicate/formula.ts} +1 -1
- package/src/internal/predicate/key.d.ts +11 -0
- package/src/internal/{predicate-key.ts → predicate/key.ts} +2 -2
- package/src/internal/{predicate-nnf.ts → predicate/nnf.ts} +2 -2
- package/src/internal/predicate/normalize.d.ts +53 -0
- package/src/internal/{predicate-normalize.ts → predicate/normalize.ts} +19 -19
- package/src/internal/predicate/runtime.d.ts +31 -0
- package/src/internal/{predicate-runtime.ts → predicate/runtime.ts} +9 -6
- package/src/internal/projection-alias.d.ts +13 -0
- package/src/internal/projections.d.ts +31 -0
- package/src/internal/projections.ts +1 -1
- package/src/internal/query-ast.d.ts +217 -0
- package/src/internal/query-ast.ts +1 -1
- package/src/internal/query-requirements.d.ts +20 -0
- package/src/internal/query.d.ts +775 -0
- package/src/internal/query.ts +389 -313
- package/src/internal/renderer.ts +7 -21
- package/src/internal/row-set.d.ts +53 -0
- package/src/internal/{plan.ts → row-set.ts} +11 -9
- package/src/internal/{runtime-normalize.ts → runtime/normalize.ts} +9 -31
- package/src/internal/{runtime-schema.ts → runtime/schema.ts} +13 -38
- package/src/internal/runtime/value.d.ts +22 -0
- package/src/internal/{runtime-value.ts → runtime/value.ts} +2 -2
- package/src/internal/scalar.d.ts +107 -0
- package/src/internal/scalar.ts +191 -0
- package/src/internal/schema-derivation.d.ts +105 -0
- package/src/internal/schema-expression.d.ts +18 -0
- package/src/internal/schema-expression.ts +38 -7
- package/src/internal/table-options.d.ts +94 -0
- package/src/internal/table-options.ts +8 -2
- package/src/internal/table.d.ts +173 -0
- package/src/internal/table.ts +32 -14
- package/src/mysql/column.ts +94 -18
- package/src/mysql/datatypes/index.ts +47 -7
- package/src/mysql/errors/generated.ts +57336 -0
- package/src/mysql/errors/index.ts +1 -0
- package/src/mysql/errors/normalize.ts +55 -53
- package/src/mysql/errors/types.ts +74 -0
- package/src/mysql/executor.ts +69 -7
- package/src/mysql/function/aggregate.ts +1 -5
- package/src/mysql/function/core.ts +1 -4
- package/src/mysql/function/index.ts +0 -1
- package/src/mysql/function/string.ts +1 -5
- package/src/mysql/function/temporal.ts +12 -15
- package/src/mysql/function/window.ts +1 -6
- package/src/{internal/mysql-dialect.ts → mysql/internal/dialect.ts} +1 -1
- package/src/{internal/mysql-query.ts → mysql/internal/dsl.ts} +1024 -2082
- package/src/{internal/mysql-renderer.ts → mysql/internal/renderer.ts} +6 -6
- package/src/mysql/internal/sql-expression-renderer.ts +1455 -0
- package/src/mysql/json.ts +2 -0
- package/src/mysql/query.ts +111 -91
- package/src/mysql/renderer.ts +1 -1
- package/src/mysql/table.ts +1 -1
- package/src/mysql.ts +6 -4
- package/src/postgres/cast.ts +11 -12
- package/src/postgres/column.ts +178 -46
- package/src/postgres/datatypes/index.d.ts +515 -0
- package/src/postgres/datatypes/index.ts +22 -13
- package/src/postgres/datatypes/spec.d.ts +412 -0
- package/src/postgres/errors/generated.ts +2636 -0
- package/src/postgres/errors/index.ts +1 -0
- package/src/postgres/errors/normalize.ts +47 -62
- package/src/postgres/errors/types.ts +92 -34
- package/src/postgres/executor.ts +37 -5
- package/src/postgres/function/aggregate.ts +1 -5
- package/src/postgres/function/core.ts +12 -6
- package/src/postgres/function/index.ts +0 -1
- package/src/postgres/function/string.ts +1 -5
- package/src/postgres/function/temporal.ts +12 -15
- package/src/postgres/function/window.ts +1 -6
- package/src/{internal/postgres-dialect.ts → postgres/internal/dialect.ts} +1 -1
- package/src/{internal/postgres-query.ts → postgres/internal/dsl.ts} +1085 -2089
- package/src/{internal/postgres-renderer.ts → postgres/internal/renderer.ts} +6 -6
- package/src/postgres/internal/schema-ddl.ts +108 -0
- package/src/{internal/postgres-schema-model.ts → postgres/internal/schema-model.ts} +12 -6
- package/src/{internal → postgres/internal}/sql-expression-renderer.ts +19 -17
- package/src/postgres/{function/json.ts → json.ts} +77 -85
- package/src/postgres/metadata.ts +2 -2
- package/src/postgres/query.ts +113 -89
- package/src/postgres/renderer.ts +3 -13
- package/src/postgres/schema-expression.ts +2 -1
- package/src/postgres/schema-management.ts +1 -1
- package/src/postgres/table.ts +12 -4
- package/src/postgres/type.ts +29 -2
- package/src/postgres.ts +6 -4
- package/src/internal/expression.ts +0 -327
- package/src/internal/schema-ddl.ts +0 -55
- package/src/mysql/function/json.ts +0 -4
- package/src/mysql/private/query.ts +0 -1
- package/src/postgres/private/query.ts +0 -1
- /package/src/internal/{predicate-atom.ts → predicate/atom.ts} +0 -0
package/src/mysql/query.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
+
type AnyTableFunctionSource,
|
|
3
|
+
type AnyUnnestSource,
|
|
4
|
+
type AnyValuesSource,
|
|
2
5
|
type CapabilitiesOfPlan,
|
|
3
6
|
type CompletePlan,
|
|
4
7
|
type DialectCompatiblePlan,
|
|
@@ -35,98 +38,115 @@ import {
|
|
|
35
38
|
type StatementOfPlan,
|
|
36
39
|
type StringExpressionInput
|
|
37
40
|
} from "../internal/query.js"
|
|
38
|
-
import {
|
|
41
|
+
import {
|
|
42
|
+
type PublicNonStructuredFromApi,
|
|
43
|
+
type PublicStructuredFromConstraint,
|
|
44
|
+
type PublicStructuredFromResult,
|
|
45
|
+
type as mysqlType,
|
|
46
|
+
values,
|
|
47
|
+
unnest,
|
|
48
|
+
select,
|
|
49
|
+
insert,
|
|
50
|
+
from as dslFrom
|
|
51
|
+
} from "./internal/dsl.js"
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
literal,
|
|
55
|
+
column,
|
|
56
|
+
cast,
|
|
57
|
+
eq,
|
|
58
|
+
neq,
|
|
59
|
+
lt,
|
|
60
|
+
lte,
|
|
61
|
+
gt,
|
|
62
|
+
gte,
|
|
63
|
+
isNull,
|
|
64
|
+
isNotNull,
|
|
65
|
+
like,
|
|
66
|
+
ilike,
|
|
67
|
+
regexMatch,
|
|
68
|
+
regexIMatch,
|
|
69
|
+
regexNotMatch,
|
|
70
|
+
regexNotIMatch,
|
|
71
|
+
and,
|
|
72
|
+
or,
|
|
73
|
+
not,
|
|
74
|
+
all,
|
|
75
|
+
any,
|
|
76
|
+
case_ as case,
|
|
77
|
+
match,
|
|
78
|
+
in_ as in,
|
|
79
|
+
notIn,
|
|
80
|
+
between,
|
|
81
|
+
contains,
|
|
82
|
+
containedBy,
|
|
83
|
+
overlaps,
|
|
84
|
+
exists,
|
|
85
|
+
isDistinctFrom,
|
|
86
|
+
isNotDistinctFrom,
|
|
87
|
+
excluded,
|
|
88
|
+
as,
|
|
89
|
+
with_ as with,
|
|
90
|
+
withRecursive,
|
|
91
|
+
lateral,
|
|
92
|
+
scalar,
|
|
93
|
+
inSubquery,
|
|
94
|
+
compareAny,
|
|
95
|
+
compareAll,
|
|
96
|
+
generateSeries,
|
|
97
|
+
values,
|
|
98
|
+
unnest,
|
|
99
|
+
select,
|
|
100
|
+
returning,
|
|
101
|
+
onConflict,
|
|
102
|
+
insert,
|
|
103
|
+
update,
|
|
104
|
+
upsert,
|
|
105
|
+
delete_ as delete,
|
|
106
|
+
truncate,
|
|
107
|
+
merge,
|
|
108
|
+
transaction,
|
|
109
|
+
commit,
|
|
110
|
+
rollback,
|
|
111
|
+
savepoint,
|
|
112
|
+
rollbackTo,
|
|
113
|
+
releaseSavepoint,
|
|
114
|
+
createTable,
|
|
115
|
+
dropTable,
|
|
116
|
+
createIndex,
|
|
117
|
+
dropIndex,
|
|
118
|
+
union,
|
|
119
|
+
unionAll,
|
|
120
|
+
intersect,
|
|
121
|
+
intersectAll,
|
|
122
|
+
except,
|
|
123
|
+
exceptAll,
|
|
124
|
+
where,
|
|
125
|
+
having,
|
|
126
|
+
innerJoin,
|
|
127
|
+
leftJoin,
|
|
128
|
+
rightJoin,
|
|
129
|
+
fullJoin,
|
|
130
|
+
crossJoin,
|
|
131
|
+
distinct,
|
|
132
|
+
distinctOn,
|
|
133
|
+
limit,
|
|
134
|
+
offset,
|
|
135
|
+
lock,
|
|
136
|
+
orderBy,
|
|
137
|
+
groupBy
|
|
138
|
+
} from "./internal/dsl.js"
|
|
139
|
+
export { mysqlType as type }
|
|
140
|
+
|
|
141
|
+
type StructuredSource = AnyValuesSource | AnyUnnestSource | AnyTableFunctionSource
|
|
142
|
+
|
|
143
|
+
type StructuredFromApi = <CurrentSource extends StructuredSource>(
|
|
144
|
+
source: CurrentSource
|
|
145
|
+
) => <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
146
|
+
plan: PlanValue & PublicStructuredFromConstraint<PlanValue, CurrentSource, "mysql">
|
|
147
|
+
) => PublicStructuredFromResult<PlanValue, CurrentSource, "mysql">
|
|
39
148
|
|
|
40
|
-
export const
|
|
41
|
-
export const column = mysqlQuery.column
|
|
42
|
-
export const cast = mysqlQuery.cast
|
|
43
|
-
export const type = mysqlQuery.type
|
|
44
|
-
export const eq = mysqlQuery.eq
|
|
45
|
-
export const neq = mysqlQuery.neq
|
|
46
|
-
export const lt = mysqlQuery.lt
|
|
47
|
-
export const lte = mysqlQuery.lte
|
|
48
|
-
export const gt = mysqlQuery.gt
|
|
49
|
-
export const gte = mysqlQuery.gte
|
|
50
|
-
export const isNull = mysqlQuery.isNull
|
|
51
|
-
export const isNotNull = mysqlQuery.isNotNull
|
|
52
|
-
export const like = mysqlQuery.like
|
|
53
|
-
export const ilike = mysqlQuery.ilike
|
|
54
|
-
export const regexMatch = mysqlQuery.regexMatch
|
|
55
|
-
export const regexIMatch = mysqlQuery.regexIMatch
|
|
56
|
-
export const regexNotMatch = mysqlQuery.regexNotMatch
|
|
57
|
-
export const regexNotIMatch = mysqlQuery.regexNotIMatch
|
|
58
|
-
export const and = mysqlQuery.and
|
|
59
|
-
export const or = mysqlQuery.or
|
|
60
|
-
export const not = mysqlQuery.not
|
|
61
|
-
export const all = mysqlQuery.all
|
|
62
|
-
export const any = mysqlQuery.any
|
|
63
|
-
const case_ = mysqlQuery.case
|
|
64
|
-
export const match = mysqlQuery.match
|
|
65
|
-
export const in_ = mysqlQuery.in
|
|
66
|
-
export const notIn = mysqlQuery.notIn
|
|
67
|
-
export const between = mysqlQuery.between
|
|
68
|
-
export const contains = mysqlQuery.contains
|
|
69
|
-
export const containedBy = mysqlQuery.containedBy
|
|
70
|
-
export const overlaps = mysqlQuery.overlaps
|
|
71
|
-
export const exists = mysqlQuery.exists
|
|
72
|
-
export const isDistinctFrom = mysqlQuery.isDistinctFrom
|
|
73
|
-
export const isNotDistinctFrom = mysqlQuery.isNotDistinctFrom
|
|
74
|
-
export const excluded = mysqlQuery.excluded
|
|
75
|
-
export const as = mysqlQuery.as
|
|
76
|
-
export const with_ = mysqlQuery.with
|
|
77
|
-
export const withRecursive = mysqlQuery.withRecursive
|
|
78
|
-
export const lateral = mysqlQuery.lateral
|
|
79
|
-
export const scalar = mysqlQuery.scalar
|
|
80
|
-
export const inSubquery = mysqlQuery.inSubquery
|
|
81
|
-
export const compareAny = mysqlQuery.compareAny
|
|
82
|
-
export const compareAll = mysqlQuery.compareAll
|
|
83
|
-
export const values = mysqlQuery.values
|
|
84
|
-
export const unnest = mysqlQuery.unnest
|
|
85
|
-
export const generateSeries = mysqlQuery.generateSeries
|
|
86
|
-
export const returning = mysqlQuery.returning
|
|
87
|
-
export const onConflict = mysqlQuery.onConflict
|
|
88
|
-
export const insert = mysqlQuery.insert
|
|
89
|
-
export const update = mysqlQuery.update
|
|
90
|
-
export const upsert = mysqlQuery.upsert
|
|
91
|
-
export const delete_ = mysqlQuery.delete
|
|
92
|
-
export const truncate = mysqlQuery.truncate
|
|
93
|
-
export const merge = mysqlQuery.merge
|
|
94
|
-
export const transaction = mysqlQuery.transaction
|
|
95
|
-
export const commit = mysqlQuery.commit
|
|
96
|
-
export const rollback = mysqlQuery.rollback
|
|
97
|
-
export const savepoint = mysqlQuery.savepoint
|
|
98
|
-
export const rollbackTo = mysqlQuery.rollbackTo
|
|
99
|
-
export const releaseSavepoint = mysqlQuery.releaseSavepoint
|
|
100
|
-
export const createTable = mysqlQuery.createTable
|
|
101
|
-
export const dropTable = mysqlQuery.dropTable
|
|
102
|
-
export const createIndex = mysqlQuery.createIndex
|
|
103
|
-
export const dropIndex = mysqlQuery.dropIndex
|
|
104
|
-
export const union = mysqlQuery.union
|
|
105
|
-
export const unionAll = mysqlQuery.unionAll
|
|
106
|
-
export const intersect = mysqlQuery.intersect
|
|
107
|
-
export const intersectAll = mysqlQuery.intersectAll
|
|
108
|
-
export const except = mysqlQuery.except
|
|
109
|
-
export const exceptAll = mysqlQuery.exceptAll
|
|
110
|
-
export const select = mysqlQuery.select
|
|
111
|
-
export const where = mysqlQuery.where
|
|
112
|
-
export const having = mysqlQuery.having
|
|
113
|
-
export const from = mysqlQuery.from
|
|
114
|
-
export const innerJoin = mysqlQuery.innerJoin
|
|
115
|
-
export const leftJoin = mysqlQuery.leftJoin
|
|
116
|
-
export const rightJoin = mysqlQuery.rightJoin
|
|
117
|
-
export const fullJoin = mysqlQuery.fullJoin
|
|
118
|
-
export const crossJoin = mysqlQuery.crossJoin
|
|
119
|
-
export const distinct = mysqlQuery.distinct
|
|
120
|
-
export const distinctOn = mysqlQuery.distinctOn
|
|
121
|
-
export const limit = mysqlQuery.limit
|
|
122
|
-
export const offset = mysqlQuery.offset
|
|
123
|
-
export const lock = mysqlQuery.lock
|
|
124
|
-
export const orderBy = mysqlQuery.orderBy
|
|
125
|
-
export const groupBy = mysqlQuery.groupBy
|
|
126
|
-
export { case_ as case }
|
|
127
|
-
export { in_ as in }
|
|
128
|
-
export { with_ as with }
|
|
129
|
-
export { delete_ as delete }
|
|
149
|
+
export const from: StructuredFromApi & PublicNonStructuredFromApi = dslFrom as StructuredFromApi & PublicNonStructuredFromApi
|
|
130
150
|
|
|
131
151
|
export type {
|
|
132
152
|
CapabilitiesOfPlan,
|
package/src/mysql/renderer.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as CoreRenderer from "../internal/renderer.js"
|
|
2
|
-
import { renderMysqlPlan } from "
|
|
2
|
+
import { renderMysqlPlan } from "./internal/renderer.js"
|
|
3
3
|
|
|
4
4
|
/** MySQL-specialized rendered query shape. */
|
|
5
5
|
export type RenderedQuery<Row> = CoreRenderer.RenderedQuery<Row, "mysql">
|
package/src/mysql/table.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as Schema from "effect/Schema"
|
|
2
2
|
|
|
3
|
-
import type * as Expression from "../internal/
|
|
3
|
+
import type * as Expression from "../internal/scalar.js"
|
|
4
4
|
import { ColumnTypeId, type AnyColumnDefinition } from "../internal/column-state.js"
|
|
5
5
|
import * as BaseTable from "../internal/table.js"
|
|
6
6
|
|
package/src/mysql.ts
CHANGED
|
@@ -4,14 +4,16 @@ export * as Column from "./mysql/column.js"
|
|
|
4
4
|
export * as Datatypes from "./mysql/datatypes/index.js"
|
|
5
5
|
/** MySQL error catalog and error normalization helpers. */
|
|
6
6
|
export * as Errors from "./mysql/errors/index.js"
|
|
7
|
-
/** Shared scalar SQL
|
|
8
|
-
export * as
|
|
7
|
+
/** Shared scalar SQL interfaces and DB-type descriptors. */
|
|
8
|
+
export * as Scalar from "./internal/scalar.js"
|
|
9
9
|
/** MySQL-specialized SQL function expressions. */
|
|
10
10
|
export * as Function from "./mysql/function/index.js"
|
|
11
|
+
/** MySQL-specialized JSON expression helpers. */
|
|
12
|
+
export * as Json from "./mysql/json.js"
|
|
11
13
|
/** MySQL-specialized typed query execution contracts. */
|
|
12
14
|
export * as Executor from "./mysql/executor.js"
|
|
13
|
-
/** Shared logical
|
|
14
|
-
export * as
|
|
15
|
+
/** Shared logical row-set interfaces. */
|
|
16
|
+
export * as RowSet from "./internal/row-set.js"
|
|
15
17
|
/** MySQL-specialized query-construction DSL. */
|
|
16
18
|
export * as Query from "./mysql/query.js"
|
|
17
19
|
/** MySQL-specialized table-definition DSL. */
|
package/src/postgres/cast.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import type * as Expression from "../internal/
|
|
2
|
-
import {
|
|
1
|
+
import type * as Expression from "../internal/scalar.js"
|
|
2
|
+
import type { ExpressionInput } from "../internal/query.js"
|
|
3
|
+
import { cast as postgresCast } from "./internal/dsl.js"
|
|
3
4
|
|
|
4
|
-
type CastInput =
|
|
5
|
-
type CastTarget =
|
|
6
|
-
type CastExpression<Target extends CastTarget> = Expression.
|
|
5
|
+
type CastInput = ExpressionInput
|
|
6
|
+
type CastTarget = Expression.DbType.Any
|
|
7
|
+
type CastExpression<Target extends CastTarget> = Expression.Scalar<
|
|
7
8
|
Expression.RuntimeOfDbType<Target>,
|
|
8
9
|
Target,
|
|
9
10
|
Expression.Nullability,
|
|
10
|
-
|
|
11
|
-
Expression.
|
|
12
|
-
|
|
13
|
-
Expression.SourceDependencies,
|
|
14
|
-
Expression.SourceNullabilityMode
|
|
11
|
+
Target["dialect"],
|
|
12
|
+
Expression.ScalarKind,
|
|
13
|
+
Expression.BindingId
|
|
15
14
|
>
|
|
16
15
|
|
|
17
16
|
const to: {
|
|
@@ -24,8 +23,8 @@ const to: {
|
|
|
24
23
|
): <Value extends CastInput>(value: Value) => CastExpression<Target>
|
|
25
24
|
} = ((...args: [CastInput, CastTarget] | [CastTarget]) =>
|
|
26
25
|
args.length === 1
|
|
27
|
-
? ((value: CastInput) =>
|
|
28
|
-
:
|
|
26
|
+
? ((value: CastInput) => postgresCast(value as never, args[0] as never))
|
|
27
|
+
: postgresCast(args[0] as never, args[1] as never)) as unknown as typeof to
|
|
29
28
|
|
|
30
29
|
/** Postgres cast helpers. */
|
|
31
30
|
export const cast = { to }
|
package/src/postgres/column.ts
CHANGED
|
@@ -1,46 +1,178 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
1
|
+
import * as Schema from "effect/Schema"
|
|
2
|
+
|
|
3
|
+
import * as BaseColumn from "../internal/column.js"
|
|
4
|
+
import { makeColumnDefinition, type ColumnDefinition } from "../internal/column-state.js"
|
|
5
|
+
import type * as Expression from "../internal/scalar.js"
|
|
6
|
+
import {
|
|
7
|
+
BigIntStringSchema,
|
|
8
|
+
DecimalStringSchema,
|
|
9
|
+
InstantStringSchema,
|
|
10
|
+
LocalDateStringSchema,
|
|
11
|
+
LocalDateTimeStringSchema,
|
|
12
|
+
LocalTimeStringSchema,
|
|
13
|
+
OffsetTimeStringSchema,
|
|
14
|
+
type BigIntString,
|
|
15
|
+
type DecimalString,
|
|
16
|
+
type InstantString,
|
|
17
|
+
type LocalDateString,
|
|
18
|
+
type LocalDateTimeString,
|
|
19
|
+
type LocalTimeString,
|
|
20
|
+
type OffsetTimeString
|
|
21
|
+
} from "../internal/runtime/value.js"
|
|
22
|
+
import { postgresDatatypes } from "./datatypes/index.js"
|
|
23
|
+
|
|
24
|
+
const enrichDbType = <Db extends Expression.DbType.Any>(dbType: Db): Db => {
|
|
25
|
+
const candidate = (postgresDatatypes as unknown as Record<string, (() => Expression.DbType.Any) | undefined>)[dbType.kind]
|
|
26
|
+
return typeof candidate === "function"
|
|
27
|
+
? { ...candidate(), ...dbType } as Db
|
|
28
|
+
: dbType
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const primitive = <Type, Db extends Expression.DbType.Any>(
|
|
32
|
+
schema: Schema.Schema<Type, any, any>,
|
|
33
|
+
dbType: Db
|
|
34
|
+
): ColumnDefinition<Type, Type, Type, Db, false, false, false, false, false, undefined> =>
|
|
35
|
+
makeColumnDefinition(schema as Schema.Schema<NonNullable<Type>>, {
|
|
36
|
+
dbType,
|
|
37
|
+
nullable: false,
|
|
38
|
+
hasDefault: false,
|
|
39
|
+
generated: false,
|
|
40
|
+
primaryKey: false,
|
|
41
|
+
unique: false,
|
|
42
|
+
references: undefined
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const renderNumericDdlType = (
|
|
46
|
+
kind: string,
|
|
47
|
+
options?: BaseColumn.NumericOptions
|
|
48
|
+
): string | undefined => {
|
|
49
|
+
if (options === undefined || options.precision === undefined) {
|
|
50
|
+
return undefined
|
|
51
|
+
}
|
|
52
|
+
return options.scale === undefined
|
|
53
|
+
? `${kind}(${options.precision})`
|
|
54
|
+
: `${kind}(${options.precision},${options.scale})`
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const boundedString = (length?: number): Schema.Schema<string> =>
|
|
58
|
+
length === undefined
|
|
59
|
+
? Schema.String
|
|
60
|
+
: Schema.String.pipe(Schema.maxLength(length))
|
|
61
|
+
|
|
62
|
+
export const custom = <SchemaType extends Schema.Schema.Any, Db extends Expression.DbType.Any>(
|
|
63
|
+
schema: SchemaType,
|
|
64
|
+
dbType: Db
|
|
65
|
+
) =>
|
|
66
|
+
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>, any, any>, {
|
|
67
|
+
dbType: enrichDbType(dbType),
|
|
68
|
+
nullable: false,
|
|
69
|
+
hasDefault: false,
|
|
70
|
+
generated: false,
|
|
71
|
+
primaryKey: false,
|
|
72
|
+
unique: false,
|
|
73
|
+
references: undefined,
|
|
74
|
+
ddlType: undefined,
|
|
75
|
+
identity: undefined
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
export const uuid = () => primitive(Schema.UUID, postgresDatatypes.uuid())
|
|
79
|
+
export const text = () => primitive(Schema.String, postgresDatatypes.text())
|
|
80
|
+
export const int = () => primitive(Schema.Int, postgresDatatypes.int4())
|
|
81
|
+
export const int2 = () => primitive(Schema.Int, postgresDatatypes.int2())
|
|
82
|
+
export const int8 = () => primitive(BigIntStringSchema, postgresDatatypes.int8())
|
|
83
|
+
export const number = (options?: BaseColumn.NumericOptions) =>
|
|
84
|
+
makeColumnDefinition(DecimalStringSchema, {
|
|
85
|
+
dbType: postgresDatatypes.numeric(),
|
|
86
|
+
nullable: false,
|
|
87
|
+
hasDefault: false,
|
|
88
|
+
generated: false,
|
|
89
|
+
primaryKey: false,
|
|
90
|
+
unique: false,
|
|
91
|
+
references: undefined,
|
|
92
|
+
ddlType: renderNumericDdlType("numeric", options),
|
|
93
|
+
identity: undefined
|
|
94
|
+
})
|
|
95
|
+
export const float4 = () => primitive(Schema.Number, postgresDatatypes.float4())
|
|
96
|
+
export const float8 = () => primitive(Schema.Number, postgresDatatypes.float8())
|
|
97
|
+
export const boolean = () => primitive(Schema.Boolean, postgresDatatypes.boolean())
|
|
98
|
+
export const date = () => primitive(LocalDateStringSchema, postgresDatatypes.date())
|
|
99
|
+
export const timestamp = () => primitive(LocalDateTimeStringSchema, postgresDatatypes.timestamp())
|
|
100
|
+
export const time = () => primitive(LocalTimeStringSchema, postgresDatatypes.time())
|
|
101
|
+
export const timetz = () => primitive(OffsetTimeStringSchema, postgresDatatypes.timetz())
|
|
102
|
+
export const timestamptz = () => primitive(InstantStringSchema, postgresDatatypes.timestamptz())
|
|
103
|
+
export const interval = () => primitive(Schema.String, postgresDatatypes.interval())
|
|
104
|
+
export const bytea = () => primitive(Schema.Uint8ArrayFromSelf, postgresDatatypes.bytea())
|
|
105
|
+
export const name = () => primitive(Schema.String, postgresDatatypes.name())
|
|
106
|
+
export const oid = () => primitive(Schema.Int, postgresDatatypes.oid())
|
|
107
|
+
export const regclass = () => primitive(Schema.String, postgresDatatypes.regclass())
|
|
108
|
+
export const bit = () => primitive(Schema.String, postgresDatatypes.bit())
|
|
109
|
+
export const varbit = () => primitive(Schema.String, postgresDatatypes.varbit())
|
|
110
|
+
export const xml = () => primitive(Schema.String, postgresDatatypes.xml())
|
|
111
|
+
export const pg_lsn = () => primitive(Schema.String, postgresDatatypes.pg_lsn())
|
|
112
|
+
export const char = (length = 1) =>
|
|
113
|
+
makeColumnDefinition(boundedString(length), {
|
|
114
|
+
dbType: postgresDatatypes.char(),
|
|
115
|
+
nullable: false,
|
|
116
|
+
hasDefault: false,
|
|
117
|
+
generated: false,
|
|
118
|
+
primaryKey: false,
|
|
119
|
+
unique: false,
|
|
120
|
+
references: undefined,
|
|
121
|
+
ddlType: `char(${length})`,
|
|
122
|
+
identity: undefined
|
|
123
|
+
})
|
|
124
|
+
export const varchar = (length?: number) =>
|
|
125
|
+
makeColumnDefinition(boundedString(length), {
|
|
126
|
+
dbType: postgresDatatypes.varchar(),
|
|
127
|
+
nullable: false,
|
|
128
|
+
hasDefault: false,
|
|
129
|
+
generated: false,
|
|
130
|
+
primaryKey: false,
|
|
131
|
+
unique: false,
|
|
132
|
+
references: undefined,
|
|
133
|
+
ddlType: length === undefined ? "varchar" : `varchar(${length})`,
|
|
134
|
+
identity: undefined
|
|
135
|
+
})
|
|
136
|
+
export const json = <SchemaType extends Schema.Schema.Any>(schema: SchemaType) =>
|
|
137
|
+
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>, any, any>, {
|
|
138
|
+
dbType: postgresDatatypes.json(),
|
|
139
|
+
nullable: false,
|
|
140
|
+
hasDefault: false,
|
|
141
|
+
generated: false,
|
|
142
|
+
primaryKey: false,
|
|
143
|
+
unique: false,
|
|
144
|
+
references: undefined,
|
|
145
|
+
ddlType: undefined,
|
|
146
|
+
identity: undefined
|
|
147
|
+
})
|
|
148
|
+
export const jsonb = <SchemaType extends Schema.Schema.Any>(schema: SchemaType) =>
|
|
149
|
+
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>, any, any>, {
|
|
150
|
+
dbType: postgresDatatypes.jsonb(),
|
|
151
|
+
nullable: false,
|
|
152
|
+
hasDefault: false,
|
|
153
|
+
generated: false,
|
|
154
|
+
primaryKey: false,
|
|
155
|
+
unique: false,
|
|
156
|
+
references: undefined,
|
|
157
|
+
ddlType: undefined,
|
|
158
|
+
identity: undefined
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
export const nullable = BaseColumn.nullable
|
|
162
|
+
export const brand = BaseColumn.brand
|
|
163
|
+
export const primaryKey = BaseColumn.primaryKey
|
|
164
|
+
export const unique = BaseColumn.unique
|
|
165
|
+
const default_ = BaseColumn.default_
|
|
166
|
+
export const generated = BaseColumn.generated
|
|
167
|
+
export const ddlType = BaseColumn.ddlType
|
|
168
|
+
export const array = BaseColumn.array
|
|
169
|
+
export const identityAlways = BaseColumn.identityAlways
|
|
170
|
+
export const identityByDefault = BaseColumn.identityByDefault
|
|
171
|
+
export const foreignKey = BaseColumn.foreignKey
|
|
172
|
+
export const index = BaseColumn.index
|
|
173
|
+
export const references = BaseColumn.references
|
|
174
|
+
export const schema = BaseColumn.schema
|
|
175
|
+
export { default_ as default }
|
|
176
|
+
|
|
177
|
+
export type Any = BaseColumn.Any
|
|
178
|
+
export type AnyBound = BaseColumn.AnyBound
|