@travetto/model-sql 2.2.0 → 2.2.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/package.json +6 -6
- package/src/dialect/base.ts +9 -11
- package/src/internal/util.ts +1 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-sql",
|
|
3
3
|
"displayName": "SQL Model Service",
|
|
4
|
-
"version": "2.2.
|
|
4
|
+
"version": "2.2.1",
|
|
5
5
|
"description": "SQL backing for the travetto model module, with real-time modeling support for SQL schemas.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"sql",
|
|
@@ -28,13 +28,13 @@
|
|
|
28
28
|
"directory": "module/model-sql"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@travetto/config": "^2.2.
|
|
32
|
-
"@travetto/context": "^2.2.
|
|
33
|
-
"@travetto/model": "^2.2.
|
|
34
|
-
"@travetto/model-query": "2.2.
|
|
31
|
+
"@travetto/config": "^2.2.1",
|
|
32
|
+
"@travetto/context": "^2.2.1",
|
|
33
|
+
"@travetto/model": "^2.2.1",
|
|
34
|
+
"@travetto/model-query": "2.2.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@travetto/app": "^2.2.
|
|
37
|
+
"@travetto/app": "^2.2.1"
|
|
38
38
|
},
|
|
39
39
|
"optionalPeerDependencies": {
|
|
40
40
|
"@types/mysql": "^2.15.21",
|
package/src/dialect/base.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SchemaRegistry, FieldConfig, Schema } from '@travetto/schema';
|
|
2
2
|
import { Class, Util, AppError } from '@travetto/base';
|
|
3
|
-
import { SelectClause, Query, SortClause, WhereClause } from '@travetto/model-query';
|
|
3
|
+
import { SelectClause, Query, SortClause, WhereClause, RetainFields } from '@travetto/model-query';
|
|
4
4
|
import { BulkResponse, IndexConfig } from '@travetto/model';
|
|
5
5
|
import { PointImpl } from '@travetto/model-query/src/internal/model/point';
|
|
6
6
|
import { ModelType } from '@travetto/model/src/types/model';
|
|
@@ -30,8 +30,6 @@ class Total {
|
|
|
30
30
|
function makeField(name: string, type: Class, required: boolean, extra: Partial<FieldConfig>): FieldConfig {
|
|
31
31
|
return {
|
|
32
32
|
name,
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
34
|
-
owner: null as unknown as Class,
|
|
35
33
|
type,
|
|
36
34
|
array: false,
|
|
37
35
|
...(required ? { required: { active: true } } : {}),
|
|
@@ -410,8 +408,7 @@ export abstract class SQLDialect implements DialectState {
|
|
|
410
408
|
const { foreignMap, localMap } = SQLUtil.getFieldsByLocation(stack);
|
|
411
409
|
const SQL_OPS = this.SQL_OPS;
|
|
412
410
|
|
|
413
|
-
|
|
414
|
-
for (const key of Object.keys(o) as ((keyof (typeof o)))[]) {
|
|
411
|
+
for (const key of Object.keys(o)) {
|
|
415
412
|
const top = o[key];
|
|
416
413
|
const field = localMap[key] ?? foreignMap[key];
|
|
417
414
|
if (!field) {
|
|
@@ -493,7 +490,7 @@ export abstract class SQLDialect implements DialectState {
|
|
|
493
490
|
}
|
|
494
491
|
case '$lt': case '$gt': case '$gte': case '$lte': {
|
|
495
492
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
496
|
-
const subItems =
|
|
493
|
+
const subItems = Object.keys(top as typeof SQL_OPS)
|
|
497
494
|
.map(ssk => `${sPath} ${SQL_OPS[ssk]} ${resolve(top[ssk])}`);
|
|
498
495
|
items.push(subItems.length > 1 ? `(${subItems.join(` ${SQL_OPS.$and} `)})` : subItems[0]);
|
|
499
496
|
break;
|
|
@@ -713,8 +710,7 @@ CREATE TABLE IF NOT EXISTS ${this.table(stack)} (
|
|
|
713
710
|
getCreateIndexSQL<T extends ModelType>(cls: Class<T>, idx: IndexConfig<T>): string {
|
|
714
711
|
const table = this.namespace(SQLUtil.classToStack(cls));
|
|
715
712
|
const fields: [string, boolean][] = idx.fields.map(x => {
|
|
716
|
-
|
|
717
|
-
const key = Object.keys(x)[0] as keyof typeof x;
|
|
713
|
+
const key = Object.keys(x)[0];
|
|
718
714
|
const val = x[key];
|
|
719
715
|
if (Util.isPlainObject(val)) {
|
|
720
716
|
throw new Error('Unable to supported nested fields for indices');
|
|
@@ -912,13 +908,15 @@ ${this.getWhereSQL(cls, where)}`;
|
|
|
912
908
|
const top = stack[stack.length - 1];
|
|
913
909
|
const ids = Object.keys(top);
|
|
914
910
|
const selectTop = selectStack[selectStack.length - 1];
|
|
915
|
-
// @
|
|
916
|
-
const
|
|
911
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
912
|
+
const fieldKey = config.name as keyof RetainFields<T>;
|
|
913
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
914
|
+
const subSelectTop: SelectClause<T> | undefined = selectTop?.[fieldKey] as SelectClause<T> | undefined;
|
|
917
915
|
|
|
918
916
|
// See if a selection exists at all
|
|
919
917
|
const sel: FieldConfig[] = subSelectTop ? fields
|
|
920
918
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
921
|
-
.filter(f => subSelectTop[f.name as
|
|
919
|
+
.filter(f => typeof subSelectTop === 'object' && subSelectTop[f.name as typeof fieldKey] === 1)
|
|
922
920
|
: [];
|
|
923
921
|
|
|
924
922
|
if (sel.length) {
|
package/src/internal/util.ts
CHANGED
|
@@ -46,8 +46,7 @@ export class SQLUtil {
|
|
|
46
46
|
if (Array.isArray(o)) {
|
|
47
47
|
return o.filter(x => x !== null && x !== undefined).map(x => this.cleanResults(dct, x));
|
|
48
48
|
} else if (!Util.isSimple(o)) {
|
|
49
|
-
|
|
50
|
-
for (const k of Object.keys(o) as (keyof T)[]) {
|
|
49
|
+
for (const k of Object.keys(o)) {
|
|
51
50
|
if (o[k] === null || o[k] === undefined || k === dct.parentPathField.name || k === dct.pathField.name || k === dct.idxField.name) {
|
|
52
51
|
delete o[k];
|
|
53
52
|
} else {
|