@avelonjs/postgres 0.1.0 → 0.3.1
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 +89 -55
- package/package.json +3 -2
- package/src/bun-client.ts +32 -0
- package/src/compile.ts +62 -8
- package/src/driver.ts +33 -223
- package/src/errors.ts +9 -2
- package/src/execute.ts +209 -0
- package/src/fixtures-sql.ts +104 -0
- package/src/fixtures.ts +2 -52
- package/src/index.ts +2 -1
- package/src/migrations-core.ts +142 -0
- package/src/migrations.ts +13 -91
- package/src/schema-core.ts +124 -0
- package/src/schema.ts +5 -117
- package/src/sql-client.ts +28 -0
- package/src/sql.ts +15 -0
- package/src/validate.ts +24 -7
package/src/validate.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Invalid,
|
|
3
|
+
type OrderTerm,
|
|
4
|
+
type Predicate,
|
|
5
|
+
type QueryIR,
|
|
6
|
+
type RelationLoad,
|
|
7
|
+
} from '@avelonjs/core'
|
|
2
8
|
|
|
3
9
|
const IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/
|
|
4
10
|
const COMPARE_OPS = new Set(['=', '!=', '<', '<=', '>', '>=', 'like', 'ilike'] as const)
|
|
@@ -63,7 +69,7 @@ function validatePredicate(value: unknown, path: string): asserts value is Predi
|
|
|
63
69
|
return
|
|
64
70
|
case 'compare':
|
|
65
71
|
assertIdentifier(value.column, `${path}.column`)
|
|
66
|
-
if (!COMPARE_OPS.has(value.op as
|
|
72
|
+
if (!COMPARE_OPS.has(value.op as typeof COMPARE_OPS extends Set<infer T> ? T : never)) {
|
|
67
73
|
invalid(`${path}.op is invalid.`, path, 'Unknown comparison operator')
|
|
68
74
|
}
|
|
69
75
|
return
|
|
@@ -128,7 +134,11 @@ function validateRelation(value: unknown, path: string, depth: number, maxDepth:
|
|
|
128
134
|
validateRelation(relation, `${path}.relations[${index}]`, depth + 1, maxDepth)
|
|
129
135
|
const name = (relation as RelationLoad).relation
|
|
130
136
|
if (names.has(name)) {
|
|
131
|
-
invalid(
|
|
137
|
+
invalid(
|
|
138
|
+
`${path}.relations contains duplicate relation '${name}'.`,
|
|
139
|
+
path,
|
|
140
|
+
'Duplicate relation',
|
|
141
|
+
)
|
|
132
142
|
}
|
|
133
143
|
names.add(name)
|
|
134
144
|
}
|
|
@@ -156,7 +166,8 @@ function validateValues(ir: QueryIR): void {
|
|
|
156
166
|
invalid(`${ir.mode} values must not be empty.`, 'values', 'Expected non-empty rows')
|
|
157
167
|
}
|
|
158
168
|
for (const [index, row] of rows.entries()) {
|
|
159
|
-
if (!isRecord(row))
|
|
169
|
+
if (!isRecord(row))
|
|
170
|
+
invalid(`values[${index}] must be an object.`, 'values', 'Expected an object')
|
|
160
171
|
const columns = Object.keys(row)
|
|
161
172
|
if (
|
|
162
173
|
columns.length !== firstColumns.length ||
|
|
@@ -209,7 +220,8 @@ export function validateQueryIR(ir: QueryIR, maxRelationDepth: number): void {
|
|
|
209
220
|
}
|
|
210
221
|
if (ir.order.length > 0) invalid('count does not accept an order.', 'mode', 'Remove order')
|
|
211
222
|
if (ir.limit !== undefined) invalid('count does not accept a limit.', 'mode', 'Remove limit')
|
|
212
|
-
if (ir.offset !== undefined)
|
|
223
|
+
if (ir.offset !== undefined)
|
|
224
|
+
invalid('count does not accept an offset.', 'mode', 'Remove offset')
|
|
213
225
|
if (ir.returning !== undefined) {
|
|
214
226
|
invalid('count does not accept returning.', 'mode', 'Remove returning')
|
|
215
227
|
}
|
|
@@ -219,14 +231,19 @@ export function validateQueryIR(ir: QueryIR, maxRelationDepth: number): void {
|
|
|
219
231
|
|
|
220
232
|
if (ir.returning !== undefined) validateProjection(ir.returning, 'returning')
|
|
221
233
|
if (ir.mode === 'upsert') {
|
|
222
|
-
if (!isRecord(ir.conflict))
|
|
234
|
+
if (!isRecord(ir.conflict))
|
|
235
|
+
invalid('upsert requires conflict.', 'conflict', 'Required for upsert')
|
|
223
236
|
if (!Array.isArray(ir.conflict.columns) || ir.conflict.columns.length === 0) {
|
|
224
237
|
invalid('conflict.columns must be non-empty.', 'conflict', 'Expected one or more columns')
|
|
225
238
|
}
|
|
226
239
|
for (const column of ir.conflict.columns) assertIdentifier(column, 'conflict.columns entry')
|
|
227
240
|
if (ir.conflict.update !== '*') {
|
|
228
241
|
if (!Array.isArray(ir.conflict.update) || ir.conflict.update.length === 0) {
|
|
229
|
-
invalid(
|
|
242
|
+
invalid(
|
|
243
|
+
"conflict.update must be '*' or a non-empty array.",
|
|
244
|
+
'conflict',
|
|
245
|
+
'Invalid update list',
|
|
246
|
+
)
|
|
230
247
|
}
|
|
231
248
|
for (const column of ir.conflict.update) assertIdentifier(column, 'conflict.update entry')
|
|
232
249
|
}
|