dobo 2.5.0 → 2.5.1
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/factory/driver.js +17 -6
- package/lib/factory/model/_util.js +15 -5
- package/package.json +1 -1
- package/wiki/CHANGES.md +2 -0
package/lib/factory/driver.js
CHANGED
|
@@ -37,6 +37,7 @@ async function driverFactory () {
|
|
|
37
37
|
uniqueIndex: false,
|
|
38
38
|
nullableField: true
|
|
39
39
|
}
|
|
40
|
+
this.useUtc = false
|
|
40
41
|
this.maxChunkSize = 500
|
|
41
42
|
this.memory = false
|
|
42
43
|
this.options = options
|
|
@@ -81,18 +82,28 @@ async function driverFactory () {
|
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
sanitizeRecord (model, record = {}) {
|
|
85
|
+
const { dayjs } = this.app.lib
|
|
86
|
+
const { isString } = this.app.lib._
|
|
84
87
|
const item = { ...record }
|
|
85
88
|
if (has(item, this.idField.name) && this.idField.name !== 'id') {
|
|
86
89
|
item.id = item[this.idField.name]
|
|
87
90
|
delete item[this.idField.name]
|
|
88
91
|
}
|
|
89
92
|
for (const prop of model.properties) {
|
|
90
|
-
if (isSet(item[prop.name])
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
if (isSet(item[prop.name])) {
|
|
94
|
+
if (!this.support.propType[prop.type]) {
|
|
95
|
+
try {
|
|
96
|
+
if (prop.type === 'datetime') {
|
|
97
|
+
const dt = this.useUtc ? dayjs.utc(item[prop.name]) : dayjs(item[prop.name])
|
|
98
|
+
item[prop.name] = dt.toDate()
|
|
99
|
+
} else if (['object', 'array'].includes(prop.type)) item[prop.name] = JSON.parse(item[prop.name])
|
|
100
|
+
} catch (err) {
|
|
101
|
+
item[prop.name] = null
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (prop.type === 'datetime' && isString(item[prop.name])) {
|
|
105
|
+
const dt = this.useUtc ? dayjs.utc(item[prop.name]) : dayjs(item[prop.name])
|
|
106
|
+
item[prop.name] = dt.toDate()
|
|
96
107
|
}
|
|
97
108
|
}
|
|
98
109
|
}
|
|
@@ -253,26 +253,36 @@ function sanitizeQuery (query = {}, parent) {
|
|
|
253
253
|
const { dayjs } = this.app.lib
|
|
254
254
|
const obj = cloneDeep(query)
|
|
255
255
|
const keys = Object.keys(obj)
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const prop = find(this.properties, { name: key.startsWith('$') ? p : key })
|
|
256
|
+
|
|
257
|
+
const sanitizeField = (prop, val) => {
|
|
259
258
|
if (!prop) return val
|
|
260
|
-
if (['datetime'
|
|
259
|
+
if (['datetime'].includes(prop.type)) {
|
|
261
260
|
const dt = dayjs(val)
|
|
262
261
|
return dt.isValid() ? dt.toDate() : val
|
|
263
262
|
} else if (['smallint', 'integer'].includes(prop.type)) return parseInt(val) || val
|
|
264
263
|
else if (['float', 'double'].includes(prop.type)) return parseFloat(val) || val
|
|
265
264
|
else if (['boolean'].includes(prop.type)) return !!val
|
|
265
|
+
else if (['string', 'text'].includes(prop.type)) return val + ''
|
|
266
266
|
return val
|
|
267
267
|
}
|
|
268
|
+
|
|
269
|
+
const sanitizeChild = (key, val, p) => {
|
|
270
|
+
if (!isSet(val)) return val
|
|
271
|
+
const prop = find(this.properties, { name: key.startsWith('$') ? p : key })
|
|
272
|
+
if (!prop) return val
|
|
273
|
+
return sanitizeField(prop, val)
|
|
274
|
+
}
|
|
275
|
+
|
|
268
276
|
keys.forEach(k => {
|
|
269
277
|
const v = obj[k]
|
|
278
|
+
const prop = find(this.properties, { name: k })
|
|
270
279
|
if (isPlainObject(v)) obj[k] = sanitizeQuery.call(this, v, k)
|
|
271
280
|
else if (isArray(v)) {
|
|
272
281
|
v.forEach((i, idx) => {
|
|
273
282
|
if (isPlainObject(i)) obj[k][idx] = sanitizeQuery.call(this, i, k)
|
|
283
|
+
else obj[k][idx] = sanitizeField(prop, i)
|
|
274
284
|
})
|
|
275
|
-
} else obj[k] =
|
|
285
|
+
} else obj[k] = sanitizeChild(k, v, parent)
|
|
276
286
|
})
|
|
277
287
|
return obj
|
|
278
288
|
}
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
- [2.5.0] Add feature to push custom ```options._data```. If provided, this will be used instead of auto generated one.
|
|
6
6
|
- [2.5.0] Remove ```silent``` in ```options``` object
|
|
7
|
+
- [2.5.1] Driver now support ```this.useUtc``` for database that store values in UTC string
|
|
8
|
+
- [2.5.1] Bug fix on ```driver.sanitizeRecord()```
|
|
7
9
|
|
|
8
10
|
## 2026-01-29
|
|
9
11
|
|