@entity-access/entity-access 1.0.200 → 1.0.202
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/dist/compiler/QueryCompiler.d.ts +2 -1
- package/dist/compiler/QueryCompiler.d.ts.map +1 -1
- package/dist/compiler/QueryCompiler.js +2 -3
- package/dist/compiler/QueryCompiler.js.map +1 -1
- package/dist/decorators/Table.d.ts +1 -0
- package/dist/decorators/Table.d.ts.map +1 -1
- package/dist/decorators/Table.js +7 -0
- package/dist/decorators/Table.js.map +1 -1
- package/dist/drivers/sql-server/SqlServerQueryCompiler.d.ts +1 -1
- package/dist/drivers/sql-server/SqlServerQueryCompiler.d.ts.map +1 -1
- package/dist/drivers/sql-server/SqlServerQueryCompiler.js +2 -3
- package/dist/drivers/sql-server/SqlServerQueryCompiler.js.map +1 -1
- package/dist/entity-query/EntityType.d.ts +5 -3
- package/dist/entity-query/EntityType.d.ts.map +1 -1
- package/dist/entity-query/EntityType.js +15 -9
- package/dist/entity-query/EntityType.js.map +1 -1
- package/dist/migrations/Migrations.d.ts.map +1 -1
- package/dist/migrations/Migrations.js +3 -0
- package/dist/migrations/Migrations.js.map +1 -1
- package/dist/model/EntityModel.d.ts.map +1 -1
- package/dist/model/EntityModel.js +4 -1
- package/dist/model/EntityModel.js.map +1 -1
- package/dist/model/EntityQuery.d.ts.map +1 -1
- package/dist/model/EntityQuery.js +13 -4
- package/dist/model/EntityQuery.js.map +1 -1
- package/dist/query/ast/ExpressionToSql.d.ts.map +1 -1
- package/dist/query/ast/ExpressionToSql.js +12 -6
- package/dist/query/ast/ExpressionToSql.js.map +1 -1
- package/dist/query/ast/Expressions.d.ts +2 -0
- package/dist/query/ast/Expressions.d.ts.map +1 -1
- package/dist/query/ast/Expressions.js +3 -0
- package/dist/query/ast/Expressions.js.map +1 -1
- package/dist/tests/db-tests/tests/select-map.d.ts +3 -0
- package/dist/tests/db-tests/tests/select-map.d.ts.map +1 -0
- package/dist/tests/db-tests/tests/select-map.js +12 -0
- package/dist/tests/db-tests/tests/select-map.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/workflows/WorkflowStorage.d.ts.map +1 -1
- package/dist/workflows/WorkflowStorage.js +1 -0
- package/dist/workflows/WorkflowStorage.js.map +1 -1
- package/package.json +1 -1
- package/src/compiler/QueryCompiler.ts +3 -2
- package/src/decorators/Table.ts +8 -0
- package/src/drivers/sql-server/SqlServerQueryCompiler.ts +2 -1
- package/src/entity-query/EntityType.ts +19 -10
- package/src/migrations/Migrations.ts +4 -0
- package/src/model/EntityModel.ts +9 -2
- package/src/model/EntityQuery.ts +14 -4
- package/src/query/ast/ExpressionToSql.ts +12 -6
- package/src/query/ast/Expressions.ts +5 -0
- package/src/tests/db-tests/tests/select-map.ts +19 -0
- package/src/workflows/WorkflowStorage.ts +2 -1
package/src/model/EntityModel.ts
CHANGED
|
@@ -19,7 +19,10 @@ const getOrCreateModel = (map: Map<any, EntityType>, type: IClassOf<any>, naming
|
|
|
19
19
|
map.set(type, t);
|
|
20
20
|
for (const iterator of original.columns) {
|
|
21
21
|
const column = { ... iterator };
|
|
22
|
-
column.columnName = column.explicitName
|
|
22
|
+
column.columnName = column.explicitName
|
|
23
|
+
? column.columnName
|
|
24
|
+
: (namingConvention
|
|
25
|
+
? namingConvention(column.columnName) : column.columnName);
|
|
23
26
|
t.addColumn(column);
|
|
24
27
|
column.entityType = t;
|
|
25
28
|
}
|
|
@@ -54,7 +57,11 @@ export default class EntityModel {
|
|
|
54
57
|
let source = this.sources.get(type);
|
|
55
58
|
if (!source) {
|
|
56
59
|
const cache = (this.context.driver[driverModelCache] ??= new Map());
|
|
57
|
-
const entityType = getOrCreateModel(
|
|
60
|
+
const entityType = getOrCreateModel(
|
|
61
|
+
cache,
|
|
62
|
+
type,
|
|
63
|
+
this.context.driver.compiler.namingConvention
|
|
64
|
+
);
|
|
58
65
|
this.types.set(type, entityType);
|
|
59
66
|
source = new EntitySource(entityType, this.context);
|
|
60
67
|
this.sources.set(type, source);
|
package/src/model/EntityQuery.ts
CHANGED
|
@@ -33,7 +33,7 @@ export default class EntityQuery<T = any>
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
map(parameters: any, fx: any): any {
|
|
36
|
-
|
|
36
|
+
const q = this.extend(parameters, fx, (select, body) => {
|
|
37
37
|
const fields = [] as Expression[];
|
|
38
38
|
switch(body.type) {
|
|
39
39
|
case "NewObjectExpression":
|
|
@@ -41,7 +41,7 @@ export default class EntityQuery<T = any>
|
|
|
41
41
|
for (const iterator of noe.properties) {
|
|
42
42
|
fields.push(ExpressionAs.create({
|
|
43
43
|
expression: iterator.expression,
|
|
44
|
-
alias: iterator.alias
|
|
44
|
+
alias: Expression.quotedIdentifier(iterator.alias.value)
|
|
45
45
|
}));
|
|
46
46
|
}
|
|
47
47
|
break;
|
|
@@ -52,6 +52,8 @@ export default class EntityQuery<T = any>
|
|
|
52
52
|
}
|
|
53
53
|
return { ... select, fields };
|
|
54
54
|
});
|
|
55
|
+
q.type = null;
|
|
56
|
+
return q;
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
withSignal(signal: AbortSignal): any {
|
|
@@ -111,14 +113,19 @@ export default class EntityQuery<T = any>
|
|
|
111
113
|
}
|
|
112
114
|
|
|
113
115
|
signal?.throwIfAborted();
|
|
116
|
+
let select = this.selectStatement;
|
|
114
117
|
|
|
115
|
-
|
|
118
|
+
if (type && select.model) {
|
|
119
|
+
select = { ... select, fields: select.model.getFieldMap(select.sourceParameter) };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
query = this.context.driver.compiler.compileExpression(this, select);
|
|
116
123
|
this.traceQuery?.(query.text);
|
|
117
124
|
const reader = await this.context.connection.executeReader(query, signal);
|
|
118
125
|
scope.register(reader);
|
|
119
126
|
for await (const iterator of reader.next(10, signal)) {
|
|
120
127
|
if (type) {
|
|
121
|
-
const item = type
|
|
128
|
+
const item = type.map(iterator) as any;
|
|
122
129
|
// set identity...
|
|
123
130
|
const entry = this.context.changeSet.getEntry(item, item);
|
|
124
131
|
relationMapper.fix(entry);
|
|
@@ -138,6 +145,9 @@ export default class EntityQuery<T = any>
|
|
|
138
145
|
let query: { text, values };
|
|
139
146
|
let reader: IDbReader;
|
|
140
147
|
try {
|
|
148
|
+
if (select.model) {
|
|
149
|
+
select = { ... select, fields: select.model.getFieldMap(select.sourceParameter) };
|
|
150
|
+
}
|
|
141
151
|
query = this.context.driver.compiler.compileExpression(this, select);
|
|
142
152
|
this.traceQuery?.(query.text);
|
|
143
153
|
reader = await this.context.connection.executeReader(query, signal);
|
|
@@ -323,7 +323,9 @@ export default class ExpressionToSql extends Visitor<ITextQuery> {
|
|
|
323
323
|
}
|
|
324
324
|
|
|
325
325
|
visitIdentifier(e: Identifier): ITextQuery {
|
|
326
|
-
|
|
326
|
+
if (e.quoted) {
|
|
327
|
+
return [this.compiler.quote(e.value)];
|
|
328
|
+
}
|
|
327
329
|
return [e.value];
|
|
328
330
|
}
|
|
329
331
|
|
|
@@ -358,10 +360,10 @@ export default class ExpressionToSql extends Visitor<ITextQuery> {
|
|
|
358
360
|
const name = this.scope.nameOf(parameter);
|
|
359
361
|
|
|
360
362
|
// need to change name as per naming convention here...
|
|
361
|
-
const namingConvention = this.compiler.namingConvention;
|
|
362
|
-
if (scope.model && namingConvention) {
|
|
363
|
-
|
|
364
|
-
}
|
|
363
|
+
// const namingConvention = this.compiler.namingConvention;
|
|
364
|
+
// if (scope.model && namingConvention) {
|
|
365
|
+
// chain[0] = namingConvention(chain[0]);
|
|
366
|
+
// }
|
|
365
367
|
|
|
366
368
|
return [ QueryParameter.create(() => name) , "." , chain.join(".")];
|
|
367
369
|
}
|
|
@@ -669,7 +671,11 @@ export default class ExpressionToSql extends Visitor<ITextQuery> {
|
|
|
669
671
|
const scope = this.scope.get(pe);
|
|
670
672
|
const peModel = scope?.model;
|
|
671
673
|
if (peModel) {
|
|
672
|
-
const { relation } = peModel.getProperty(id.value);
|
|
674
|
+
const { relation, field } = peModel.getProperty(id.value);
|
|
675
|
+
if (field) {
|
|
676
|
+
// we need to replace field with column name...
|
|
677
|
+
return Expression.member(target, field.columnName);
|
|
678
|
+
}
|
|
673
679
|
if (relation) {
|
|
674
680
|
|
|
675
681
|
const { fkColumn } = relation;
|
|
@@ -66,6 +66,10 @@ export abstract class Expression {
|
|
|
66
66
|
return Identifier.create({ value: name });
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
static quotedIdentifier(name: string) {
|
|
70
|
+
return Identifier.create({ value: name, quoted: true });
|
|
71
|
+
}
|
|
72
|
+
|
|
69
73
|
static logicalAnd(left: Expression, right: Expression): BinaryExpression {
|
|
70
74
|
return BinaryExpression.create({ left, operator: "AND", right});
|
|
71
75
|
}
|
|
@@ -307,6 +311,7 @@ export class Constant extends Expression {
|
|
|
307
311
|
export class Identifier extends Expression {
|
|
308
312
|
readonly type = "Identifier";
|
|
309
313
|
public value: string;
|
|
314
|
+
public quoted: boolean;
|
|
310
315
|
}
|
|
311
316
|
|
|
312
317
|
export class NullExpression extends Expression {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import { TestConfig } from "../../TestConfig.js";
|
|
3
|
+
import { createContext, headPhoneCategory } from "../../model/createContext.js";
|
|
4
|
+
import Sql from "../../../sql/Sql.js";
|
|
5
|
+
|
|
6
|
+
export default async function(this: TestConfig) {
|
|
7
|
+
|
|
8
|
+
if (!this.db) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const context = await createContext(this.driver);
|
|
13
|
+
|
|
14
|
+
const f = await context.orderItems.all()
|
|
15
|
+
.map({}, (p) => ({ orderID, amount }) => ({ orderID, amount }))
|
|
16
|
+
.first();
|
|
17
|
+
|
|
18
|
+
console.log(f);
|
|
19
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
1
2
|
import { randomUUID } from "crypto";
|
|
2
3
|
import Column from "../decorators/Column.js";
|
|
3
4
|
import Index from "../decorators/Index.js";
|
|
@@ -293,7 +294,7 @@ export default class WorkflowStorage {
|
|
|
293
294
|
list.push(iterator);
|
|
294
295
|
}
|
|
295
296
|
} catch (error) {
|
|
296
|
-
console.error(error);
|
|
297
|
+
console.error(error);
|
|
297
298
|
}
|
|
298
299
|
}
|
|
299
300
|
return list;
|