@prisma-next/adapter-postgres 0.3.0-dev.7 → 0.3.0-dev.70
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/LICENSE +201 -0
- package/README.md +64 -2
- package/dist/adapter-DtehReRR.mjs +271 -0
- package/dist/adapter-DtehReRR.mjs.map +1 -0
- package/dist/adapter.d.mts +23 -0
- package/dist/adapter.d.mts.map +1 -0
- package/dist/adapter.mjs +3 -0
- package/dist/codec-ids-Bsm9c7ns.mjs +29 -0
- package/dist/codec-ids-Bsm9c7ns.mjs.map +1 -0
- package/dist/codec-types.d.mts +141 -0
- package/dist/codec-types.d.mts.map +1 -0
- package/dist/codec-types.mjs +3 -0
- package/dist/codecs-BfC_5c-4.mjs +207 -0
- package/dist/codecs-BfC_5c-4.mjs.map +1 -0
- package/dist/column-types.d.mts +110 -0
- package/dist/column-types.d.mts.map +1 -0
- package/dist/column-types.mjs +180 -0
- package/dist/column-types.mjs.map +1 -0
- package/dist/control.d.mts +111 -0
- package/dist/control.d.mts.map +1 -0
- package/dist/control.mjs +462 -0
- package/dist/control.mjs.map +1 -0
- package/dist/descriptor-meta-ilnFI7bx.mjs +921 -0
- package/dist/descriptor-meta-ilnFI7bx.mjs.map +1 -0
- package/dist/runtime.d.mts +19 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +85 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/sql-utils-CSfAGEwF.mjs +78 -0
- package/dist/sql-utils-CSfAGEwF.mjs.map +1 -0
- package/dist/types-CXO7EB60.d.mts +19 -0
- package/dist/types-CXO7EB60.d.mts.map +1 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +1 -0
- package/package.json +37 -46
- package/src/core/adapter.ts +139 -28
- package/src/core/codec-ids.ts +28 -0
- package/src/core/codecs.ts +325 -23
- package/src/core/control-adapter.ts +400 -178
- package/src/core/default-normalizer.ts +90 -0
- package/src/core/descriptor-meta.ts +221 -9
- package/src/core/enum-control-hooks.ts +735 -0
- package/src/core/json-schema-type-expression.ts +131 -0
- package/src/core/json-schema-validator.ts +53 -0
- package/src/core/parameterized-types.ts +118 -0
- package/src/core/sql-utils.ts +111 -0
- package/src/core/standard-schema.ts +71 -0
- package/src/exports/codec-types.ts +73 -1
- package/src/exports/column-types.ts +233 -9
- package/src/exports/control.ts +16 -9
- package/src/exports/runtime.ts +61 -18
- package/dist/chunk-HD5YISNQ.js +0 -47
- package/dist/chunk-HD5YISNQ.js.map +0 -1
- package/dist/chunk-J3XSOAM2.js +0 -162
- package/dist/chunk-J3XSOAM2.js.map +0 -1
- package/dist/chunk-T6S3A6VT.js +0 -301
- package/dist/chunk-T6S3A6VT.js.map +0 -1
- package/dist/core/adapter.d.ts +0 -19
- package/dist/core/adapter.d.ts.map +0 -1
- package/dist/core/codecs.d.ts +0 -110
- package/dist/core/codecs.d.ts.map +0 -1
- package/dist/core/control-adapter.d.ts +0 -33
- package/dist/core/control-adapter.d.ts.map +0 -1
- package/dist/core/descriptor-meta.d.ts +0 -72
- package/dist/core/descriptor-meta.d.ts.map +0 -1
- package/dist/core/types.d.ts +0 -16
- package/dist/core/types.d.ts.map +0 -1
- package/dist/exports/adapter.d.ts +0 -2
- package/dist/exports/adapter.d.ts.map +0 -1
- package/dist/exports/adapter.js +0 -8
- package/dist/exports/adapter.js.map +0 -1
- package/dist/exports/codec-types.d.ts +0 -11
- package/dist/exports/codec-types.d.ts.map +0 -1
- package/dist/exports/codec-types.js +0 -7
- package/dist/exports/codec-types.js.map +0 -1
- package/dist/exports/column-types.d.ts +0 -17
- package/dist/exports/column-types.d.ts.map +0 -1
- package/dist/exports/column-types.js +0 -49
- package/dist/exports/column-types.js.map +0 -1
- package/dist/exports/control.d.ts +0 -8
- package/dist/exports/control.d.ts.map +0 -1
- package/dist/exports/control.js +0 -279
- package/dist/exports/control.js.map +0 -1
- package/dist/exports/runtime.d.ts +0 -15
- package/dist/exports/runtime.d.ts.map +0 -1
- package/dist/exports/runtime.js +0 -20
- package/dist/exports/runtime.js.map +0 -1
- package/dist/exports/types.d.ts +0 -2
- package/dist/exports/types.d.ts.map +0 -1
- package/dist/exports/types.js +0 -1
- package/dist/exports/types.js.map +0 -1
package/src/core/codecs.ts
CHANGED
|
@@ -11,11 +11,89 @@
|
|
|
11
11
|
* at compile time (to derive CodecTypes).
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import type { Codec, CodecMeta } from '@prisma-next/sql-relational-core/ast';
|
|
15
|
+
import { codec, defineCodecs, sqlCodecDefinitions } from '@prisma-next/sql-relational-core/ast';
|
|
16
|
+
import { ifDefined } from '@prisma-next/utils/defined';
|
|
17
|
+
import { type as arktype } from 'arktype';
|
|
18
|
+
import {
|
|
19
|
+
PG_BIT_CODEC_ID,
|
|
20
|
+
PG_BOOL_CODEC_ID,
|
|
21
|
+
PG_CHAR_CODEC_ID,
|
|
22
|
+
PG_ENUM_CODEC_ID,
|
|
23
|
+
PG_FLOAT_CODEC_ID,
|
|
24
|
+
PG_FLOAT4_CODEC_ID,
|
|
25
|
+
PG_FLOAT8_CODEC_ID,
|
|
26
|
+
PG_INT_CODEC_ID,
|
|
27
|
+
PG_INT2_CODEC_ID,
|
|
28
|
+
PG_INT4_CODEC_ID,
|
|
29
|
+
PG_INT8_CODEC_ID,
|
|
30
|
+
PG_INTERVAL_CODEC_ID,
|
|
31
|
+
PG_JSON_CODEC_ID,
|
|
32
|
+
PG_JSONB_CODEC_ID,
|
|
33
|
+
PG_NUMERIC_CODEC_ID,
|
|
34
|
+
PG_TEXT_CODEC_ID,
|
|
35
|
+
PG_TIME_CODEC_ID,
|
|
36
|
+
PG_TIMESTAMP_CODEC_ID,
|
|
37
|
+
PG_TIMESTAMPTZ_CODEC_ID,
|
|
38
|
+
PG_TIMETZ_CODEC_ID,
|
|
39
|
+
PG_VARBIT_CODEC_ID,
|
|
40
|
+
PG_VARCHAR_CODEC_ID,
|
|
41
|
+
} from './codec-ids';
|
|
42
|
+
|
|
43
|
+
const lengthParamsSchema = arktype({
|
|
44
|
+
length: 'number.integer > 0',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const numericParamsSchema = arktype({
|
|
48
|
+
precision: 'number.integer > 0 & number.integer <= 1000',
|
|
49
|
+
'scale?': 'number.integer >= 0',
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const precisionParamsSchema = arktype({
|
|
53
|
+
'precision?': 'number.integer >= 0 & number.integer <= 6',
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
function aliasCodec<
|
|
57
|
+
Id extends string,
|
|
58
|
+
TWire,
|
|
59
|
+
TJs,
|
|
60
|
+
TParams = Record<string, unknown>,
|
|
61
|
+
THelper = unknown,
|
|
62
|
+
>(
|
|
63
|
+
base: Codec<string, TWire, TJs, TParams, THelper>,
|
|
64
|
+
options: {
|
|
65
|
+
readonly typeId: Id;
|
|
66
|
+
readonly targetTypes: readonly string[];
|
|
67
|
+
readonly meta?: CodecMeta;
|
|
68
|
+
},
|
|
69
|
+
): Codec<Id, TWire, TJs, TParams, THelper> {
|
|
70
|
+
return {
|
|
71
|
+
id: options.typeId,
|
|
72
|
+
targetTypes: options.targetTypes,
|
|
73
|
+
...ifDefined('meta', options.meta),
|
|
74
|
+
...ifDefined('paramsSchema', base.paramsSchema),
|
|
75
|
+
...ifDefined('init', base.init),
|
|
76
|
+
...ifDefined('encode', base.encode),
|
|
77
|
+
decode: base.decode,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const sqlCharCodec = sqlCodecDefinitions.char.codec;
|
|
82
|
+
const sqlVarcharCodec = sqlCodecDefinitions.varchar.codec;
|
|
83
|
+
const sqlIntCodec = sqlCodecDefinitions.int.codec;
|
|
84
|
+
const sqlFloatCodec = sqlCodecDefinitions.float.codec;
|
|
85
|
+
|
|
86
|
+
export type JsonValue =
|
|
87
|
+
| string
|
|
88
|
+
| number
|
|
89
|
+
| boolean
|
|
90
|
+
| null
|
|
91
|
+
| { readonly [key: string]: JsonValue }
|
|
92
|
+
| readonly JsonValue[];
|
|
15
93
|
|
|
16
94
|
// Create individual codec instances
|
|
17
95
|
const pgTextCodec = codec({
|
|
18
|
-
typeId:
|
|
96
|
+
typeId: PG_TEXT_CODEC_ID,
|
|
19
97
|
targetTypes: ['text'],
|
|
20
98
|
encode: (value: string): string => value,
|
|
21
99
|
decode: (wire: string): string => wire,
|
|
@@ -30,8 +108,64 @@ const pgTextCodec = codec({
|
|
|
30
108
|
},
|
|
31
109
|
});
|
|
32
110
|
|
|
33
|
-
const
|
|
34
|
-
typeId:
|
|
111
|
+
const pgCharCodec = aliasCodec(sqlCharCodec, {
|
|
112
|
+
typeId: PG_CHAR_CODEC_ID,
|
|
113
|
+
targetTypes: ['character'],
|
|
114
|
+
meta: {
|
|
115
|
+
db: {
|
|
116
|
+
sql: {
|
|
117
|
+
postgres: {
|
|
118
|
+
nativeType: 'character',
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const pgVarcharCodec = aliasCodec(sqlVarcharCodec, {
|
|
126
|
+
typeId: PG_VARCHAR_CODEC_ID,
|
|
127
|
+
targetTypes: ['character varying'],
|
|
128
|
+
meta: {
|
|
129
|
+
db: {
|
|
130
|
+
sql: {
|
|
131
|
+
postgres: {
|
|
132
|
+
nativeType: 'character varying',
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const pgIntCodec = aliasCodec(sqlIntCodec, {
|
|
140
|
+
typeId: PG_INT_CODEC_ID,
|
|
141
|
+
targetTypes: ['int4'],
|
|
142
|
+
meta: {
|
|
143
|
+
db: {
|
|
144
|
+
sql: {
|
|
145
|
+
postgres: {
|
|
146
|
+
nativeType: 'integer',
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const pgFloatCodec = aliasCodec(sqlFloatCodec, {
|
|
154
|
+
typeId: PG_FLOAT_CODEC_ID,
|
|
155
|
+
targetTypes: ['float8'],
|
|
156
|
+
meta: {
|
|
157
|
+
db: {
|
|
158
|
+
sql: {
|
|
159
|
+
postgres: {
|
|
160
|
+
nativeType: 'double precision',
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const pgInt4Codec = codec<typeof PG_INT4_CODEC_ID, number, number>({
|
|
168
|
+
typeId: PG_INT4_CODEC_ID,
|
|
35
169
|
targetTypes: ['int4'],
|
|
36
170
|
encode: (value) => value,
|
|
37
171
|
decode: (wire) => wire,
|
|
@@ -46,8 +180,28 @@ const pgInt4Codec = codec<'pg/int4@1', number, number>({
|
|
|
46
180
|
},
|
|
47
181
|
});
|
|
48
182
|
|
|
49
|
-
const
|
|
50
|
-
typeId:
|
|
183
|
+
const pgNumericCodec = codec<typeof PG_NUMERIC_CODEC_ID, string, string>({
|
|
184
|
+
typeId: PG_NUMERIC_CODEC_ID,
|
|
185
|
+
targetTypes: ['numeric', 'decimal'],
|
|
186
|
+
encode: (value: string): string => value,
|
|
187
|
+
decode: (wire: string | number): string => {
|
|
188
|
+
if (typeof wire === 'number') return String(wire);
|
|
189
|
+
return wire;
|
|
190
|
+
},
|
|
191
|
+
paramsSchema: numericParamsSchema,
|
|
192
|
+
meta: {
|
|
193
|
+
db: {
|
|
194
|
+
sql: {
|
|
195
|
+
postgres: {
|
|
196
|
+
nativeType: 'numeric',
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const pgInt2Codec = codec<typeof PG_INT2_CODEC_ID, number, number>({
|
|
204
|
+
typeId: PG_INT2_CODEC_ID,
|
|
51
205
|
targetTypes: ['int2'],
|
|
52
206
|
encode: (value) => value,
|
|
53
207
|
decode: (wire) => wire,
|
|
@@ -62,8 +216,8 @@ const pgInt2Codec = codec<'pg/int2@1', number, number>({
|
|
|
62
216
|
},
|
|
63
217
|
});
|
|
64
218
|
|
|
65
|
-
const pgInt8Codec = codec<
|
|
66
|
-
typeId:
|
|
219
|
+
const pgInt8Codec = codec<typeof PG_INT8_CODEC_ID, number, number>({
|
|
220
|
+
typeId: PG_INT8_CODEC_ID,
|
|
67
221
|
targetTypes: ['int8'],
|
|
68
222
|
encode: (value) => value,
|
|
69
223
|
decode: (wire) => wire,
|
|
@@ -78,8 +232,8 @@ const pgInt8Codec = codec<'pg/int8@1', number, number>({
|
|
|
78
232
|
},
|
|
79
233
|
});
|
|
80
234
|
|
|
81
|
-
const pgFloat4Codec = codec<
|
|
82
|
-
typeId:
|
|
235
|
+
const pgFloat4Codec = codec<typeof PG_FLOAT4_CODEC_ID, number, number>({
|
|
236
|
+
typeId: PG_FLOAT4_CODEC_ID,
|
|
83
237
|
targetTypes: ['float4'],
|
|
84
238
|
encode: (value) => value,
|
|
85
239
|
decode: (wire) => wire,
|
|
@@ -94,8 +248,8 @@ const pgFloat4Codec = codec<'pg/float4@1', number, number>({
|
|
|
94
248
|
},
|
|
95
249
|
});
|
|
96
250
|
|
|
97
|
-
const pgFloat8Codec = codec<
|
|
98
|
-
typeId:
|
|
251
|
+
const pgFloat8Codec = codec<typeof PG_FLOAT8_CODEC_ID, number, number>({
|
|
252
|
+
typeId: PG_FLOAT8_CODEC_ID,
|
|
99
253
|
targetTypes: ['float8'],
|
|
100
254
|
encode: (value) => value,
|
|
101
255
|
decode: (wire) => wire,
|
|
@@ -110,8 +264,8 @@ const pgFloat8Codec = codec<'pg/float8@1', number, number>({
|
|
|
110
264
|
},
|
|
111
265
|
});
|
|
112
266
|
|
|
113
|
-
const pgTimestampCodec = codec<
|
|
114
|
-
typeId:
|
|
267
|
+
const pgTimestampCodec = codec<typeof PG_TIMESTAMP_CODEC_ID, string | Date, string>({
|
|
268
|
+
typeId: PG_TIMESTAMP_CODEC_ID,
|
|
115
269
|
targetTypes: ['timestamp'],
|
|
116
270
|
encode: (value: string | Date): string => {
|
|
117
271
|
if (value instanceof Date) return value.toISOString();
|
|
@@ -119,10 +273,10 @@ const pgTimestampCodec = codec<'pg/timestamp@1', string | Date, string>({
|
|
|
119
273
|
return String(value);
|
|
120
274
|
},
|
|
121
275
|
decode: (wire: string | Date): string => {
|
|
122
|
-
if (typeof wire === 'string') return wire;
|
|
123
276
|
if (wire instanceof Date) return wire.toISOString();
|
|
124
|
-
return
|
|
277
|
+
return wire;
|
|
125
278
|
},
|
|
279
|
+
paramsSchema: precisionParamsSchema,
|
|
126
280
|
meta: {
|
|
127
281
|
db: {
|
|
128
282
|
sql: {
|
|
@@ -134,8 +288,8 @@ const pgTimestampCodec = codec<'pg/timestamp@1', string | Date, string>({
|
|
|
134
288
|
},
|
|
135
289
|
});
|
|
136
290
|
|
|
137
|
-
const pgTimestamptzCodec = codec<
|
|
138
|
-
typeId:
|
|
291
|
+
const pgTimestamptzCodec = codec<typeof PG_TIMESTAMPTZ_CODEC_ID, string | Date, string>({
|
|
292
|
+
typeId: PG_TIMESTAMPTZ_CODEC_ID,
|
|
139
293
|
targetTypes: ['timestamptz'],
|
|
140
294
|
encode: (value: string | Date): string => {
|
|
141
295
|
if (value instanceof Date) return value.toISOString();
|
|
@@ -143,10 +297,10 @@ const pgTimestamptzCodec = codec<'pg/timestamptz@1', string | Date, string>({
|
|
|
143
297
|
return String(value);
|
|
144
298
|
},
|
|
145
299
|
decode: (wire: string | Date): string => {
|
|
146
|
-
if (typeof wire === 'string') return wire;
|
|
147
300
|
if (wire instanceof Date) return wire.toISOString();
|
|
148
|
-
return
|
|
301
|
+
return wire;
|
|
149
302
|
},
|
|
303
|
+
paramsSchema: precisionParamsSchema,
|
|
150
304
|
meta: {
|
|
151
305
|
db: {
|
|
152
306
|
sql: {
|
|
@@ -158,8 +312,42 @@ const pgTimestamptzCodec = codec<'pg/timestamptz@1', string | Date, string>({
|
|
|
158
312
|
},
|
|
159
313
|
});
|
|
160
314
|
|
|
161
|
-
const
|
|
162
|
-
typeId:
|
|
315
|
+
const pgTimeCodec = codec<typeof PG_TIME_CODEC_ID, string, string>({
|
|
316
|
+
typeId: PG_TIME_CODEC_ID,
|
|
317
|
+
targetTypes: ['time'],
|
|
318
|
+
encode: (value: string): string => value,
|
|
319
|
+
decode: (wire: string): string => wire,
|
|
320
|
+
paramsSchema: precisionParamsSchema,
|
|
321
|
+
meta: {
|
|
322
|
+
db: {
|
|
323
|
+
sql: {
|
|
324
|
+
postgres: {
|
|
325
|
+
nativeType: 'time',
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
const pgTimetzCodec = codec<typeof PG_TIMETZ_CODEC_ID, string, string>({
|
|
333
|
+
typeId: PG_TIMETZ_CODEC_ID,
|
|
334
|
+
targetTypes: ['timetz'],
|
|
335
|
+
encode: (value: string): string => value,
|
|
336
|
+
decode: (wire: string): string => wire,
|
|
337
|
+
paramsSchema: precisionParamsSchema,
|
|
338
|
+
meta: {
|
|
339
|
+
db: {
|
|
340
|
+
sql: {
|
|
341
|
+
postgres: {
|
|
342
|
+
nativeType: 'timetz',
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
const pgBoolCodec = codec<typeof PG_BOOL_CODEC_ID, boolean, boolean>({
|
|
350
|
+
typeId: PG_BOOL_CODEC_ID,
|
|
163
351
|
targetTypes: ['bool'],
|
|
164
352
|
encode: (value) => value,
|
|
165
353
|
decode: (wire) => wire,
|
|
@@ -174,17 +362,131 @@ const pgBoolCodec = codec<'pg/bool@1', boolean, boolean>({
|
|
|
174
362
|
},
|
|
175
363
|
});
|
|
176
364
|
|
|
365
|
+
const pgBitCodec = codec<typeof PG_BIT_CODEC_ID, string, string>({
|
|
366
|
+
typeId: PG_BIT_CODEC_ID,
|
|
367
|
+
targetTypes: ['bit'],
|
|
368
|
+
encode: (value: string): string => value,
|
|
369
|
+
decode: (wire: string): string => wire,
|
|
370
|
+
paramsSchema: lengthParamsSchema,
|
|
371
|
+
meta: {
|
|
372
|
+
db: {
|
|
373
|
+
sql: {
|
|
374
|
+
postgres: {
|
|
375
|
+
nativeType: 'bit',
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
},
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
const pgVarbitCodec = codec<typeof PG_VARBIT_CODEC_ID, string, string>({
|
|
383
|
+
typeId: PG_VARBIT_CODEC_ID,
|
|
384
|
+
targetTypes: ['bit varying'],
|
|
385
|
+
encode: (value: string): string => value,
|
|
386
|
+
decode: (wire: string): string => wire,
|
|
387
|
+
paramsSchema: lengthParamsSchema,
|
|
388
|
+
meta: {
|
|
389
|
+
db: {
|
|
390
|
+
sql: {
|
|
391
|
+
postgres: {
|
|
392
|
+
nativeType: 'bit varying',
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
const pgEnumCodec = codec<typeof PG_ENUM_CODEC_ID, string, string>({
|
|
400
|
+
typeId: PG_ENUM_CODEC_ID,
|
|
401
|
+
targetTypes: ['enum'],
|
|
402
|
+
encode: (value) => value,
|
|
403
|
+
decode: (wire) => wire,
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
const pgIntervalCodec = codec<
|
|
407
|
+
typeof PG_INTERVAL_CODEC_ID,
|
|
408
|
+
string | Record<string, unknown>,
|
|
409
|
+
string
|
|
410
|
+
>({
|
|
411
|
+
typeId: PG_INTERVAL_CODEC_ID,
|
|
412
|
+
targetTypes: ['interval'],
|
|
413
|
+
encode: (value: string): string => value,
|
|
414
|
+
decode: (wire: string | Record<string, unknown>): string => {
|
|
415
|
+
if (typeof wire === 'string') return wire;
|
|
416
|
+
return JSON.stringify(wire);
|
|
417
|
+
},
|
|
418
|
+
paramsSchema: precisionParamsSchema,
|
|
419
|
+
meta: {
|
|
420
|
+
db: {
|
|
421
|
+
sql: {
|
|
422
|
+
postgres: {
|
|
423
|
+
nativeType: 'interval',
|
|
424
|
+
},
|
|
425
|
+
},
|
|
426
|
+
},
|
|
427
|
+
},
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
const pgJsonCodec = codec<typeof PG_JSON_CODEC_ID, string | JsonValue, JsonValue>({
|
|
431
|
+
typeId: PG_JSON_CODEC_ID,
|
|
432
|
+
targetTypes: ['json'],
|
|
433
|
+
encode: (value) => JSON.stringify(value),
|
|
434
|
+
decode: (wire) => (typeof wire === 'string' ? JSON.parse(wire) : wire),
|
|
435
|
+
meta: {
|
|
436
|
+
db: {
|
|
437
|
+
sql: {
|
|
438
|
+
postgres: {
|
|
439
|
+
nativeType: 'json',
|
|
440
|
+
},
|
|
441
|
+
},
|
|
442
|
+
},
|
|
443
|
+
},
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
const pgJsonbCodec = codec<typeof PG_JSONB_CODEC_ID, string | JsonValue, JsonValue>({
|
|
447
|
+
typeId: PG_JSONB_CODEC_ID,
|
|
448
|
+
targetTypes: ['jsonb'],
|
|
449
|
+
encode: (value) => JSON.stringify(value),
|
|
450
|
+
decode: (wire) => (typeof wire === 'string' ? JSON.parse(wire) : wire),
|
|
451
|
+
meta: {
|
|
452
|
+
db: {
|
|
453
|
+
sql: {
|
|
454
|
+
postgres: {
|
|
455
|
+
nativeType: 'jsonb',
|
|
456
|
+
},
|
|
457
|
+
},
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
});
|
|
461
|
+
|
|
177
462
|
// Build codec definitions using the builder DSL
|
|
178
463
|
const codecs = defineCodecs()
|
|
464
|
+
.add('char', sqlCharCodec)
|
|
465
|
+
.add('varchar', sqlVarcharCodec)
|
|
466
|
+
.add('int', sqlIntCodec)
|
|
467
|
+
.add('float', sqlFloatCodec)
|
|
179
468
|
.add('text', pgTextCodec)
|
|
469
|
+
.add('character', pgCharCodec)
|
|
470
|
+
.add('character varying', pgVarcharCodec)
|
|
471
|
+
.add('integer', pgIntCodec)
|
|
472
|
+
.add('double precision', pgFloatCodec)
|
|
180
473
|
.add('int4', pgInt4Codec)
|
|
181
474
|
.add('int2', pgInt2Codec)
|
|
182
475
|
.add('int8', pgInt8Codec)
|
|
183
476
|
.add('float4', pgFloat4Codec)
|
|
184
477
|
.add('float8', pgFloat8Codec)
|
|
478
|
+
.add('numeric', pgNumericCodec)
|
|
185
479
|
.add('timestamp', pgTimestampCodec)
|
|
186
480
|
.add('timestamptz', pgTimestamptzCodec)
|
|
187
|
-
.add('
|
|
481
|
+
.add('time', pgTimeCodec)
|
|
482
|
+
.add('timetz', pgTimetzCodec)
|
|
483
|
+
.add('bool', pgBoolCodec)
|
|
484
|
+
.add('bit', pgBitCodec)
|
|
485
|
+
.add('bit varying', pgVarbitCodec)
|
|
486
|
+
.add('interval', pgIntervalCodec)
|
|
487
|
+
.add('enum', pgEnumCodec)
|
|
488
|
+
.add('json', pgJsonCodec)
|
|
489
|
+
.add('jsonb', pgJsonbCodec);
|
|
188
490
|
|
|
189
491
|
// Export derived structures directly from codecs builder
|
|
190
492
|
export const codecDefinitions = codecs.codecDefinitions;
|