@travetto/model-sql 3.1.6 → 3.1.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/package.json +2 -2
- package/src/dialect/base.ts +23 -8
- package/src/internal/util.ts +6 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-sql",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.8",
|
|
4
4
|
"description": "SQL backing for the travetto model module, with real-time modeling support for SQL schemas.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sql",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@travetto/config": "^3.1.2",
|
|
31
31
|
"@travetto/context": "^3.1.1",
|
|
32
32
|
"@travetto/model": "^3.1.8",
|
|
33
|
-
"@travetto/model-query": "^3.1.
|
|
33
|
+
"@travetto/model-query": "^3.1.8"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"@travetto/command": "^3.1.2",
|
package/src/dialect/base.ts
CHANGED
|
@@ -478,6 +478,19 @@ export abstract class SQLDialect implements DialectState {
|
|
|
478
478
|
}
|
|
479
479
|
break;
|
|
480
480
|
}
|
|
481
|
+
case '$empty': {
|
|
482
|
+
const valueTable = this.parentTable(sStack);
|
|
483
|
+
const alias = `_all_${sStack.length}`;
|
|
484
|
+
const pPath = this.ident(this.parentPathField.name);
|
|
485
|
+
const rpPath = this.resolveName([...sStack, field, this.parentPathField]);
|
|
486
|
+
|
|
487
|
+
items.push(`0 ${v ? '=' : '<>'} (
|
|
488
|
+
SELECT COUNT(${alias}.${this.ident(field.name)})
|
|
489
|
+
FROM ${valueTable} ${alias}
|
|
490
|
+
WHERE ${alias}.${pPath} = ${rpPath}
|
|
491
|
+
)`);
|
|
492
|
+
break;
|
|
493
|
+
}
|
|
481
494
|
case '$exists': items.push(`${sPath} ${v ? SQL_OPS.$isNot : SQL_OPS.$is} NULL`); break;
|
|
482
495
|
case '$ne': case '$eq': {
|
|
483
496
|
if (v === null || v === undefined) {
|
|
@@ -648,17 +661,19 @@ ${this.getLimitSQL(cls, query)}`;
|
|
|
648
661
|
}
|
|
649
662
|
}
|
|
650
663
|
|
|
664
|
+
const fieldSql = fields
|
|
665
|
+
.map(f => {
|
|
666
|
+
const def = this.getColumnDefinition(f) || '';
|
|
667
|
+
return f.name === this.idField.name && !parent ?
|
|
668
|
+
def.replace('DEFAULT NULL', 'NOT NULL') : def;
|
|
669
|
+
})
|
|
670
|
+
.filter(x => !!x.trim())
|
|
671
|
+
.join(',\n ');
|
|
672
|
+
|
|
651
673
|
/* eslint-disable @typescript-eslint/indent */
|
|
652
674
|
const out = `
|
|
653
675
|
CREATE TABLE IF NOT EXISTS ${this.table(stack)} (
|
|
654
|
-
${
|
|
655
|
-
.map(f => {
|
|
656
|
-
const def = this.getColumnDefinition(f) || '';
|
|
657
|
-
return f.name === this.idField.name && !parent ?
|
|
658
|
-
def.replace('DEFAULT NULL', 'NOT NULL') : def;
|
|
659
|
-
})
|
|
660
|
-
.filter(x => !!x.trim())
|
|
661
|
-
.join(',\n ')},
|
|
676
|
+
${fieldSql}${fieldSql.length ? ',' : ''}
|
|
662
677
|
${this.getColumnDefinition(this.pathField)} UNIQUE,
|
|
663
678
|
${!parent ?
|
|
664
679
|
`PRIMARY KEY (${this.ident(this.idField)})` :
|
package/src/internal/util.ts
CHANGED
|
@@ -198,12 +198,17 @@ export class SQLUtil {
|
|
|
198
198
|
pathObj.push(val);
|
|
199
199
|
config.path[config.path.length - 1] = { ...top, index: i++ };
|
|
200
200
|
handler.onSub({ ...config, value: val });
|
|
201
|
+
if (!field.array) {
|
|
202
|
+
config.descend();
|
|
203
|
+
}
|
|
201
204
|
} finally {
|
|
202
205
|
pathObj.pop();
|
|
203
206
|
}
|
|
204
207
|
i += 1;
|
|
205
208
|
}
|
|
206
|
-
|
|
209
|
+
if (field.array) {
|
|
210
|
+
config.descend();
|
|
211
|
+
}
|
|
207
212
|
}
|
|
208
213
|
},
|
|
209
214
|
onSimple: (config) => {
|