metal-orm 1.0.95 → 1.0.97
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/dist/index.cjs +11 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +11 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/orm/hydration.ts +9 -1
- package/src/query-builder/update-query-state.ts +10 -2
package/package.json
CHANGED
package/src/orm/hydration.ts
CHANGED
|
@@ -45,9 +45,17 @@ export const hydrateRows = (rows: Record<string, unknown>[], plan?: HydrationPla
|
|
|
45
45
|
return seen;
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
+
const hasRelations = plan.relations.length > 0;
|
|
49
|
+
|
|
48
50
|
for (const row of rows) {
|
|
49
51
|
const rootId = row[plan.rootPrimaryKey];
|
|
50
|
-
|
|
52
|
+
|
|
53
|
+
if (rootId === undefined || rootId === null) {
|
|
54
|
+
if (!hasRelations) {
|
|
55
|
+
rootMap.set(Symbol(), createBaseRow(row, plan));
|
|
56
|
+
}
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
51
59
|
|
|
52
60
|
const parent = getOrCreateParent(row);
|
|
53
61
|
if (!parent) continue;
|
|
@@ -14,10 +14,16 @@ import {
|
|
|
14
14
|
import { JoinNode } from '../core/ast/join.js';
|
|
15
15
|
import { createTableNode } from '../core/ast/builders.js';
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Allowed literal type names - single source of truth for both type and error messages
|
|
19
|
+
*/
|
|
20
|
+
const LITERAL_VALUE_TYPES = ['string', 'number', 'boolean', 'Date', 'null'] as const;
|
|
21
|
+
|
|
17
22
|
/**
|
|
18
23
|
* Literal values that can be used in UPDATE statements
|
|
24
|
+
* Derived from LITERAL_VALUE_TYPES to maintain single source of truth
|
|
19
25
|
*/
|
|
20
|
-
type LiteralValue =
|
|
26
|
+
type LiteralValue = typeof LITERAL_VALUE_TYPES[number] | null;
|
|
21
27
|
|
|
22
28
|
/**
|
|
23
29
|
* Values allowed in UPDATE SET clauses
|
|
@@ -31,6 +37,7 @@ type UpdateValue = OperandNode | LiteralValue;
|
|
|
31
37
|
*/
|
|
32
38
|
const isUpdateValue = (value: unknown): value is UpdateValue => {
|
|
33
39
|
if (value === null) return true;
|
|
40
|
+
if (value instanceof Date) return true;
|
|
34
41
|
switch (typeof value) {
|
|
35
42
|
case 'string':
|
|
36
43
|
case 'number':
|
|
@@ -80,8 +87,9 @@ export class UpdateQueryState {
|
|
|
80
87
|
withSet(values: Record<string, unknown>): UpdateQueryState {
|
|
81
88
|
const assignments: UpdateAssignmentNode[] = Object.entries(values).map(([column, rawValue]) => {
|
|
82
89
|
if (!isUpdateValue(rawValue)) {
|
|
90
|
+
const allowedTypes = [...LITERAL_VALUE_TYPES, 'OperandNode'];
|
|
83
91
|
throw new Error(
|
|
84
|
-
`Invalid update value for column "${column}": only
|
|
92
|
+
`Invalid update value for column "${column}": only ${allowedTypes.join(', ')} are allowed`
|
|
85
93
|
);
|
|
86
94
|
}
|
|
87
95
|
|