@uniflowed/sql 0.34.0 → 0.36.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/adapters/better-sqlite3.js +8 -8
- package/adapters/bun-sqlite.js +8 -8
- package/adapters/d1.js +2 -2
- package/adapters/mysql2.js +13 -13
- package/adapters/node-sqlite.js +7 -7
- package/adapters/pg.js +120 -9
- package/adapters/pglite.js +29 -6
- package/adapters/postgres.js +99 -8
- package/index.js +233 -97
- package/internal/shared.js +4 -4
- package/internal/statements.js +1 -1
- package/mysql.js +10 -10
- package/package.json +1 -1
- package/postgresql.js +14 -14
- package/sqlite.js +13 -13
package/mysql.js
CHANGED
|
@@ -34,8 +34,8 @@ export type MysqlParam = null | string | Uint8Array;
|
|
|
34
34
|
/** How one MySQL type becomes a Flow value and back. */
|
|
35
35
|
export type Codec<T> = {|
|
|
36
36
|
readonly sqlType: string,
|
|
37
|
-
readonly decode: (value: mixed) => T,
|
|
38
|
-
readonly encode: (value: T) => MysqlParam,
|
|
37
|
+
readonly decode : (value: mixed) => T,
|
|
38
|
+
readonly encode : (value: T) => MysqlParam,
|
|
39
39
|
|};
|
|
40
40
|
|
|
41
41
|
/** `TINYINT` through `INT`, signed or unsigned, and `YEAR`: all fit a `number`. */
|
|
@@ -55,7 +55,7 @@ export function integer(sqlType: string): Codec<number> {
|
|
|
55
55
|
/** `BIGINT`, signed or unsigned, exactly. */
|
|
56
56
|
export const bigint: Codec<bigint> = {
|
|
57
57
|
sqlType: "bigint",
|
|
58
|
-
decode: (value) => bigintFrom("bigint", value),
|
|
58
|
+
decode : (value) => bigintFrom("bigint", value),
|
|
59
59
|
encode: (value) => {
|
|
60
60
|
if (typeof value !== "bigint") {
|
|
61
61
|
return encodeError("bigint (a bigint)", value);
|
|
@@ -169,14 +169,14 @@ export function bytes(sqlType: string): Codec<Uint8Array> {
|
|
|
169
169
|
/** `JSON`. */
|
|
170
170
|
export const json: Codec<JsonValue> = {
|
|
171
171
|
sqlType: "json",
|
|
172
|
-
decode: (value) => jsonFromText(value),
|
|
173
|
-
encode: (value) => jsonParam(value),
|
|
172
|
+
decode : (value) => jsonFromText(value),
|
|
173
|
+
encode : (value) => jsonParam(value),
|
|
174
174
|
};
|
|
175
175
|
|
|
176
176
|
/** A result sqlc could not type. */
|
|
177
177
|
export const unknown: Codec<mixed> = {
|
|
178
178
|
sqlType: "unknown",
|
|
179
|
-
decode: (value) => value,
|
|
179
|
+
decode : (value) => value,
|
|
180
180
|
encode: (value) => {
|
|
181
181
|
if (value === null || typeof value === "string" || value instanceof Uint8Array) {
|
|
182
182
|
return value;
|
|
@@ -194,7 +194,7 @@ export const unknown: Codec<mixed> = {
|
|
|
194
194
|
/** An `ENUM(…)` column, from its values in declaration order. */
|
|
195
195
|
export function enumeration<T extends string>(
|
|
196
196
|
sqlType: string,
|
|
197
|
-
values: $ReadOnlyArray<T>,
|
|
197
|
+
values : $ReadOnlyArray<T>,
|
|
198
198
|
): Codec<T> {
|
|
199
199
|
const expected = `${sqlType} (${enumName(values)})`;
|
|
200
200
|
return {
|
|
@@ -209,14 +209,14 @@ export function enumeration<T extends string>(
|
|
|
209
209
|
* value back to what `codec` writes.
|
|
210
210
|
*/
|
|
211
211
|
export function map<T, U>(
|
|
212
|
-
codec: Codec<T>,
|
|
212
|
+
codec : Codec<T>,
|
|
213
213
|
decode: (value: T) => U,
|
|
214
214
|
encode: (value: U) => T,
|
|
215
215
|
): Codec<U> {
|
|
216
216
|
return {
|
|
217
217
|
sqlType: codec.sqlType,
|
|
218
|
-
decode: (value) => decode(codec.decode(value)),
|
|
219
|
-
encode: (value) => codec.encode(encode(value)),
|
|
218
|
+
decode : (value) => decode(codec.decode(value)),
|
|
219
|
+
encode : (value) => codec.encode(encode(value)),
|
|
220
220
|
};
|
|
221
221
|
}
|
|
222
222
|
|
package/package.json
CHANGED
package/postgresql.js
CHANGED
|
@@ -39,8 +39,8 @@ export type ArrayNode = string | null | $ReadOnlyArray<ArrayNode>;
|
|
|
39
39
|
export type Codec<T> = {|
|
|
40
40
|
/** For messages: `int8`, `text[]`. */
|
|
41
41
|
readonly sqlType: string,
|
|
42
|
-
readonly decode: (value: mixed) => T,
|
|
43
|
-
readonly encode: (value: T) => string,
|
|
42
|
+
readonly decode : (value: mixed) => T,
|
|
43
|
+
readonly encode : (value: T) => string,
|
|
44
44
|
readonly element: (node: ArrayNode) => T,
|
|
45
45
|
/** The value as it appears inside `{…}`: quoted, or a nested literal. */
|
|
46
46
|
readonly literal: (value: T) => string,
|
|
@@ -54,9 +54,9 @@ function quote(text: string): string {
|
|
|
54
54
|
|
|
55
55
|
/** A scalar codec from its two text conversions. */
|
|
56
56
|
export function scalar<T>(
|
|
57
|
-
sqlType: string,
|
|
57
|
+
sqlType : string,
|
|
58
58
|
fromText: (text: string) => T,
|
|
59
|
-
toText: (value: T) => string,
|
|
59
|
+
toText : (value: T) => string,
|
|
60
60
|
): Codec<T> {
|
|
61
61
|
const decode = (value: mixed): T => {
|
|
62
62
|
if (typeof value !== "string") {
|
|
@@ -78,7 +78,7 @@ export function scalar<T>(
|
|
|
78
78
|
return fromText(node);
|
|
79
79
|
},
|
|
80
80
|
literal: (value) => quote(toText(value)),
|
|
81
|
-
depth: 0,
|
|
81
|
+
depth : 0,
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
84
|
|
|
@@ -381,7 +381,7 @@ export const timestamptz: Codec<Date> = scalar("timestamptz", instantFromText, i
|
|
|
381
381
|
/** A value sqlc could not type (`any`, `anyelement`, …): whatever the server printed. */
|
|
382
382
|
export const unknown: Codec<mixed> = {
|
|
383
383
|
sqlType: "unknown",
|
|
384
|
-
decode: (value) => value,
|
|
384
|
+
decode : (value) => value,
|
|
385
385
|
encode: (value) => {
|
|
386
386
|
if (typeof value === "string") {
|
|
387
387
|
return value;
|
|
@@ -396,7 +396,7 @@ export const unknown: Codec<mixed> = {
|
|
|
396
396
|
},
|
|
397
397
|
element: (node) => node,
|
|
398
398
|
literal: (value) => (value === null ? "NULL" : quote(String(value))),
|
|
399
|
-
depth: 0,
|
|
399
|
+
depth : 0,
|
|
400
400
|
};
|
|
401
401
|
|
|
402
402
|
// ---------------------------------------------------------------------------
|
|
@@ -405,7 +405,7 @@ export const unknown: Codec<mixed> = {
|
|
|
405
405
|
/** A codec for a `CREATE TYPE … AS ENUM`, from its labels in declaration order. */
|
|
406
406
|
export function enumeration<T extends string>(
|
|
407
407
|
sqlType: string,
|
|
408
|
-
values: $ReadOnlyArray<T>,
|
|
408
|
+
values : $ReadOnlyArray<T>,
|
|
409
409
|
): Codec<T> {
|
|
410
410
|
const expected = `${sqlType} (${enumName(values)})`;
|
|
411
411
|
return scalar(
|
|
@@ -550,10 +550,10 @@ export function array<T>(element: Codec<T>): Codec<$ReadOnlyArray<T>> {
|
|
|
550
550
|
// An empty array has no dimensions at all, whatever the column says.
|
|
551
551
|
return root.length === 0 ? [] : fromNode(root);
|
|
552
552
|
},
|
|
553
|
-
encode: toLiteral,
|
|
553
|
+
encode : toLiteral,
|
|
554
554
|
element: (node) => (Array.isArray(node) && node.length === 0 ? [] : fromNode(node)),
|
|
555
555
|
literal: toLiteral,
|
|
556
|
-
depth: element.depth + 1,
|
|
556
|
+
depth : element.depth + 1,
|
|
557
557
|
};
|
|
558
558
|
}
|
|
559
559
|
|
|
@@ -563,17 +563,17 @@ export function array<T>(element: Codec<T>): Codec<$ReadOnlyArray<T>> {
|
|
|
563
563
|
* options, where `decode` is the application's own check.
|
|
564
564
|
*/
|
|
565
565
|
export function map<T, U>(
|
|
566
|
-
codec: Codec<T>,
|
|
566
|
+
codec : Codec<T>,
|
|
567
567
|
decode: (value: T) => U,
|
|
568
568
|
encode: (value: U) => T,
|
|
569
569
|
): Codec<U> {
|
|
570
570
|
return {
|
|
571
571
|
sqlType: codec.sqlType,
|
|
572
|
-
decode: (value) => decode(codec.decode(value)),
|
|
573
|
-
encode: (value) => codec.encode(encode(value)),
|
|
572
|
+
decode : (value) => decode(codec.decode(value)),
|
|
573
|
+
encode : (value) => codec.encode(encode(value)),
|
|
574
574
|
element: (node) => decode(codec.element(node)),
|
|
575
575
|
literal: (value) => codec.literal(encode(value)),
|
|
576
|
-
depth: codec.depth,
|
|
576
|
+
depth : codec.depth,
|
|
577
577
|
};
|
|
578
578
|
}
|
|
579
579
|
|
package/sqlite.js
CHANGED
|
@@ -31,8 +31,8 @@ import {
|
|
|
31
31
|
/** How one declared type becomes a Flow value and back. */
|
|
32
32
|
export type Codec<T> = {|
|
|
33
33
|
readonly sqlType: string,
|
|
34
|
-
readonly decode: (value: mixed) => T,
|
|
35
|
-
readonly encode: (value: T) => SqlParam,
|
|
34
|
+
readonly decode : (value: mixed) => T,
|
|
35
|
+
readonly encode : (value: T) => SqlParam,
|
|
36
36
|
|};
|
|
37
37
|
|
|
38
38
|
/** `INTEGER` as a `number`, which throws past 2^53 instead of rounding. */
|
|
@@ -50,8 +50,8 @@ export const integer: Codec<number> = {
|
|
|
50
50
|
/** `INTEGER` as a `bigint`, for `sqliteInteger: "bigint"`. */
|
|
51
51
|
export const integerAsBigint: Codec<bigint> = {
|
|
52
52
|
sqlType: "INTEGER",
|
|
53
|
-
decode: (value) => bigintFrom("INTEGER", value),
|
|
54
|
-
encode: (value) => bigintParam("INTEGER (a bigint)", value),
|
|
53
|
+
decode : (value) => bigintFrom("INTEGER", value),
|
|
54
|
+
encode : (value) => bigintParam("INTEGER (a bigint)", value),
|
|
55
55
|
};
|
|
56
56
|
|
|
57
57
|
/** `REAL`, `DOUBLE`, `FLOAT`, and `NUMERIC`/`DECIMAL`, which SQLite stores as one or an INTEGER. */
|
|
@@ -106,21 +106,21 @@ export const string: Codec<string> = text("TEXT");
|
|
|
106
106
|
/** `BLOB`. */
|
|
107
107
|
export const blob: Codec<Uint8Array> = {
|
|
108
108
|
sqlType: "BLOB",
|
|
109
|
-
decode: (value) => bytesFrom("BLOB", value),
|
|
110
|
-
encode: (value) => bytesParam("BLOB (a Uint8Array)", value),
|
|
109
|
+
decode : (value) => bytesFrom("BLOB", value),
|
|
110
|
+
encode : (value) => bytesParam("BLOB (a Uint8Array)", value),
|
|
111
111
|
};
|
|
112
112
|
|
|
113
113
|
/** `JSON` and `JSONB` (sqlc reads the latter through `json()`), stored as text. */
|
|
114
114
|
export const json: Codec<JsonValue> = {
|
|
115
115
|
sqlType: "JSON",
|
|
116
|
-
decode: (value) => jsonFromText(value),
|
|
117
|
-
encode: (value) => jsonParam(value),
|
|
116
|
+
decode : (value) => jsonFromText(value),
|
|
117
|
+
encode : (value) => jsonParam(value),
|
|
118
118
|
};
|
|
119
119
|
|
|
120
120
|
/** A declared type with no affinity uf can type, or a result sqlc could not. */
|
|
121
121
|
export const unknown: Codec<mixed> = {
|
|
122
122
|
sqlType: "unknown",
|
|
123
|
-
decode: (value) => value,
|
|
123
|
+
decode : (value) => value,
|
|
124
124
|
encode: (value) => {
|
|
125
125
|
if (
|
|
126
126
|
value === null ||
|
|
@@ -141,7 +141,7 @@ export const unknown: Codec<mixed> = {
|
|
|
141
141
|
/** A `CHECK (x IN (…))`-style enum sqlc was told about through an override. */
|
|
142
142
|
export function enumeration<T extends string>(
|
|
143
143
|
sqlType: string,
|
|
144
|
-
values: $ReadOnlyArray<T>,
|
|
144
|
+
values : $ReadOnlyArray<T>,
|
|
145
145
|
): Codec<T> {
|
|
146
146
|
const expected = `${sqlType} (${enumName(values)})`;
|
|
147
147
|
return {
|
|
@@ -156,14 +156,14 @@ export function enumeration<T extends string>(
|
|
|
156
156
|
* value back to what `codec` writes.
|
|
157
157
|
*/
|
|
158
158
|
export function map<T, U>(
|
|
159
|
-
codec: Codec<T>,
|
|
159
|
+
codec : Codec<T>,
|
|
160
160
|
decode: (value: T) => U,
|
|
161
161
|
encode: (value: U) => T,
|
|
162
162
|
): Codec<U> {
|
|
163
163
|
return {
|
|
164
164
|
sqlType: codec.sqlType,
|
|
165
|
-
decode: (value) => decode(codec.decode(value)),
|
|
166
|
-
encode: (value) => codec.encode(encode(value)),
|
|
165
|
+
decode : (value) => decode(codec.decode(value)),
|
|
166
|
+
encode : (value) => codec.encode(encode(value)),
|
|
167
167
|
};
|
|
168
168
|
}
|
|
169
169
|
|