leoric 2.8.7 → 2.8.8
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/History.md +12 -0
- package/package.json +1 -1
- package/src/bone.js +2 -2
- package/src/decorators.js +9 -2
- package/src/decorators.js.map +1 -1
- package/src/decorators.ts +9 -2
- package/src/drivers/abstract/spellbook.js +1 -0
- package/src/drivers/postgres/index.js +7 -6
- package/src/spell.js +5 -2
package/History.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
2.8.8 / 2022-10-25
|
|
2
|
+
==================
|
|
3
|
+
|
|
4
|
+
## What's Changed
|
|
5
|
+
* fix: join query with select columns should include order columns by @cyjake in https://github.com/cyjake/leoric/pull/360
|
|
6
|
+
* docs: support switchable dark theme, at web app level by @cyjake in https://github.com/cyjake/leoric/pull/359
|
|
7
|
+
* fix: @Column() should not tamper parent attributes directly by @cyjake in https://github.com/cyjake/leoric/pull/362
|
|
8
|
+
* fix: bone.update({ deletedAt: null }) and likewise methods should work by @cyjake in https://github.com/cyjake/leoric/pull/363
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
**Full Changelog**: https://github.com/cyjake/leoric/compare/v2.8.7...v2.8.8
|
|
12
|
+
|
|
1
13
|
2.8.7 / 2022-10-11
|
|
2
14
|
==================
|
|
3
15
|
|
package/package.json
CHANGED
package/src/bone.js
CHANGED
|
@@ -668,7 +668,7 @@ class Bone {
|
|
|
668
668
|
* @public
|
|
669
669
|
* @param {Object} values
|
|
670
670
|
* @param {Object?} options
|
|
671
|
-
* @returns {number} affected rows
|
|
671
|
+
* @returns {Promise<number>} affected rows
|
|
672
672
|
* @memberof Bone
|
|
673
673
|
*/
|
|
674
674
|
async update(values, options = {}) {
|
|
@@ -697,7 +697,7 @@ class Bone {
|
|
|
697
697
|
/**
|
|
698
698
|
* Persist changes on current instance back to database with `UPDATE`.
|
|
699
699
|
* @private
|
|
700
|
-
* @return {number}
|
|
700
|
+
* @return {Promise<number>}
|
|
701
701
|
*/
|
|
702
702
|
async _update(values, options = {}) {
|
|
703
703
|
const Model = this.constructor;
|
package/src/decorators.js
CHANGED
|
@@ -59,9 +59,16 @@ function Column(options = {}) {
|
|
|
59
59
|
throw new Error(`unknown column options ${options}`);
|
|
60
60
|
// target refers to model prototype, an internal instance of `Bone {}`
|
|
61
61
|
const model = target.constructor;
|
|
62
|
-
|
|
62
|
+
if (!Object.hasOwnProperty('attributes') || !model.attributes) {
|
|
63
|
+
Object.defineProperty(model, 'attributes', {
|
|
64
|
+
value: { ...model.attributes },
|
|
65
|
+
writable: false,
|
|
66
|
+
enumerable: false,
|
|
67
|
+
configurable: true,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
63
70
|
const { name: columnName, ...restOptions } = options;
|
|
64
|
-
attributes[propertyKey] = { ...restOptions, columnName };
|
|
71
|
+
model.attributes[propertyKey] = { ...restOptions, columnName };
|
|
65
72
|
};
|
|
66
73
|
}
|
|
67
74
|
exports.Column = Column;
|
package/src/decorators.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["decorators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4BAA0B;AAG1B,2DAA8D;AAC9D,2CAAqD;AAWrD,SAAS,QAAQ,CAAC,MAAM;IACtB,MAAM,EACJ,MAAM,EAAE,OAAO,EACf,IAAI,EACJ,MAAM,EACN,OAAO,GACR,GAAG,oBAAS,CAAC;IAEd,QAAQ,MAAM,EAAE;QACd,KAAK,MAAM;YACT,OAAO,MAAM,CAAC;QAChB,KAAK,MAAM;YACT,OAAO,OAAO,CAAC;QACjB,KAAK,IAAI;YACP,OAAO,IAAI,CAAC;QACd,KAAK,MAAM;YACT,OAAO,MAAM,CAAC;QAChB,KAAK,OAAO;YACV,OAAO,OAAO,CAAC;QACjB;YACE,MAAM,IAAI,KAAK,CAAC,2BAA2B,MAAM,EAAE,CAAC,CAAC;KACxD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IAAI,MAAM,CAAC,IAAI,KAAK,UAAU;gBAAE,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC;SACjE;QACD,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE;YAChC,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC;YACxC,CAAC,WAAW,CAAC,EAAE,OAAO;SACvB,EAAE,KAAK,CAAC,CAAC;IACZ,CAAC,CAAA;AACH,CAAC;AAZD,8BAYC"}
|
package/src/decorators.ts
CHANGED
|
@@ -54,9 +54,16 @@ export function Column(options: ColumnOption | DATA_TYPE<DataType> | DataType =
|
|
|
54
54
|
|
|
55
55
|
// target refers to model prototype, an internal instance of `Bone {}`
|
|
56
56
|
const model = target.constructor as any;
|
|
57
|
-
|
|
57
|
+
if (!Object.hasOwnProperty('attributes') || !model.attributes) {
|
|
58
|
+
Object.defineProperty(model, 'attributes', {
|
|
59
|
+
value: { ...model.attributes },
|
|
60
|
+
writable: false,
|
|
61
|
+
enumerable: false,
|
|
62
|
+
configurable: true,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
58
65
|
const { name: columnName, ...restOptions } = options;
|
|
59
|
-
attributes[propertyKey] = { ...restOptions, columnName };
|
|
66
|
+
model.attributes[propertyKey] = { ...restOptions, columnName };
|
|
60
67
|
};
|
|
61
68
|
}
|
|
62
69
|
|
|
@@ -54,6 +54,7 @@ function createSubspell(spell) {
|
|
|
54
54
|
const { type, qualifiers = [], value } = token;
|
|
55
55
|
if (type == 'id' && qualifiers[0] == baseName) {
|
|
56
56
|
subspell.orders.push([{ type, value }, direction]);
|
|
57
|
+
if (subspell.columns.length > 0) subspell.columns.push({ type, value });
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
|
|
@@ -109,15 +109,16 @@ class PostgresDriver extends AbstractDriver {
|
|
|
109
109
|
tables = [].concat(tables);
|
|
110
110
|
const text = heresql(`
|
|
111
111
|
SELECT columns.*,
|
|
112
|
-
|
|
112
|
+
constraints.constraint_type
|
|
113
113
|
FROM information_schema.columns AS columns
|
|
114
|
-
|
|
114
|
+
LEFT JOIN information_schema.key_column_usage AS usage
|
|
115
115
|
ON columns.table_catalog = usage.table_catalog
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
AND columns.table_name = usage.table_name
|
|
117
|
+
AND columns.column_name = usage.column_name
|
|
118
|
+
LEFT JOIN information_schema.table_constraints AS constraints
|
|
119
119
|
ON usage.constraint_name = constraints.constraint_name
|
|
120
|
-
|
|
120
|
+
WHERE columns.table_catalog = $1 AND columns.table_name = ANY($2)
|
|
121
|
+
ORDER BY columns.ordinal_position ASC
|
|
121
122
|
`);
|
|
122
123
|
|
|
123
124
|
const { pool } = this;
|
package/src/spell.js
CHANGED
|
@@ -263,13 +263,16 @@ function joinAssociation(spell, BaseModel, baseName, refName, opts = {}) {
|
|
|
263
263
|
* If Model supports soft delete, and deletedAt isn't specified in whereConditions yet, and the table isn't a subquery, append a default where({ deletedAt: null }).
|
|
264
264
|
*/
|
|
265
265
|
function scopeDeletedAt(spell) {
|
|
266
|
-
const { table, whereConditions, Model } = spell;
|
|
266
|
+
const { table, sets, whereConditions, Model } = spell;
|
|
267
267
|
|
|
268
268
|
const { deletedAt } = Model.timestamps;
|
|
269
269
|
|
|
270
270
|
// from subquery
|
|
271
271
|
if (table.type !== 'id') return;
|
|
272
272
|
|
|
273
|
+
// UPDATE users SET deleted_at = NULL WHERE id = 42;
|
|
274
|
+
if (sets && sets[deletedAt] === null) return;
|
|
275
|
+
|
|
273
276
|
// deletedAt already specified
|
|
274
277
|
for (const condition of whereConditions) {
|
|
275
278
|
let found = false;
|
|
@@ -963,7 +966,7 @@ for (const aggregator in AGGREGATOR_MAP) {
|
|
|
963
966
|
value: function Spell_aggregator(name = '*') {
|
|
964
967
|
if (name instanceof Raw) {
|
|
965
968
|
this.$select(Raw.build(`${func.toUpperCase()}(${name}) AS ${aggregator}`));
|
|
966
|
-
return this
|
|
969
|
+
return this;
|
|
967
970
|
}
|
|
968
971
|
if (name !== '*' && parseExpr(name).type !== 'id') {
|
|
969
972
|
throw new Error(`unexpected operand ${name} for ${func.toUpperCase()}()`);
|