@stonyx/orm 0.3.2-alpha.113 → 0.3.2-alpha.114
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.
|
@@ -23,7 +23,12 @@
|
|
|
23
23
|
export function convertRow(row, columns, rule) {
|
|
24
24
|
const converted = {};
|
|
25
25
|
for (const [col, value] of Object.entries(row)) {
|
|
26
|
-
|
|
26
|
+
// `Object.hasOwn`, not `columns[col]`: a column named `toString` or
|
|
27
|
+
// `constructor` would otherwise reach the rule with a function as its
|
|
28
|
+
// "declared type". Inert for the shipped Postgres rule (strict equality
|
|
29
|
+
// against 'JSONB'), but `ColumnRule` is the extension point other drivers
|
|
30
|
+
// write against, and the obvious `if (columnType)` rule would invert.
|
|
31
|
+
converted[col] = rule(value, Object.hasOwn(columns, col) ? columns[col] : undefined);
|
|
27
32
|
}
|
|
28
33
|
return converted;
|
|
29
34
|
}
|
|
@@ -18,7 +18,16 @@ import type { ColumnRule } from '../column-conversion.js';
|
|
|
18
18
|
* `schema.columns`.
|
|
19
19
|
*
|
|
20
20
|
* The `'JSONB'` sentinel is the exact literal emitted by
|
|
21
|
-
* `src/postgres/type-map.ts
|
|
22
|
-
*
|
|
21
|
+
* `src/postgres/type-map.ts`, the only module that produces the values in
|
|
22
|
+
* `schema.columns`. The two producing functions are `getPgType` and
|
|
23
|
+
* `getVectorType` (`src/postgres/schema-introspector.ts` writes `columns[key]`
|
|
24
|
+
* at exactly three sites, all routed through those two); `mysqlTypeToPg` is not
|
|
25
|
+
* exported and is reachable only from inside `getPgType`.
|
|
26
|
+
*
|
|
27
|
+
* One documented gap: `getPgType` returns a consumer transform's declared
|
|
28
|
+
* `pgType` verbatim, so a consumer writing `pgType: 'jsonb'` puts a value in
|
|
29
|
+
* `schema.columns` that type-map never authored and this exact-match sentinel
|
|
30
|
+
* misses. It misses identically on the create path, pre-fix and post-fix --
|
|
31
|
+
* pre-existing and symmetric, not introduced here.
|
|
23
32
|
*/
|
|
24
33
|
export declare const postgresJsonRule: ColumnRule;
|
|
@@ -17,8 +17,17 @@
|
|
|
17
17
|
* `schema.columns`.
|
|
18
18
|
*
|
|
19
19
|
* The `'JSONB'` sentinel is the exact literal emitted by
|
|
20
|
-
* `src/postgres/type-map.ts
|
|
21
|
-
*
|
|
20
|
+
* `src/postgres/type-map.ts`, the only module that produces the values in
|
|
21
|
+
* `schema.columns`. The two producing functions are `getPgType` and
|
|
22
|
+
* `getVectorType` (`src/postgres/schema-introspector.ts` writes `columns[key]`
|
|
23
|
+
* at exactly three sites, all routed through those two); `mysqlTypeToPg` is not
|
|
24
|
+
* exported and is reachable only from inside `getPgType`.
|
|
25
|
+
*
|
|
26
|
+
* One documented gap: `getPgType` returns a consumer transform's declared
|
|
27
|
+
* `pgType` verbatim, so a consumer writing `pgType: 'jsonb'` puts a value in
|
|
28
|
+
* `schema.columns` that type-map never authored and this exact-match sentinel
|
|
29
|
+
* misses. It misses identically on the create path, pre-fix and post-fix --
|
|
30
|
+
* pre-existing and symmetric, not introduced here.
|
|
22
31
|
*/
|
|
23
32
|
export const postgresJsonRule = (value, columnType) => columnType === 'JSONB' && typeof value !== 'string'
|
|
24
33
|
? JSON.stringify(value)
|
package/package.json
CHANGED
package/src/column-conversion.ts
CHANGED
|
@@ -41,7 +41,12 @@ export function convertRow(
|
|
|
41
41
|
const converted: Record<string, unknown> = {};
|
|
42
42
|
|
|
43
43
|
for (const [col, value] of Object.entries(row)) {
|
|
44
|
-
|
|
44
|
+
// `Object.hasOwn`, not `columns[col]`: a column named `toString` or
|
|
45
|
+
// `constructor` would otherwise reach the rule with a function as its
|
|
46
|
+
// "declared type". Inert for the shipped Postgres rule (strict equality
|
|
47
|
+
// against 'JSONB'), but `ColumnRule` is the extension point other drivers
|
|
48
|
+
// write against, and the obvious `if (columnType)` rule would invert.
|
|
49
|
+
converted[col] = rule(value, Object.hasOwn(columns, col) ? columns[col] : undefined);
|
|
45
50
|
}
|
|
46
51
|
|
|
47
52
|
return converted;
|
|
@@ -19,8 +19,17 @@ import type { ColumnRule } from '../column-conversion.js';
|
|
|
19
19
|
* `schema.columns`.
|
|
20
20
|
*
|
|
21
21
|
* The `'JSONB'` sentinel is the exact literal emitted by
|
|
22
|
-
* `src/postgres/type-map.ts
|
|
23
|
-
*
|
|
22
|
+
* `src/postgres/type-map.ts`, the only module that produces the values in
|
|
23
|
+
* `schema.columns`. The two producing functions are `getPgType` and
|
|
24
|
+
* `getVectorType` (`src/postgres/schema-introspector.ts` writes `columns[key]`
|
|
25
|
+
* at exactly three sites, all routed through those two); `mysqlTypeToPg` is not
|
|
26
|
+
* exported and is reachable only from inside `getPgType`.
|
|
27
|
+
*
|
|
28
|
+
* One documented gap: `getPgType` returns a consumer transform's declared
|
|
29
|
+
* `pgType` verbatim, so a consumer writing `pgType: 'jsonb'` puts a value in
|
|
30
|
+
* `schema.columns` that type-map never authored and this exact-match sentinel
|
|
31
|
+
* misses. It misses identically on the create path, pre-fix and post-fix --
|
|
32
|
+
* pre-existing and symmetric, not introduced here.
|
|
24
33
|
*/
|
|
25
34
|
export const postgresJsonRule: ColumnRule = (value, columnType) =>
|
|
26
35
|
columnType === 'JSONB' && typeof value !== 'string'
|