@travetto/model-sql 3.1.0-rc.0 → 3.1.0-rc.10
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 +7 -7
- package/src/dialect/base.ts +15 -17
- package/src/service.ts +9 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-sql",
|
|
3
|
-
"version": "3.1.0-rc.
|
|
3
|
+
"version": "3.1.0-rc.10",
|
|
4
4
|
"description": "SQL backing for the travetto model module, with real-time modeling support for SQL schemas.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sql",
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
"directory": "module/model-sql"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@travetto/config": "^3.1.0-rc.
|
|
31
|
-
"@travetto/context": "^3.1.0-rc.
|
|
32
|
-
"@travetto/model": "^3.1.0-rc.
|
|
33
|
-
"@travetto/model-query": "^3.1.0-rc.
|
|
30
|
+
"@travetto/config": "^3.1.0-rc.8",
|
|
31
|
+
"@travetto/context": "^3.1.0-rc.5",
|
|
32
|
+
"@travetto/model": "^3.1.0-rc.10",
|
|
33
|
+
"@travetto/model-query": "^3.1.0-rc.10"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@travetto/command": "^3.1.0-rc.
|
|
37
|
-
"@travetto/test": "^3.1.0-rc.
|
|
36
|
+
"@travetto/command": "^3.1.0-rc.5",
|
|
37
|
+
"@travetto/test": "^3.1.0-rc.4"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@travetto/command": {
|
package/src/dialect/base.ts
CHANGED
|
@@ -6,7 +6,6 @@ import { BulkResponse, IndexConfig } from '@travetto/model';
|
|
|
6
6
|
import { PointImpl } from '@travetto/model-query/src/internal/model/point';
|
|
7
7
|
import { ModelType } from '@travetto/model/src/types/model';
|
|
8
8
|
import { ModelQueryUtil } from '@travetto/model-query/src/internal/service/query';
|
|
9
|
-
import { ModelUtil } from '@travetto/model/src/internal/util';
|
|
10
9
|
|
|
11
10
|
import { SQLUtil, VisitStack } from '../internal/util';
|
|
12
11
|
import { DeleteWrapper, InsertWrapper, DialectState } from '../internal/types';
|
|
@@ -46,7 +45,13 @@ export abstract class SQLDialect implements DialectState {
|
|
|
46
45
|
/**
|
|
47
46
|
* Default length of unique ids
|
|
48
47
|
*/
|
|
49
|
-
|
|
48
|
+
ID_LEN = 32;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Hash Length
|
|
52
|
+
*/
|
|
53
|
+
HASH_LEN = 64;
|
|
54
|
+
|
|
50
55
|
/**
|
|
51
56
|
* Default length for varchar
|
|
52
57
|
*/
|
|
@@ -104,8 +109,8 @@ export abstract class SQLDialect implements DialectState {
|
|
|
104
109
|
* Generate an id field
|
|
105
110
|
*/
|
|
106
111
|
idField = makeField('id', String, true, {
|
|
107
|
-
maxlength: { n:
|
|
108
|
-
minlength: { n:
|
|
112
|
+
maxlength: { n: this.ID_LEN },
|
|
113
|
+
minlength: { n: this.ID_LEN }
|
|
109
114
|
});
|
|
110
115
|
|
|
111
116
|
/**
|
|
@@ -117,8 +122,8 @@ export abstract class SQLDialect implements DialectState {
|
|
|
117
122
|
* Parent path reference
|
|
118
123
|
*/
|
|
119
124
|
parentPathField = makeField('__parent_path', String, true, {
|
|
120
|
-
maxlength: { n: this.
|
|
121
|
-
minlength: { n: this.
|
|
125
|
+
maxlength: { n: this.HASH_LEN },
|
|
126
|
+
minlength: { n: this.HASH_LEN },
|
|
122
127
|
required: { active: true }
|
|
123
128
|
});
|
|
124
129
|
|
|
@@ -126,8 +131,8 @@ export abstract class SQLDialect implements DialectState {
|
|
|
126
131
|
* Path reference
|
|
127
132
|
*/
|
|
128
133
|
pathField = makeField('__path', String, true, {
|
|
129
|
-
maxlength: { n: this.
|
|
130
|
-
minlength: { n: this.
|
|
134
|
+
maxlength: { n: this.HASH_LEN },
|
|
135
|
+
minlength: { n: this.HASH_LEN },
|
|
131
136
|
required: { active: true }
|
|
132
137
|
});
|
|
133
138
|
|
|
@@ -242,7 +247,7 @@ export abstract class SQLDialect implements DialectState {
|
|
|
242
247
|
} else if (conf.type === Boolean) {
|
|
243
248
|
type = this.COLUMN_TYPES.BOOLEAN;
|
|
244
249
|
} else if (conf.type === String) {
|
|
245
|
-
if (conf.
|
|
250
|
+
if (conf.specifiers?.includes('text')) {
|
|
246
251
|
type = this.COLUMN_TYPES.TEXT;
|
|
247
252
|
} else {
|
|
248
253
|
type = this.PARAMETERIZED_COLUMN_TYPES.VARCHAR(conf.maxlength ? conf.maxlength.n : this.DEFAULT_STRING_LEN);
|
|
@@ -307,13 +312,6 @@ export abstract class SQLDialect implements DialectState {
|
|
|
307
312
|
*/
|
|
308
313
|
abstract getModifyColumnSQL(stack: VisitStack[]): string;
|
|
309
314
|
|
|
310
|
-
/**
|
|
311
|
-
* Generate a UUID
|
|
312
|
-
*/
|
|
313
|
-
generateId(): string {
|
|
314
|
-
return ModelUtil.uuid(this.KEY_LEN);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
315
|
/**
|
|
318
316
|
* Determine table/field namespace for a given stack location
|
|
319
317
|
*/
|
|
@@ -646,7 +644,7 @@ ${this.getLimitSQL(cls, query)}`;
|
|
|
646
644
|
if (!idField) {
|
|
647
645
|
fields.push(idField = this.idField);
|
|
648
646
|
} else {
|
|
649
|
-
idField.maxlength = { n: this.
|
|
647
|
+
idField.maxlength = { n: this.ID_LEN };
|
|
650
648
|
}
|
|
651
649
|
}
|
|
652
650
|
|
package/src/service.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ModelType,
|
|
3
3
|
BulkOp, BulkResponse, ModelCrudSupport, ModelStorageSupport, ModelBulkSupport,
|
|
4
|
-
NotFoundError, ModelRegistry, ExistsError, OptionalId
|
|
4
|
+
NotFoundError, ModelRegistry, ExistsError, OptionalId,
|
|
5
|
+
ModelUuidGenerator
|
|
5
6
|
} from '@travetto/model';
|
|
6
7
|
import { DataUtil, Class } from '@travetto/base';
|
|
7
8
|
import { SchemaChange } from '@travetto/schema';
|
|
@@ -9,7 +10,7 @@ import { AsyncContext } from '@travetto/context';
|
|
|
9
10
|
import { Injectable } from '@travetto/di';
|
|
10
11
|
import {
|
|
11
12
|
ModelQuery, ModelQueryCrudSupport, ModelQueryFacetSupport, ModelQuerySupport,
|
|
12
|
-
PageableModelQuery, ValidStringFields, WhereClauseRaw
|
|
13
|
+
PageableModelQuery, ValidStringFields, WhereClauseRaw,
|
|
13
14
|
} from '@travetto/model-query';
|
|
14
15
|
|
|
15
16
|
import { ModelQueryUtil } from '@travetto/model-query/src/internal/service/query';
|
|
@@ -44,6 +45,7 @@ export class SQLModelService implements
|
|
|
44
45
|
#manager: TableManager;
|
|
45
46
|
#context: AsyncContext;
|
|
46
47
|
#dialect: SQLDialect;
|
|
48
|
+
uuid: ModelUuidGenerator;
|
|
47
49
|
|
|
48
50
|
readonly config: SQLModelConfig;
|
|
49
51
|
|
|
@@ -107,6 +109,7 @@ export class SQLModelService implements
|
|
|
107
109
|
if (this.#dialect.conn.init) {
|
|
108
110
|
await this.#dialect.conn.init();
|
|
109
111
|
}
|
|
112
|
+
this.uuid = ModelCrudUtil.uuidGenerator(this.#dialect.ID_LEN);
|
|
110
113
|
this.#manager = new TableManager(this.#context, this.#dialect);
|
|
111
114
|
await ModelStorageUtil.registerModelChangeListener(this);
|
|
112
115
|
ModelExpiryUtil.registerCull(this);
|
|
@@ -117,10 +120,6 @@ export class SQLModelService implements
|
|
|
117
120
|
return this.#dialect.conn;
|
|
118
121
|
}
|
|
119
122
|
|
|
120
|
-
uuid(): string {
|
|
121
|
-
return this.#dialect.generateId();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
123
|
async exportModel<T extends ModelType>(e: Class<T>): Promise<string> {
|
|
125
124
|
return (await this.#manager.exportTables(e)).join('\n');
|
|
126
125
|
}
|
|
@@ -259,8 +258,8 @@ export class SQLModelService implements
|
|
|
259
258
|
|
|
260
259
|
@Connected()
|
|
261
260
|
async queryOne<T extends ModelType>(cls: Class<T>, builder: ModelQuery<T>, failOnMany = true): Promise<T> {
|
|
262
|
-
const res = await this.query(cls, { ...builder, limit: failOnMany ? 2 : 1 });
|
|
263
|
-
return ModelQueryUtil.verifyGetSingleCounts(cls, res, failOnMany);
|
|
261
|
+
const res = await this.query<T>(cls, { ...builder, limit: failOnMany ? 2 : 1 });
|
|
262
|
+
return ModelQueryUtil.verifyGetSingleCounts<T>(cls, res, failOnMany);
|
|
264
263
|
}
|
|
265
264
|
|
|
266
265
|
@Connected()
|
|
@@ -285,8 +284,8 @@ export class SQLModelService implements
|
|
|
285
284
|
|
|
286
285
|
@Connected()
|
|
287
286
|
async suggest<T extends ModelType>(cls: Class<T>, field: ValidStringFields<T>, prefix?: string, query?: PageableModelQuery<T>): Promise<T[]> {
|
|
288
|
-
const q = ModelQuerySuggestUtil.getSuggestQuery(cls, field, prefix, query);
|
|
289
|
-
const results = await this.query(cls, q);
|
|
287
|
+
const q = ModelQuerySuggestUtil.getSuggestQuery<T>(cls, field, prefix, query);
|
|
288
|
+
const results = await this.query<T>(cls, q);
|
|
290
289
|
return ModelQuerySuggestUtil.combineSuggestResults(cls, field, prefix, results, (a, b) => b, query?.limit);
|
|
291
290
|
}
|
|
292
291
|
|