effect-qb 0.19.0 → 4.0.0-beta.92

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.
Files changed (89) hide show
  1. package/README.md +7 -1
  2. package/dist/index.js +1987 -679
  3. package/dist/mysql.js +1486 -616
  4. package/dist/postgres/metadata.js +1334 -263
  5. package/dist/postgres.js +3374 -2308
  6. package/dist/sqlite.js +1569 -627
  7. package/dist/standard.js +1982 -674
  8. package/package.json +2 -4
  9. package/src/internal/coercion/rules.ts +13 -1
  10. package/src/internal/column-state.d.ts +3 -3
  11. package/src/internal/column-state.ts +13 -12
  12. package/src/internal/column.ts +8 -8
  13. package/src/internal/datatypes/define.ts +5 -0
  14. package/src/internal/datatypes/lookup.ts +67 -18
  15. package/src/internal/datatypes/matrix.ts +903 -0
  16. package/src/internal/datatypes/shape.ts +2 -0
  17. package/src/internal/dialect-renderers/mysql.ts +6 -4
  18. package/src/internal/dialect-renderers/postgres.ts +6 -4
  19. package/src/internal/dialect-renderers/sqlite.ts +6 -4
  20. package/src/internal/dialect.ts +1 -1
  21. package/src/internal/executor.ts +56 -43
  22. package/src/internal/json/path-access.ts +351 -0
  23. package/src/internal/query.d.ts +1 -1
  24. package/src/internal/query.ts +1 -1
  25. package/src/internal/runtime/driver-value-mapping.ts +3 -3
  26. package/src/internal/runtime/schema.ts +28 -38
  27. package/src/internal/runtime/value.ts +20 -23
  28. package/src/internal/scalar.d.ts +1 -1
  29. package/src/internal/scalar.ts +2 -1
  30. package/src/internal/schema-derivation.d.ts +7 -7
  31. package/src/internal/schema-derivation.ts +11 -11
  32. package/src/internal/standard-dsl.ts +118 -28
  33. package/src/internal/table.ts +451 -120
  34. package/src/mysql/column.ts +6 -6
  35. package/src/mysql/datatypes/index.ts +1 -0
  36. package/src/mysql/datatypes/spec.ts +6 -176
  37. package/src/mysql/executor.ts +4 -6
  38. package/src/mysql/function/temporal.ts +1 -1
  39. package/src/mysql/internal/dsl.ts +113 -16
  40. package/src/mysql/json.ts +1 -33
  41. package/src/mysql/renderer.ts +13 -6
  42. package/src/mysql/type.ts +60 -0
  43. package/src/mysql.ts +3 -1
  44. package/src/postgres/check.ts +1 -0
  45. package/src/postgres/column.ts +11 -11
  46. package/src/postgres/datatypes/index.ts +1 -0
  47. package/src/postgres/datatypes/spec.ts +6 -260
  48. package/src/postgres/executor.ts +4 -6
  49. package/src/postgres/foreign-key.ts +24 -0
  50. package/src/postgres/function/temporal.ts +1 -1
  51. package/src/postgres/index.ts +1 -0
  52. package/src/postgres/internal/dsl.ts +119 -21
  53. package/src/postgres/json-extension.ts +7 -0
  54. package/src/postgres/json.ts +726 -173
  55. package/src/postgres/jsonb.ts +0 -1
  56. package/src/postgres/primary-key.ts +24 -0
  57. package/src/postgres/renderer.ts +13 -6
  58. package/src/postgres/schema-management.ts +1 -6
  59. package/src/postgres/schema.ts +16 -8
  60. package/src/postgres/table.ts +111 -113
  61. package/src/postgres/type.ts +86 -4
  62. package/src/postgres/unique.ts +32 -0
  63. package/src/postgres.ts +12 -6
  64. package/src/sqlite/column.ts +6 -6
  65. package/src/sqlite/datatypes/index.ts +1 -0
  66. package/src/sqlite/datatypes/spec.ts +6 -94
  67. package/src/sqlite/executor.ts +4 -6
  68. package/src/sqlite/function/temporal.ts +1 -1
  69. package/src/sqlite/internal/dsl.ts +97 -5
  70. package/src/sqlite/json.ts +1 -32
  71. package/src/sqlite/renderer.ts +13 -6
  72. package/src/sqlite/type.ts +40 -0
  73. package/src/sqlite.ts +3 -1
  74. package/src/standard/cast.ts +113 -0
  75. package/src/standard/check.ts +17 -0
  76. package/src/standard/column.ts +10 -10
  77. package/src/standard/datatypes/index.ts +2 -2
  78. package/src/standard/datatypes/spec.ts +10 -96
  79. package/src/standard/foreign-key.ts +37 -0
  80. package/src/standard/function/temporal.ts +1 -1
  81. package/src/standard/index.ts +17 -0
  82. package/src/standard/json.ts +883 -0
  83. package/src/standard/primary-key.ts +17 -0
  84. package/src/standard/renderer.ts +31 -3
  85. package/src/standard/table.ts +25 -21
  86. package/src/standard/unique.ts +17 -0
  87. package/src/standard.ts +14 -0
  88. package/src/internal/table.d.ts +0 -174
  89. package/src/postgres/cast.ts +0 -45
@@ -0,0 +1,903 @@
1
+ import type { DatatypeFamilySpec, DatatypeKindSpec } from "./shape.js"
2
+
3
+ export type MatrixDialect = "standard" | "postgres" | "mysql" | "sqlite"
4
+
5
+ export const portableDatatypeFamilies = {
6
+ uuid: {
7
+ compareGroup: "uuid",
8
+ castTargets: ["uuid", "char", "varchar", "text"],
9
+ traits: {
10
+ textual: true
11
+ }
12
+ },
13
+ text: {
14
+ compareGroup: "text",
15
+ castTargets: [
16
+ "text",
17
+ "numeric",
18
+ "integer",
19
+ "real",
20
+ "boolean",
21
+ "date",
22
+ "time",
23
+ "datetime",
24
+ "interval",
25
+ "uuid",
26
+ "json",
27
+ "blob",
28
+ "binary",
29
+ "array",
30
+ "range",
31
+ "multirange",
32
+ "record",
33
+ "enum",
34
+ "set",
35
+ "money",
36
+ "null"
37
+ ],
38
+ traits: {
39
+ textual: true,
40
+ ordered: true
41
+ }
42
+ },
43
+ numeric: {
44
+ compareGroup: "numeric",
45
+ castTargets: ["numeric", "integer", "real", "text", "boolean", "date", "time", "datetime"],
46
+ traits: {
47
+ ordered: true
48
+ }
49
+ },
50
+ integer: {
51
+ compareGroup: "numeric",
52
+ castTargets: ["integer", "numeric", "real", "text", "boolean", "date", "time", "datetime"],
53
+ traits: {
54
+ ordered: true
55
+ }
56
+ },
57
+ real: {
58
+ compareGroup: "numeric",
59
+ castTargets: ["real", "numeric", "integer", "text", "boolean"],
60
+ traits: {
61
+ ordered: true
62
+ }
63
+ },
64
+ boolean: {
65
+ compareGroup: "boolean",
66
+ castTargets: ["boolean", "integer", "numeric", "text"],
67
+ traits: {}
68
+ },
69
+ date: {
70
+ compareGroup: "date",
71
+ castTargets: ["date", "time", "datetime", "text", "numeric", "integer"],
72
+ traits: {
73
+ ordered: true
74
+ }
75
+ },
76
+ time: {
77
+ compareGroup: "time",
78
+ castTargets: ["time", "date", "datetime", "text", "numeric", "integer"],
79
+ traits: {
80
+ ordered: true
81
+ }
82
+ },
83
+ datetime: {
84
+ compareGroup: "datetime",
85
+ castTargets: ["datetime", "date", "time", "text", "numeric", "integer"],
86
+ traits: {
87
+ ordered: true
88
+ }
89
+ },
90
+ json: {
91
+ compareGroup: "json",
92
+ castTargets: ["json", "text"],
93
+ traits: {}
94
+ },
95
+ blob: {
96
+ compareGroup: "blob",
97
+ castTargets: ["blob", "text"],
98
+ traits: {}
99
+ },
100
+ null: {
101
+ compareGroup: "null",
102
+ castTargets: ["uuid", "text", "numeric", "integer", "real", "boolean", "date", "time", "datetime", "json", "blob", "null"],
103
+ traits: {}
104
+ }
105
+ } as const satisfies Record<string, DatatypeFamilySpec>
106
+
107
+ export const portableDatatypeKinds = {
108
+ uuid: { family: "uuid", runtime: "string" },
109
+ text: { family: "text", runtime: "string" },
110
+ varchar: { family: "text", runtime: "string" },
111
+ char: { family: "text", runtime: "string" },
112
+ int: { family: "integer", runtime: "number" },
113
+ integer: { family: "integer", runtime: "number" },
114
+ bigint: { family: "integer", runtime: "bigintString" },
115
+ numeric: { family: "numeric", runtime: "decimalString" },
116
+ decimal: { family: "numeric", runtime: "decimalString" },
117
+ real: { family: "real", runtime: "number" },
118
+ boolean: { family: "boolean", runtime: "boolean" },
119
+ date: { family: "date", runtime: "localDate" },
120
+ time: { family: "time", runtime: "localTime" },
121
+ datetime: { family: "datetime", runtime: "localDateTime" },
122
+ timestamp: { family: "datetime", runtime: "localDateTime" },
123
+ json: { family: "json", runtime: "json" },
124
+ blob: { family: "blob", runtime: "bytes" }
125
+ } as const satisfies Record<string, DatatypeKindSpec>
126
+
127
+ export type PortableDatatypeFamily = keyof typeof portableDatatypeFamilies
128
+ export type PortableDatatypeKind = keyof typeof portableDatatypeKinds
129
+
130
+ export const portableDatatypeKeys = Object.keys(portableDatatypeKinds) as ReadonlyArray<PortableDatatypeKind>
131
+
132
+ export const portableDatatypeDdlTypeByDialect = {
133
+ standard: {
134
+ uuid: "uuid",
135
+ text: "text",
136
+ varchar: "varchar",
137
+ char: "char",
138
+ int: "int",
139
+ integer: "integer",
140
+ bigint: "bigint",
141
+ numeric: "numeric",
142
+ decimal: "decimal",
143
+ real: "real",
144
+ boolean: "boolean",
145
+ date: "date",
146
+ time: "time",
147
+ datetime: "datetime",
148
+ timestamp: "timestamp",
149
+ json: "json",
150
+ blob: "blob"
151
+ },
152
+ postgres: {
153
+ uuid: "uuid",
154
+ text: "text",
155
+ varchar: "varchar",
156
+ char: "char",
157
+ int: "int",
158
+ integer: "integer",
159
+ bigint: "bigint",
160
+ numeric: "numeric",
161
+ decimal: "decimal",
162
+ real: "real",
163
+ boolean: "boolean",
164
+ date: "date",
165
+ time: "time",
166
+ datetime: "timestamp",
167
+ timestamp: "timestamp",
168
+ json: "json",
169
+ blob: "bytea"
170
+ },
171
+ mysql: {
172
+ uuid: "char(36)",
173
+ text: "text",
174
+ varchar: "varchar(255)",
175
+ char: "char",
176
+ int: "int",
177
+ integer: "integer",
178
+ bigint: "bigint",
179
+ numeric: "numeric",
180
+ decimal: "decimal",
181
+ real: "real",
182
+ boolean: "boolean",
183
+ date: "date",
184
+ time: "time",
185
+ datetime: "datetime",
186
+ timestamp: "timestamp",
187
+ json: "json",
188
+ blob: "blob"
189
+ },
190
+ sqlite: {
191
+ uuid: "text",
192
+ text: "text",
193
+ varchar: "varchar",
194
+ char: "char",
195
+ int: "int",
196
+ integer: "integer",
197
+ bigint: "bigint",
198
+ numeric: "numeric",
199
+ decimal: "decimal",
200
+ real: "real",
201
+ boolean: "boolean",
202
+ date: "date",
203
+ time: "time",
204
+ datetime: "datetime",
205
+ timestamp: "datetime",
206
+ json: "json",
207
+ blob: "blob"
208
+ }
209
+ } as const satisfies Record<MatrixDialect, Record<PortableDatatypeKind, string>>
210
+
211
+ export const portableDatatypeCastTypeByDialect = {
212
+ standard: portableDatatypeDdlTypeByDialect.standard,
213
+ postgres: portableDatatypeDdlTypeByDialect.postgres,
214
+ mysql: {
215
+ ...portableDatatypeDdlTypeByDialect.mysql,
216
+ uuid: "char(36)",
217
+ text: "char",
218
+ varchar: "char",
219
+ char: "char",
220
+ int: "signed",
221
+ integer: "signed",
222
+ bigint: "signed",
223
+ numeric: "decimal",
224
+ decimal: "decimal",
225
+ boolean: "unsigned",
226
+ datetime: "datetime",
227
+ timestamp: "datetime",
228
+ blob: "binary"
229
+ },
230
+ sqlite: {
231
+ ...portableDatatypeDdlTypeByDialect.sqlite,
232
+ uuid: "text",
233
+ int: "integer",
234
+ timestamp: "datetime"
235
+ }
236
+ } as const satisfies Record<MatrixDialect, Record<PortableDatatypeKind, string>>
237
+
238
+ const hasOwn = <Key extends PropertyKey>(
239
+ value: object,
240
+ key: Key
241
+ ): key is Key & keyof typeof value =>
242
+ Object.prototype.hasOwnProperty.call(value, key)
243
+
244
+ export const renderPortableDatatypeDdlType = (
245
+ dialect: string,
246
+ kind: string
247
+ ): string | undefined => {
248
+ if (!hasOwn(portableDatatypeDdlTypeByDialect, dialect)) {
249
+ return undefined
250
+ }
251
+ const byKind = portableDatatypeDdlTypeByDialect[dialect]
252
+ return hasOwn(byKind, kind) ? byKind[kind] : undefined
253
+ }
254
+
255
+ export const renderPortableDatatypeCastType = (
256
+ dialect: string,
257
+ kind: string
258
+ ): string | undefined => {
259
+ if (!hasOwn(portableDatatypeCastTypeByDialect, dialect)) {
260
+ return undefined
261
+ }
262
+ const byKind = portableDatatypeCastTypeByDialect[dialect]
263
+ return hasOwn(byKind, kind) ? byKind[kind] : undefined
264
+ }
265
+
266
+ export const postgresDatatypeFamilies = {
267
+ text: {
268
+ compareGroup: "text",
269
+ castTargets: [
270
+ "text",
271
+ "numeric",
272
+ "boolean",
273
+ "date",
274
+ "time",
275
+ "timestamp",
276
+ "interval",
277
+ "binary",
278
+ "uuid",
279
+ "json",
280
+ "xml",
281
+ "bit",
282
+ "oid",
283
+ "identifier",
284
+ "network",
285
+ "spatial",
286
+ "textsearch",
287
+ "range",
288
+ "multirange",
289
+ "array",
290
+ "money",
291
+ "null"
292
+ ],
293
+ traits: {
294
+ textual: true,
295
+ ordered: true
296
+ }
297
+ },
298
+ numeric: {
299
+ compareGroup: "numeric",
300
+ castTargets: ["numeric", "text", "boolean", "date", "time", "timestamp", "interval", "uuid", "bit", "oid", "money"],
301
+ traits: {
302
+ ordered: true
303
+ }
304
+ },
305
+ boolean: {
306
+ compareGroup: "boolean",
307
+ castTargets: ["boolean", "text", "numeric"],
308
+ traits: {}
309
+ },
310
+ date: {
311
+ compareGroup: "date",
312
+ castTargets: ["date", "timestamp", "text"],
313
+ traits: {
314
+ ordered: true
315
+ }
316
+ },
317
+ time: {
318
+ compareGroup: "time",
319
+ castTargets: ["time", "timestamp", "text"],
320
+ traits: {
321
+ ordered: true
322
+ }
323
+ },
324
+ timestamp: {
325
+ compareGroup: "timestamp",
326
+ castTargets: ["timestamp", "date", "text"],
327
+ traits: {
328
+ ordered: true
329
+ }
330
+ },
331
+ interval: {
332
+ compareGroup: "interval",
333
+ castTargets: ["interval", "text"],
334
+ traits: {
335
+ ordered: true
336
+ }
337
+ },
338
+ binary: {
339
+ compareGroup: "binary",
340
+ castTargets: ["binary", "text"],
341
+ traits: {}
342
+ },
343
+ uuid: {
344
+ compareGroup: "uuid",
345
+ castTargets: ["uuid", "text"],
346
+ traits: {
347
+ ordered: true
348
+ }
349
+ },
350
+ json: {
351
+ compareGroup: "json",
352
+ castTargets: ["json", "text"],
353
+ traits: {}
354
+ },
355
+ xml: {
356
+ compareGroup: "xml",
357
+ castTargets: ["xml", "text"],
358
+ traits: {}
359
+ },
360
+ bit: {
361
+ compareGroup: "bit",
362
+ castTargets: ["bit", "text", "numeric"],
363
+ traits: {}
364
+ },
365
+ oid: {
366
+ compareGroup: "oid",
367
+ castTargets: ["oid", "text", "numeric"],
368
+ traits: {
369
+ ordered: true
370
+ }
371
+ },
372
+ identifier: {
373
+ compareGroup: "identifier",
374
+ castTargets: ["identifier", "text"],
375
+ traits: {}
376
+ },
377
+ network: {
378
+ compareGroup: "network",
379
+ castTargets: ["network", "text"],
380
+ traits: {}
381
+ },
382
+ spatial: {
383
+ compareGroup: "spatial",
384
+ castTargets: ["spatial", "text"],
385
+ traits: {}
386
+ },
387
+ textsearch: {
388
+ compareGroup: "textsearch",
389
+ castTargets: ["textsearch", "text"],
390
+ traits: {}
391
+ },
392
+ range: {
393
+ compareGroup: "range",
394
+ castTargets: ["range", "text"],
395
+ traits: {}
396
+ },
397
+ multirange: {
398
+ compareGroup: "multirange",
399
+ castTargets: ["multirange", "text"],
400
+ traits: {}
401
+ },
402
+ enum: {
403
+ compareGroup: "enum",
404
+ castTargets: ["enum", "text"],
405
+ traits: {
406
+ textual: true,
407
+ ordered: true
408
+ }
409
+ },
410
+ record: {
411
+ compareGroup: "record",
412
+ castTargets: ["record", "text"],
413
+ traits: {}
414
+ },
415
+ array: {
416
+ compareGroup: "array",
417
+ castTargets: ["array", "text"],
418
+ traits: {}
419
+ },
420
+ money: {
421
+ compareGroup: "money",
422
+ castTargets: ["money", "text", "numeric"],
423
+ traits: {
424
+ ordered: true
425
+ }
426
+ },
427
+ null: {
428
+ compareGroup: "null",
429
+ castTargets: [
430
+ "text",
431
+ "numeric",
432
+ "boolean",
433
+ "date",
434
+ "time",
435
+ "timestamp",
436
+ "interval",
437
+ "binary",
438
+ "uuid",
439
+ "json",
440
+ "xml",
441
+ "bit",
442
+ "oid",
443
+ "identifier",
444
+ "network",
445
+ "spatial",
446
+ "textsearch",
447
+ "range",
448
+ "multirange",
449
+ "array",
450
+ "money",
451
+ "null"
452
+ ],
453
+ traits: {}
454
+ }
455
+ } as const satisfies Record<string, DatatypeFamilySpec>
456
+
457
+ export const postgresDatatypeKinds = {
458
+ text: { family: "text", runtime: "string" },
459
+ varchar: { family: "text", runtime: "string" },
460
+ char: { family: "text", runtime: "string" },
461
+ citext: { family: "text", runtime: "string" },
462
+ name: { family: "text", runtime: "string" },
463
+ uuid: { family: "uuid", runtime: "string" },
464
+ int2: { family: "numeric", runtime: "number" },
465
+ int4: { family: "numeric", runtime: "number" },
466
+ int8: { family: "numeric", runtime: "bigintString" },
467
+ numeric: { family: "numeric", runtime: "decimalString" },
468
+ float4: { family: "numeric", runtime: "number" },
469
+ float8: { family: "numeric", runtime: "number" },
470
+ money: { family: "money", runtime: "number" },
471
+ bool: { family: "boolean", runtime: "boolean" },
472
+ date: { family: "date", runtime: "localDate" },
473
+ time: { family: "time", runtime: "localTime" },
474
+ timetz: { family: "time", runtime: "offsetTime" },
475
+ timestamp: { family: "timestamp", runtime: "localDateTime" },
476
+ timestamptz: { family: "timestamp", runtime: "instant" },
477
+ interval: { family: "interval", runtime: "string" },
478
+ bytea: { family: "binary", runtime: "bytes" },
479
+ json: { family: "json", runtime: "json" },
480
+ jsonb: { family: "json", runtime: "json" },
481
+ xml: { family: "xml", runtime: "string" },
482
+ bit: { family: "bit", runtime: "string" },
483
+ varbit: { family: "bit", runtime: "string" },
484
+ oid: { family: "oid", runtime: "number" },
485
+ xid: { family: "oid", runtime: "number" },
486
+ xid8: { family: "oid", runtime: "bigintString" },
487
+ cid: { family: "oid", runtime: "number" },
488
+ tid: { family: "identifier", runtime: "string" },
489
+ regclass: { family: "identifier", runtime: "string" },
490
+ regtype: { family: "identifier", runtime: "string" },
491
+ regproc: { family: "identifier", runtime: "string" },
492
+ regprocedure: { family: "identifier", runtime: "string" },
493
+ regoper: { family: "identifier", runtime: "string" },
494
+ regoperator: { family: "identifier", runtime: "string" },
495
+ regconfig: { family: "identifier", runtime: "string" },
496
+ regdictionary: { family: "identifier", runtime: "string" },
497
+ pg_lsn: { family: "identifier", runtime: "string" },
498
+ txid_snapshot: { family: "identifier", runtime: "string" },
499
+ inet: { family: "network", runtime: "string" },
500
+ cidr: { family: "network", runtime: "string" },
501
+ macaddr: { family: "network", runtime: "string" },
502
+ macaddr8: { family: "network", runtime: "string" },
503
+ point: { family: "spatial", runtime: "unknown" },
504
+ line: { family: "spatial", runtime: "unknown" },
505
+ lseg: { family: "spatial", runtime: "unknown" },
506
+ box: { family: "spatial", runtime: "unknown" },
507
+ path: { family: "spatial", runtime: "unknown" },
508
+ polygon: { family: "spatial", runtime: "unknown" },
509
+ circle: { family: "spatial", runtime: "unknown" },
510
+ tsvector: { family: "textsearch", runtime: "string" },
511
+ tsquery: { family: "textsearch", runtime: "string" },
512
+ int4range: { family: "range", runtime: "unknown" },
513
+ int8range: { family: "range", runtime: "unknown" },
514
+ numrange: { family: "range", runtime: "unknown" },
515
+ tsrange: { family: "range", runtime: "unknown" },
516
+ tstzrange: { family: "range", runtime: "unknown" },
517
+ daterange: { family: "range", runtime: "unknown" },
518
+ int4multirange: { family: "multirange", runtime: "unknown" },
519
+ int8multirange: { family: "multirange", runtime: "unknown" },
520
+ nummultirange: { family: "multirange", runtime: "unknown" },
521
+ tsmultirange: { family: "multirange", runtime: "unknown" },
522
+ tstzmultirange: { family: "multirange", runtime: "unknown" },
523
+ datemultirange: { family: "multirange", runtime: "unknown" }
524
+ } as const satisfies Record<string, DatatypeKindSpec>
525
+
526
+ export const postgresSpecificDatatypeKeys = [
527
+ "int2",
528
+ "int4",
529
+ "int8",
530
+ "float4",
531
+ "float8",
532
+ "money",
533
+ "bool",
534
+ "timetz",
535
+ "timestamptz",
536
+ "interval",
537
+ "bytea",
538
+ "citext",
539
+ "name",
540
+ "jsonb",
541
+ "xml",
542
+ "bit",
543
+ "varbit",
544
+ "oid",
545
+ "xid",
546
+ "xid8",
547
+ "cid",
548
+ "tid",
549
+ "regclass",
550
+ "regtype",
551
+ "regproc",
552
+ "regprocedure",
553
+ "regoper",
554
+ "regoperator",
555
+ "regconfig",
556
+ "regdictionary",
557
+ "pg_lsn",
558
+ "txid_snapshot",
559
+ "inet",
560
+ "cidr",
561
+ "macaddr",
562
+ "macaddr8",
563
+ "point",
564
+ "line",
565
+ "lseg",
566
+ "box",
567
+ "path",
568
+ "polygon",
569
+ "circle",
570
+ "tsvector",
571
+ "tsquery",
572
+ "int4range",
573
+ "int8range",
574
+ "numrange",
575
+ "tsrange",
576
+ "tstzrange",
577
+ "daterange",
578
+ "int4multirange",
579
+ "int8multirange",
580
+ "nummultirange",
581
+ "tsmultirange",
582
+ "tstzmultirange",
583
+ "datemultirange"
584
+ ] as const satisfies ReadonlyArray<keyof typeof postgresDatatypeKinds>
585
+
586
+ export type PostgresSpecificDatatypeKey = typeof postgresSpecificDatatypeKeys[number]
587
+
588
+ export const mysqlDatatypeFamilies = {
589
+ text: {
590
+ compareGroup: "text",
591
+ castTargets: [
592
+ "text",
593
+ "numeric",
594
+ "boolean",
595
+ "date",
596
+ "time",
597
+ "datetime",
598
+ "timestamp",
599
+ "year",
600
+ "binary",
601
+ "json",
602
+ "bit",
603
+ "enum",
604
+ "set",
605
+ "null"
606
+ ],
607
+ traits: {
608
+ textual: true,
609
+ ordered: true
610
+ }
611
+ },
612
+ numeric: {
613
+ compareGroup: "numeric",
614
+ castTargets: ["numeric", "text", "boolean", "date", "time", "datetime", "timestamp", "year", "bit"],
615
+ traits: {
616
+ ordered: true
617
+ }
618
+ },
619
+ boolean: {
620
+ compareGroup: "boolean",
621
+ castTargets: ["boolean", "text", "numeric"],
622
+ traits: {}
623
+ },
624
+ bit: {
625
+ compareGroup: "bit",
626
+ castTargets: ["bit", "text", "numeric"],
627
+ traits: {}
628
+ },
629
+ date: {
630
+ compareGroup: "date",
631
+ castTargets: ["date", "datetime", "timestamp", "text"],
632
+ traits: {
633
+ ordered: true
634
+ }
635
+ },
636
+ time: {
637
+ compareGroup: "time",
638
+ castTargets: ["time", "datetime", "timestamp", "text"],
639
+ traits: {
640
+ ordered: true
641
+ }
642
+ },
643
+ datetime: {
644
+ compareGroup: "datetime",
645
+ castTargets: ["datetime", "timestamp", "date", "text"],
646
+ traits: {
647
+ ordered: true
648
+ }
649
+ },
650
+ timestamp: {
651
+ compareGroup: "timestamp",
652
+ castTargets: ["timestamp", "datetime", "date", "text"],
653
+ traits: {
654
+ ordered: true
655
+ }
656
+ },
657
+ year: {
658
+ compareGroup: "year",
659
+ castTargets: ["year", "text", "numeric"],
660
+ traits: {
661
+ ordered: true
662
+ }
663
+ },
664
+ binary: {
665
+ compareGroup: "binary",
666
+ castTargets: ["binary", "text"],
667
+ traits: {}
668
+ },
669
+ json: {
670
+ compareGroup: "json",
671
+ castTargets: ["json", "text"],
672
+ traits: {}
673
+ },
674
+ spatial: {
675
+ compareGroup: "spatial",
676
+ castTargets: ["spatial", "text"],
677
+ traits: {}
678
+ },
679
+ enum: {
680
+ compareGroup: "enum",
681
+ castTargets: ["enum", "text"],
682
+ traits: {
683
+ textual: true,
684
+ ordered: true
685
+ }
686
+ },
687
+ set: {
688
+ compareGroup: "set",
689
+ castTargets: ["set", "text"],
690
+ traits: {
691
+ textual: true
692
+ }
693
+ },
694
+ null: {
695
+ compareGroup: "null",
696
+ castTargets: [
697
+ "text",
698
+ "numeric",
699
+ "boolean",
700
+ "bit",
701
+ "date",
702
+ "time",
703
+ "datetime",
704
+ "timestamp",
705
+ "year",
706
+ "binary",
707
+ "json",
708
+ "spatial",
709
+ "enum",
710
+ "set",
711
+ "null"
712
+ ],
713
+ traits: {}
714
+ }
715
+ } as const satisfies Record<string, DatatypeFamilySpec>
716
+
717
+ export const mysqlDatatypeKinds = {
718
+ char: { family: "text", runtime: "string" },
719
+ varchar: { family: "text", runtime: "string" },
720
+ tinytext: { family: "text", runtime: "string" },
721
+ text: { family: "text", runtime: "string" },
722
+ mediumtext: { family: "text", runtime: "string" },
723
+ longtext: { family: "text", runtime: "string" },
724
+ tinyint: { family: "numeric", runtime: "number" },
725
+ smallint: { family: "numeric", runtime: "number" },
726
+ mediumint: { family: "numeric", runtime: "number" },
727
+ int: { family: "numeric", runtime: "number" },
728
+ integer: { family: "numeric", runtime: "number" },
729
+ bigint: { family: "numeric", runtime: "bigintString" },
730
+ decimal: { family: "numeric", runtime: "decimalString" },
731
+ dec: { family: "numeric", runtime: "decimalString" },
732
+ numeric: { family: "numeric", runtime: "decimalString" },
733
+ fixed: { family: "numeric", runtime: "decimalString" },
734
+ float: { family: "numeric", runtime: "number" },
735
+ double: { family: "numeric", runtime: "number" },
736
+ real: { family: "numeric", runtime: "number" },
737
+ bool: { family: "boolean", runtime: "boolean" },
738
+ boolean: { family: "boolean", runtime: "boolean" },
739
+ bit: { family: "bit", runtime: "string" },
740
+ date: { family: "date", runtime: "localDate" },
741
+ time: { family: "time", runtime: "localTime" },
742
+ datetime: { family: "datetime", runtime: "localDateTime" },
743
+ timestamp: { family: "timestamp", runtime: "localDateTime" },
744
+ year: { family: "year", runtime: "year" },
745
+ binary: { family: "binary", runtime: "bytes" },
746
+ varbinary: { family: "binary", runtime: "bytes" },
747
+ tinyblob: { family: "binary", runtime: "bytes" },
748
+ blob: { family: "binary", runtime: "bytes" },
749
+ mediumblob: { family: "binary", runtime: "bytes" },
750
+ longblob: { family: "binary", runtime: "bytes" },
751
+ json: { family: "json", runtime: "json" },
752
+ geometry: { family: "spatial", runtime: "unknown" },
753
+ point: { family: "spatial", runtime: "unknown" },
754
+ linestring: { family: "spatial", runtime: "unknown" },
755
+ polygon: { family: "spatial", runtime: "unknown" },
756
+ multipoint: { family: "spatial", runtime: "unknown" },
757
+ multilinestring: { family: "spatial", runtime: "unknown" },
758
+ multipolygon: { family: "spatial", runtime: "unknown" },
759
+ geometrycollection: { family: "spatial", runtime: "unknown" },
760
+ enum: { family: "enum", runtime: "string" },
761
+ set: { family: "set", runtime: "string" }
762
+ } as const satisfies Record<string, DatatypeKindSpec>
763
+
764
+ export const mysqlSpecificDatatypeKeys = [
765
+ "tinytext",
766
+ "mediumtext",
767
+ "longtext",
768
+ "tinyint",
769
+ "smallint",
770
+ "mediumint",
771
+ "dec",
772
+ "fixed",
773
+ "float",
774
+ "double",
775
+ "bool",
776
+ "bit",
777
+ "year",
778
+ "binary",
779
+ "varbinary",
780
+ "tinyblob",
781
+ "mediumblob",
782
+ "longblob",
783
+ "geometry",
784
+ "point",
785
+ "linestring",
786
+ "polygon",
787
+ "multipoint",
788
+ "multilinestring",
789
+ "multipolygon",
790
+ "geometrycollection"
791
+ ] as const satisfies ReadonlyArray<keyof typeof mysqlDatatypeKinds>
792
+
793
+ export type MysqlSpecificDatatypeKey = typeof mysqlSpecificDatatypeKeys[number]
794
+
795
+ export const sqliteDatatypeFamilies = {
796
+ text: {
797
+ compareGroup: "text",
798
+ castTargets: ["text", "numeric", "integer", "real", "boolean", "date", "time", "datetime", "json", "blob", "null"],
799
+ traits: {
800
+ textual: true,
801
+ ordered: true
802
+ }
803
+ },
804
+ numeric: {
805
+ compareGroup: "numeric",
806
+ castTargets: ["numeric", "integer", "real", "text", "boolean", "date", "time", "datetime"],
807
+ traits: {
808
+ ordered: true
809
+ }
810
+ },
811
+ integer: {
812
+ compareGroup: "numeric",
813
+ castTargets: ["integer", "numeric", "real", "text", "boolean", "date", "time", "datetime"],
814
+ traits: {
815
+ ordered: true
816
+ }
817
+ },
818
+ real: {
819
+ compareGroup: "numeric",
820
+ castTargets: ["real", "numeric", "integer", "text", "boolean"],
821
+ traits: {
822
+ ordered: true
823
+ }
824
+ },
825
+ boolean: {
826
+ compareGroup: "boolean",
827
+ castTargets: ["boolean", "integer", "numeric", "text"],
828
+ traits: {}
829
+ },
830
+ date: {
831
+ compareGroup: "date",
832
+ castTargets: ["date", "time", "datetime", "text", "numeric", "integer"],
833
+ traits: {
834
+ ordered: true
835
+ }
836
+ },
837
+ time: {
838
+ compareGroup: "time",
839
+ castTargets: ["time", "date", "datetime", "text", "numeric", "integer"],
840
+ traits: {
841
+ ordered: true
842
+ }
843
+ },
844
+ datetime: {
845
+ compareGroup: "datetime",
846
+ castTargets: ["datetime", "date", "time", "text", "numeric", "integer"],
847
+ traits: {
848
+ ordered: true
849
+ }
850
+ },
851
+ json: {
852
+ compareGroup: "json",
853
+ castTargets: ["json", "text"],
854
+ traits: {}
855
+ },
856
+ blob: {
857
+ compareGroup: "blob",
858
+ castTargets: ["blob", "text"],
859
+ traits: {}
860
+ },
861
+ null: {
862
+ compareGroup: "null",
863
+ castTargets: ["text", "numeric", "integer", "real", "boolean", "date", "time", "datetime", "json", "blob", "null"],
864
+ traits: {}
865
+ }
866
+ } as const satisfies Record<string, DatatypeFamilySpec>
867
+
868
+ export const sqliteDatatypeKinds = {
869
+ text: { family: "text", runtime: "string" },
870
+ varchar: { family: "text", runtime: "string" },
871
+ char: { family: "text", runtime: "string" },
872
+ clob: { family: "text", runtime: "string" },
873
+ int: { family: "integer", runtime: "number" },
874
+ integer: { family: "integer", runtime: "number" },
875
+ bigint: { family: "integer", runtime: "bigintString" },
876
+ numeric: { family: "numeric", runtime: "decimalString" },
877
+ decimal: { family: "numeric", runtime: "decimalString" },
878
+ real: { family: "real", runtime: "number" },
879
+ double: { family: "real", runtime: "number" },
880
+ boolean: { family: "boolean", runtime: "boolean" },
881
+ date: { family: "date", runtime: "localDate" },
882
+ time: { family: "time", runtime: "localTime" },
883
+ datetime: { family: "datetime", runtime: "localDateTime" },
884
+ timestamp: { family: "datetime", runtime: "localDateTime" },
885
+ json: { family: "json", runtime: "json" },
886
+ blob: { family: "blob", runtime: "bytes" }
887
+ } as const satisfies Record<string, DatatypeKindSpec>
888
+
889
+ export const sqliteSpecificDatatypeKeys = [
890
+ "clob",
891
+ "double"
892
+ ] as const satisfies ReadonlyArray<keyof typeof sqliteDatatypeKinds>
893
+
894
+ export type SqliteSpecificDatatypeKey = typeof sqliteSpecificDatatypeKeys[number]
895
+
896
+ export const pickDatatypeConstructors = <
897
+ Module extends Record<string, unknown>,
898
+ Keys extends ReadonlyArray<keyof Module & string>
899
+ >(
900
+ module: Module,
901
+ keys: Keys
902
+ ): Pick<Module, Keys[number]> =>
903
+ Object.fromEntries(keys.map((key) => [key, module[key]])) as Pick<Module, Keys[number]>