@travetto/model-sql 8.0.0-alpha.16 → 8.0.0-alpha.17
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 +8 -8
- package/src/dialect/base.ts +3 -1
- package/src/service.ts +37 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-sql",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "SQL backing for the travetto model module, with real-time modeling support for SQL schemas.",
|
|
6
6
|
"keywords": [
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
"directory": "module/model-sql"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@travetto/config": "^8.0.0-alpha.
|
|
32
|
-
"@travetto/context": "^8.0.0-alpha.
|
|
33
|
-
"@travetto/model": "^8.0.0-alpha.
|
|
34
|
-
"@travetto/model-indexed": "^8.0.0-alpha.
|
|
35
|
-
"@travetto/model-query": "^8.0.0-alpha.
|
|
31
|
+
"@travetto/config": "^8.0.0-alpha.15",
|
|
32
|
+
"@travetto/context": "^8.0.0-alpha.14",
|
|
33
|
+
"@travetto/model": "^8.0.0-alpha.15",
|
|
34
|
+
"@travetto/model-indexed": "^8.0.0-alpha.17",
|
|
35
|
+
"@travetto/model-query": "^8.0.0-alpha.16"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@travetto/cli": "^8.0.0-alpha.
|
|
39
|
-
"@travetto/test": "^8.0.0-alpha.
|
|
38
|
+
"@travetto/cli": "^8.0.0-alpha.20",
|
|
39
|
+
"@travetto/test": "^8.0.0-alpha.14"
|
|
40
40
|
},
|
|
41
41
|
"peerDependenciesMeta": {
|
|
42
42
|
"@travetto/cli": {
|
package/src/dialect/base.ts
CHANGED
|
@@ -539,7 +539,9 @@ export abstract class SQLDialect implements DialectState {
|
|
|
539
539
|
items.push(`${sPath} ${SQL_OPS.$eq} ${this.resolveValue(field, top)}`);
|
|
540
540
|
}
|
|
541
541
|
}
|
|
542
|
-
if (items.length ===
|
|
542
|
+
if (items.length === 0) {
|
|
543
|
+
return 'TRUE';
|
|
544
|
+
} else if (items.length === 1) {
|
|
543
545
|
return items[0];
|
|
544
546
|
} else {
|
|
545
547
|
return `(${items.join(` ${SQL_OPS.$and} `)})`;
|
package/src/service.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
type ModelIndexedSupport, type KeyedIndexSelection, type KeyedIndexBody, type ModelPageOptions, ModelIndexedUtil,
|
|
9
9
|
type SingleItemIndex, type SortedIndexSelection, type ModelPageResult, type SortedIndex, type FullKeyedIndexBody,
|
|
10
|
-
type FullKeyedIndexWithPartialBody, ModelIndexedComputedIndex
|
|
10
|
+
type FullKeyedIndexWithPartialBody, ModelIndexedComputedIndex, type ModelIndexedSearchOptions, type SortedIndexSelectionType
|
|
11
11
|
} from '@travetto/model-indexed';
|
|
12
12
|
import { castTo, type Class, JSONUtil } from '@travetto/runtime';
|
|
13
13
|
import { DataUtil } from '@travetto/schema';
|
|
@@ -16,8 +16,7 @@ import { Injectable, PostConstruct } from '@travetto/di';
|
|
|
16
16
|
import {
|
|
17
17
|
type ModelQuery, type ModelQueryCrudSupport, type ModelQueryFacetSupport, type ModelQuerySupport,
|
|
18
18
|
type PageableModelQuery, type ValidStringFields, type WhereClauseRaw, QueryVerifier, type ModelQuerySuggestSupport,
|
|
19
|
-
ModelQueryUtil, ModelQuerySuggestUtil, ModelQueryCrudUtil,
|
|
20
|
-
type ModelQueryFacet,
|
|
19
|
+
ModelQueryUtil, ModelQuerySuggestUtil, ModelQueryCrudUtil, type ModelQueryFacet,
|
|
21
20
|
} from '@travetto/model-query';
|
|
22
21
|
|
|
23
22
|
import type { SQLModelConfig } from './config.ts';
|
|
@@ -317,7 +316,7 @@ export class SQLModelService implements
|
|
|
317
316
|
}
|
|
318
317
|
|
|
319
318
|
@Connected()
|
|
320
|
-
async
|
|
319
|
+
async suggestByQuery<T extends ModelType>(cls: Class<T>, field: ValidStringFields<T>, prefix?: string, query?: PageableModelQuery<T>): Promise<T[]> {
|
|
321
320
|
await QueryVerifier.verify(cls, query);
|
|
322
321
|
const resolvedQuery = ModelQuerySuggestUtil.getSuggestQuery<T>(cls, field, prefix, query);
|
|
323
322
|
const results = await this.query<T>(cls, resolvedQuery);
|
|
@@ -325,7 +324,7 @@ export class SQLModelService implements
|
|
|
325
324
|
}
|
|
326
325
|
|
|
327
326
|
@Connected()
|
|
328
|
-
async
|
|
327
|
+
async suggestValuesByQuery<T extends ModelType>(cls: Class<T>, field: ValidStringFields<T>, prefix?: string, query?: PageableModelQuery<T>): Promise<string[]> {
|
|
329
328
|
await QueryVerifier.verify(cls, query);
|
|
330
329
|
const resolvedQuery = ModelQuerySuggestUtil.getSuggestFieldQuery(cls, field, prefix, query);
|
|
331
330
|
const results = await this.query(cls, resolvedQuery);
|
|
@@ -335,7 +334,7 @@ export class SQLModelService implements
|
|
|
335
334
|
}
|
|
336
335
|
|
|
337
336
|
@Connected()
|
|
338
|
-
async
|
|
337
|
+
async facetByQuery<T extends ModelType>(cls: Class<T>, field: ValidStringFields<T>, query?: ModelQuery<T>): Promise<ModelQueryFacet[]> {
|
|
339
338
|
await QueryVerifier.verify(cls, query);
|
|
340
339
|
const col = this.#dialect.identifier(field);
|
|
341
340
|
const ttl = this.#dialect.identifier('count');
|
|
@@ -467,4 +466,36 @@ export class SQLModelService implements
|
|
|
467
466
|
yield items;
|
|
468
467
|
}
|
|
469
468
|
}
|
|
469
|
+
|
|
470
|
+
@Connected()
|
|
471
|
+
async suggestByIndex<
|
|
472
|
+
T extends ModelType,
|
|
473
|
+
S extends SortedIndexSelection<T>,
|
|
474
|
+
K extends KeyedIndexSelection<T>,
|
|
475
|
+
B extends SortedIndexSelectionType<T, S> & string
|
|
476
|
+
>(cls: Class<T>, idx: SortedIndex<T, K, S>, body: KeyedIndexBody<T, K>, prefix: B, options?: ModelIndexedSearchOptions): Promise<T[]> {
|
|
477
|
+
const items: T[] = [];
|
|
478
|
+
const computed = ModelIndexedComputedIndex.get(idx, body).validate();
|
|
479
|
+
const nested: Record<string, unknown> = {};
|
|
480
|
+
let current = nested;
|
|
481
|
+
for (const key of idx.sortTemplate[0].path.slice(0, -1)) {
|
|
482
|
+
current = (current[key] = {});
|
|
483
|
+
}
|
|
484
|
+
current[idx.sortTemplate[0].path.at(-1)!] = { $regex: ModelIndexedUtil.getSuggestRegex(prefix) };
|
|
485
|
+
|
|
486
|
+
const baseQuery = castTo<ModelQuery<T>>({
|
|
487
|
+
where: {
|
|
488
|
+
$and: [
|
|
489
|
+
computed.project(),
|
|
490
|
+
nested
|
|
491
|
+
]
|
|
492
|
+
},
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
for await (const batch of this.#scanTable<T>(cls, () => baseQuery, { limit: 10, ...options })) {
|
|
496
|
+
items.push(...batch.items);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
return items;
|
|
500
|
+
}
|
|
470
501
|
}
|