mythix-orm-sql-base 1.4.2 → 1.4.3
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/lib/sql-connection-base.js +31 -12
- package/package.json +1 -1
|
@@ -126,12 +126,29 @@ class SQLConnectionBase extends ConnectionBase {
|
|
|
126
126
|
if (!result)
|
|
127
127
|
return {};
|
|
128
128
|
|
|
129
|
-
let
|
|
129
|
+
let {
|
|
130
|
+
rows,
|
|
131
|
+
columns,
|
|
132
|
+
} = result;
|
|
130
133
|
if (Nife.isEmpty(rows))
|
|
131
134
|
return {};
|
|
132
135
|
|
|
136
|
+
const generateIDForModelFields = (data) => {
|
|
137
|
+
let keys = Object.keys(data || {}).sort();
|
|
138
|
+
let parts = [];
|
|
139
|
+
|
|
140
|
+
for (let i = 0, il = keys.length; i < il; i++) {
|
|
141
|
+
let key = keys[i];
|
|
142
|
+
let value = data[key];
|
|
143
|
+
|
|
144
|
+
parts.push(`${key}:${value}`);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return (!parts.length) ? null : parts.join(',');
|
|
148
|
+
};
|
|
149
|
+
|
|
133
150
|
let context = queryEngine._getRawQueryContext();
|
|
134
|
-
let fields = this.findAllFieldsFromFieldProjectionMap(
|
|
151
|
+
let fields = this.findAllFieldsFromFieldProjectionMap(columns);
|
|
135
152
|
let rootModelName = context.rootModelName;
|
|
136
153
|
let modelData = {};
|
|
137
154
|
let alreadyVisited = {};
|
|
@@ -200,20 +217,22 @@ class SQLConnectionBase extends ConnectionBase {
|
|
|
200
217
|
if (!models)
|
|
201
218
|
models = modelData[modelName] = [];
|
|
202
219
|
|
|
203
|
-
|
|
204
|
-
|
|
220
|
+
let id = model[pkFieldName];
|
|
221
|
+
if (id == null)
|
|
222
|
+
id = generateIDForModelFields(model);
|
|
205
223
|
|
|
206
|
-
|
|
207
|
-
|
|
224
|
+
if (id != null) {
|
|
225
|
+
let idKey = `${modelName}:${pkFieldName}:${id}`;
|
|
208
226
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
227
|
+
if (alreadyVisited[idKey] != null) {
|
|
228
|
+
index = alreadyVisited[idKey];
|
|
229
|
+
model = models[index];
|
|
230
|
+
} else {
|
|
231
|
+
index = alreadyVisited[idKey] = models.length;
|
|
232
|
+
models.push(model);
|
|
215
233
|
}
|
|
216
234
|
} else {
|
|
235
|
+
index = models.length;
|
|
217
236
|
models.push(model);
|
|
218
237
|
continue;
|
|
219
238
|
}
|