@ts-awesome/orm 1.5.0-alpha.10 → 1.5.0-alpha.13

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/base.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { DbValueType, IBuildableQuery, IBuildableQueryCompiler, IQueryData, IQueryDriver, IQueryExecutor, IQueryExecutorProvider, IsolationLevel, ITransaction, TableMetaProvider, WithParams } from "./interfaces";
2
+ import { NamedParameter } from "./wrappers";
2
3
  export declare abstract class BaseCompiler<TQuery> implements IBuildableQueryCompiler<TQuery> {
3
4
  abstract compile(query: IBuildableQuery): TQuery;
4
5
  }
@@ -9,8 +10,8 @@ export declare abstract class BaseExecutor<TQuery, R extends IQueryData = IQuery
9
10
  protected abstract do(query: TQuery & WithParams): Promise<readonly R[]>;
10
11
  protected _namedParameters: Record<string, DbValueType>;
11
12
  get namedParameters(): Readonly<Record<string, DbValueType>>;
12
- setNamedParameter(name: string, value: DbValueType): void;
13
- removeNamedParameter(name: string): void;
13
+ setNamedParameter<T extends DbValueType>(param: NamedParameter<T>, value: T): void;
14
+ removeNamedParameter(param: NamedParameter<unknown>): void;
14
15
  }
15
16
  export declare abstract class BaseExecutorProvider<TQuery> implements IQueryExecutorProvider<TQuery> {
16
17
  abstract getExecutor(): IQueryExecutor<TQuery>;
package/dist/base.js CHANGED
@@ -33,11 +33,11 @@ let BaseExecutor = class BaseExecutor {
33
33
  get namedParameters() {
34
34
  return { ...this._namedParameters };
35
35
  }
36
- setNamedParameter(name, value) {
37
- this._namedParameters[name] = value;
36
+ setNamedParameter(param, value) {
37
+ this._namedParameters[param._named] = value;
38
38
  }
39
- removeNamedParameter(name) {
40
- delete this._namedParameters[name];
39
+ removeNamedParameter(param) {
40
+ delete this._namedParameters[param._named];
41
41
  }
42
42
  };
43
43
  BaseExecutor = __decorate([
package/dist/base.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":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ADjC,IAAA,sBAAU,GAAE;GACS,YAAY,CA6BjC;AA7BqB,oCAAY;AAgC3B,IAAe,oBAAoB,GAAnC,MAAe,oBAAoB;CAEzC,CAAA;AAFqB,oBAAoB;IADzC,IAAA,sBAAU,GAAE;GACS,oBAAoB,CAEzC;AAFqB,oDAAoB;AAKnC,IAAe,eAAe,GAA9B,MAAe,eAAgF,SAAQ,YAAuB;CAKpI,CAAA;AALqB,eAAe;IADpC,IAAA,sBAAU,GAAE;GACS,eAAe,CAKpC;AALqB,0CAAe;AAQ9B,IAAe,UAAU,GAAzB,MAAe,UAA2E,SAAQ,YAAuB;CAG/H,CAAA;AAHqB,UAAU;IAD/B,IAAA,sBAAU,GAAE;GACS,UAAU,CAG/B;AAHqB,gCAAU"}
@@ -1,5 +1,5 @@
1
1
  import { IExpression, IJoin, IOrderBy, IReference } from './intermediate';
2
- import { Operandable } from "./wrappers";
2
+ import { NamedParameter, Operandable } from "./wrappers";
3
3
  export type DbValueType = string | number | boolean | Date | null | undefined;
4
4
  export interface IDbField<T = any, X = any> {
5
5
  readQuery?(reference: IOperandable, table: Queryable<X>): IOperandable;
@@ -217,8 +217,8 @@ export interface IQueryExecutor<T, R = IQueryData> {
217
217
  execute(query: T & WithParams, scalar: true): Promise<number>;
218
218
  execute<X extends TableMetaProvider>(query: T & WithParams, Model: X, sensitive?: boolean): Promise<ReadonlyArray<InstanceType<X>>>;
219
219
  readonly namedParameters: Readonly<Record<string, DbValueType>>;
220
- setNamedParameter(name: string, value: DbValueType): void;
221
- removeNamedParameter(name: string): void;
220
+ setNamedParameter<T extends DbValueType>(param: NamedParameter<T>, value: T): void;
221
+ removeNamedParameter(param: NamedParameter<unknown>): void;
222
222
  }
223
223
  export declare const enum IsolationLevel {
224
224
  Serializable = "SERIALIZABLE",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-awesome/orm",
3
- "version": "1.5.0-alpha.10",
3
+ "version": "1.5.0-alpha.13",
4
4
  "description": "TypeScript friendly minimalistic ORM",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -13,23 +13,23 @@ const dist_1 = require("../dist");
13
13
  const models_1 = require("./models");
14
14
  const builder_1 = require("../dist/builder");
15
15
  const dist_2 = require("../dist");
16
- const tableInfo = builder_1.readModelMeta(models_1.Person);
16
+ const tableInfo = (0, builder_1.readModelMeta)(models_1.Person);
17
17
  const tableName = tableInfo.tableName;
18
18
  const person = { id: 1, name: 'Name', age: 18, city: 'City', profiles: ["profile-a"] };
19
19
  describe('Select', () => {
20
20
  it('Check query info', () => {
21
- const query = dist_1.Select(models_1.Person);
21
+ const query = (0, dist_1.Select)(models_1.Person);
22
22
  expect(query._type).toBe('SELECT');
23
23
  expect(query._table).toStrictEqual(tableInfo);
24
24
  });
25
25
  it('Columns through array list', () => {
26
26
  const nameAlias = 'PersonName';
27
27
  const coefficient = 2;
28
- const columnsThroughList = dist_1.Select(models_1.Person).columns(['name', 'age']);
29
- const columnsThroughBuilder = dist_1.Select(models_1.Person).columns(({ name, age }) => [name, age]);
30
- const columnsWithAlias = dist_1.Select(models_1.Person).columns(({ name }) => [dist_1.alias(name, nameAlias)]);
31
- const columnsWithOf = dist_1.Select(models_1.Person).columns(() => [dist_1.of(models_1.Employee, 'company')]);
32
- const columnsWithExpression = dist_1.Select(models_1.Person).columns(({ age }) => [age.mul(coefficient), dist_1.max(age)]);
28
+ const columnsThroughList = (0, dist_1.Select)(models_1.Person).columns(['name', 'age']);
29
+ const columnsThroughBuilder = (0, dist_1.Select)(models_1.Person).columns(({ name, age }) => [name, age]);
30
+ const columnsWithAlias = (0, dist_1.Select)(models_1.Person).columns(({ name }) => [(0, dist_1.alias)(name, nameAlias)]);
31
+ const columnsWithOf = (0, dist_1.Select)(models_1.Person).columns(() => [(0, dist_1.of)(models_1.Employee, 'company')]);
32
+ const columnsWithExpression = (0, dist_1.Select)(models_1.Person).columns(({ age }) => [age.mul(coefficient), (0, dist_1.max)(age)]);
33
33
  const expectation = {
34
34
  default: [
35
35
  { _column: { table: tableName, name: 'name' } },
@@ -39,7 +39,7 @@ describe('Select', () => {
39
39
  { _alias: nameAlias, _operands: [{ _column: { table: tableName, name: 'name' } }] }
40
40
  ],
41
41
  of: [
42
- { _column: { table: builder_1.readModelMeta(models_1.Employee).tableName, name: 'company' } }
42
+ { _column: { table: (0, builder_1.readModelMeta)(models_1.Employee).tableName, name: 'company' } }
43
43
  ],
44
44
  expression: [
45
45
  { _operator: '*', _operands: [{ _column: { table: tableName, name: 'age' } }, coefficient] },
@@ -53,15 +53,15 @@ describe('Select', () => {
53
53
  expect(columnsWithExpression._columns).toStrictEqual(expectation.expression);
54
54
  });
55
55
  it('Joins', () => {
56
- const employeeTableInfo = builder_1.readModelMeta(models_1.Employee);
57
- const innerJoin = dist_1.Select(models_1.Person).join(models_1.Employee, ({ id }, { personId }) => id.eq(personId));
58
- const leftJoin = dist_1.Select(models_1.Person).joinLeft(models_1.Employee, ({ id }, { personId }) => id.eq(personId));
59
- const rightJoin = dist_1.Select(models_1.Person).joinRight(models_1.Employee, ({ id }, { personId }) => id.eq(personId));
60
- const fullJoin = dist_1.Select(models_1.Person).joinFull(models_1.Employee, ({ id }, { personId }) => id.eq(personId));
56
+ const employeeTableInfo = (0, builder_1.readModelMeta)(models_1.Employee);
57
+ const innerJoin = (0, dist_1.Select)(models_1.Person).join(models_1.Employee, ({ id }, { personId }) => id.eq(personId));
58
+ const leftJoin = (0, dist_1.Select)(models_1.Person).joinLeft(models_1.Employee, ({ id }, { personId }) => id.eq(personId));
59
+ const rightJoin = (0, dist_1.Select)(models_1.Person).joinRight(models_1.Employee, ({ id }, { personId }) => id.eq(personId));
60
+ const fullJoin = (0, dist_1.Select)(models_1.Person).joinFull(models_1.Employee, ({ id }, { personId }) => id.eq(personId));
61
61
  const innerJoinExpectation = [{
62
62
  _tableName: employeeTableInfo.tableName,
63
63
  _alias: undefined,
64
- _type: "INNER" /* inner */,
64
+ _type: "INNER" /* joinTypes.inner */,
65
65
  _condition: {
66
66
  _operands: [{ _column: { table: tableName, name: 'id' } }, { _column: { table: employeeTableInfo.tableName, name: `personId` } }],
67
67
  _operator: '='
@@ -70,7 +70,7 @@ describe('Select', () => {
70
70
  const leftJoinExpectation = [{
71
71
  _tableName: employeeTableInfo.tableName,
72
72
  _alias: undefined,
73
- _type: "LEFT" /* left */,
73
+ _type: "LEFT" /* joinTypes.left */,
74
74
  _condition: {
75
75
  _operands: [{ _column: { table: tableName, name: 'id' } }, { _column: { table: employeeTableInfo.tableName, name: `personId` } }],
76
76
  _operator: '='
@@ -79,7 +79,7 @@ describe('Select', () => {
79
79
  const rightJoinExpectation = [{
80
80
  _tableName: employeeTableInfo.tableName,
81
81
  _alias: undefined,
82
- _type: "RIGHT" /* right */,
82
+ _type: "RIGHT" /* joinTypes.right */,
83
83
  _condition: {
84
84
  _operands: [{ _column: { table: tableName, name: 'id' } }, { _column: { table: employeeTableInfo.tableName, name: `personId` } }],
85
85
  _operator: '='
@@ -88,7 +88,7 @@ describe('Select', () => {
88
88
  const fullJoinExpectation = [{
89
89
  _tableName: employeeTableInfo.tableName,
90
90
  _alias: undefined,
91
- _type: "FULL OUTER" /* full */,
91
+ _type: "FULL OUTER" /* joinTypes.full */,
92
92
  _condition: {
93
93
  _operands: [{ _column: { table: tableName, name: 'id' } }, { _column: { table: employeeTableInfo.tableName, name: `personId` } }],
94
94
  _operator: '='
@@ -101,15 +101,15 @@ describe('Select', () => {
101
101
  });
102
102
  it('Joins with alias', () => {
103
103
  const tableRef = new builder_1.TableRef(models_1.Employee);
104
- const employeeTableInfo = builder_1.readModelMeta(models_1.Employee);
105
- const innerJoin = dist_1.Select(models_1.Person).join(models_1.Employee, tableRef, ({ id }, { personId }) => id.eq(personId));
106
- const leftJoin = dist_1.Select(models_1.Person).joinLeft(models_1.Employee, tableRef, ({ id }, { personId }) => id.eq(personId));
107
- const rightJoin = dist_1.Select(models_1.Person).joinRight(models_1.Employee, tableRef, ({ id }, { personId }) => id.eq(personId));
108
- const fullJoin = dist_1.Select(models_1.Person).joinFull(models_1.Employee, tableRef, ({ id }, { personId }) => id.eq(personId));
104
+ const employeeTableInfo = (0, builder_1.readModelMeta)(models_1.Employee);
105
+ const innerJoin = (0, dist_1.Select)(models_1.Person).join(models_1.Employee, tableRef, ({ id }, { personId }) => id.eq(personId));
106
+ const leftJoin = (0, dist_1.Select)(models_1.Person).joinLeft(models_1.Employee, tableRef, ({ id }, { personId }) => id.eq(personId));
107
+ const rightJoin = (0, dist_1.Select)(models_1.Person).joinRight(models_1.Employee, tableRef, ({ id }, { personId }) => id.eq(personId));
108
+ const fullJoin = (0, dist_1.Select)(models_1.Person).joinFull(models_1.Employee, tableRef, ({ id }, { personId }) => id.eq(personId));
109
109
  const innerJoinExpectation = [{
110
110
  _tableName: employeeTableInfo.tableName,
111
111
  _alias: tableRef.tableName,
112
- _type: "INNER" /* inner */,
112
+ _type: "INNER" /* joinTypes.inner */,
113
113
  _condition: {
114
114
  _operands: [{ _column: { table: tableName, name: 'id' } }, { _column: { table: tableRef.tableName, name: `personId` } }],
115
115
  _operator: '='
@@ -118,7 +118,7 @@ describe('Select', () => {
118
118
  const leftJoinExpectation = [{
119
119
  _tableName: employeeTableInfo.tableName,
120
120
  _alias: tableRef.tableName,
121
- _type: "LEFT" /* left */,
121
+ _type: "LEFT" /* joinTypes.left */,
122
122
  _condition: {
123
123
  _operands: [{ _column: { table: tableName, name: 'id' } }, { _column: { table: tableRef.tableName, name: `personId` } }],
124
124
  _operator: '='
@@ -127,7 +127,7 @@ describe('Select', () => {
127
127
  const rightJoinExpectation = [{
128
128
  _tableName: employeeTableInfo.tableName,
129
129
  _alias: tableRef.tableName,
130
- _type: "RIGHT" /* right */,
130
+ _type: "RIGHT" /* joinTypes.right */,
131
131
  _condition: {
132
132
  _operands: [{ _column: { table: tableName, name: 'id' } }, { _column: { table: tableRef.tableName, name: `personId` } }],
133
133
  _operator: '='
@@ -136,7 +136,7 @@ describe('Select', () => {
136
136
  const fullJoinExpectation = [{
137
137
  _tableName: employeeTableInfo.tableName,
138
138
  _alias: tableRef.tableName,
139
- _type: "FULL OUTER" /* full */,
139
+ _type: "FULL OUTER" /* joinTypes.full */,
140
140
  _condition: {
141
141
  _operands: [{ _column: { table: tableName, name: 'id' } }, { _column: { table: tableRef.tableName, name: `personId` } }],
142
142
  _operator: '='
@@ -148,7 +148,7 @@ describe('Select', () => {
148
148
  expect(fullJoin._joins).toStrictEqual(fullJoinExpectation);
149
149
  });
150
150
  it('Where', () => {
151
- const query = dist_1.Select(models_1.Person).where(({ age, name }) => dist_1.and(age.eq(person.age), name.like(person.name)));
151
+ const query = (0, dist_1.Select)(models_1.Person).where(({ age, name }) => (0, dist_1.and)(age.eq(person.age), name.like(person.name)));
152
152
  const expectation = [{
153
153
  _operator: 'AND',
154
154
  _operands: [
@@ -160,7 +160,7 @@ describe('Select', () => {
160
160
  });
161
161
  describe('Where filter fields', () => {
162
162
  it('simple many to many', () => {
163
- const query = dist_1.Select(models_1.Person).where(({ profiles }) => profiles.has('test'));
163
+ const query = (0, dist_1.Select)(models_1.Person).where(({ profiles }) => profiles.has('test'));
164
164
  const expectation = [{
165
165
  _operands: [
166
166
  "test",
@@ -189,7 +189,7 @@ describe('Select', () => {
189
189
  expect(query._where).toStrictEqual(expectation);
190
190
  });
191
191
  it('with builder', () => {
192
- const query = dist_1.Select(models_1.Person).where(({ tags }) => tags.has('tag'));
192
+ const query = (0, dist_1.Select)(models_1.Person).where(({ tags }) => tags.has('tag'));
193
193
  const expectation = [{
194
194
  _operands: [
195
195
  "tag",
@@ -198,7 +198,7 @@ describe('Select', () => {
198
198
  _operands: [
199
199
  {
200
200
  _columns: [{ _column: { table: "Tag", name: "name" } }],
201
- _table: builder_1.readModelMeta(models_1.Tag),
201
+ _table: (0, builder_1.readModelMeta)(models_1.Tag),
202
202
  _alias: null,
203
203
  _type: "SELECT",
204
204
  _distinct: false,
@@ -258,12 +258,12 @@ describe('Select', () => {
258
258
  });
259
259
  });
260
260
  it('Having', () => {
261
- const employeeTableName = builder_1.readModelMeta(models_1.Employee).tableName;
261
+ const employeeTableName = (0, builder_1.readModelMeta)(models_1.Employee).tableName;
262
262
  const salaryRate = 2000;
263
- const query = dist_1.Select(models_1.Employee)
264
- .columns(({ salary }) => [dist_1.sum(salary)])
263
+ const query = (0, dist_1.Select)(models_1.Employee)
264
+ .columns(({ salary }) => [(0, dist_1.sum)(salary)])
265
265
  .groupBy(['company'])
266
- .having(({ salary }) => dist_1.sum(salary).gt(salaryRate));
266
+ .having(({ salary }) => (0, dist_1.sum)(salary).gt(salaryRate));
267
267
  const expectation = {
268
268
  _columns: [{ _func: 'SUM', _args: [{ _column: { table: employeeTableName, name: 'salary' } }] }],
269
269
  _groupBy: [{ _column: { table: employeeTableName, name: 'company' } }],
@@ -280,17 +280,17 @@ describe('Select', () => {
280
280
  expect(query._having).toStrictEqual(expectation._having);
281
281
  });
282
282
  it('Group by', () => {
283
- const queryThroughList = dist_1.Select(models_1.Person).groupBy(['city']);
284
- const queryThroughBuilder = dist_1.Select(models_1.Person).groupBy(({ city }) => [city]);
283
+ const queryThroughList = (0, dist_1.Select)(models_1.Person).groupBy(['city']);
284
+ const queryThroughBuilder = (0, dist_1.Select)(models_1.Person).groupBy(({ city }) => [city]);
285
285
  const expectation = [{ _column: { table: tableName, name: 'city' } }];
286
286
  expect(queryThroughList._groupBy).toStrictEqual(expectation);
287
287
  expect(queryThroughBuilder._groupBy).toStrictEqual(expectation);
288
288
  });
289
289
  it('Order By', () => {
290
- const orderByThroughList = dist_1.Select(models_1.Person).orderBy(['city']);
291
- const defaultOrder = dist_1.Select(models_1.Person).orderBy(({ city }) => [city]);
292
- const ascOrder = dist_1.Select(models_1.Person).orderBy(({ city }) => [dist_1.asc(city)]);
293
- const descOrder = dist_1.Select(models_1.Person).orderBy(({ city }) => [dist_1.desc(city)]);
290
+ const orderByThroughList = (0, dist_1.Select)(models_1.Person).orderBy(['city']);
291
+ const defaultOrder = (0, dist_1.Select)(models_1.Person).orderBy(({ city }) => [city]);
292
+ const ascOrder = (0, dist_1.Select)(models_1.Person).orderBy(({ city }) => [(0, dist_1.asc)(city)]);
293
+ const descOrder = (0, dist_1.Select)(models_1.Person).orderBy(({ city }) => [(0, dist_1.desc)(city)]);
294
294
  const expectation = {
295
295
  default: [{ _column: { table: tableName, name: 'city' } }],
296
296
  asc: [{ _column: { table: tableName, name: 'city' }, _order: 'ASC' }],
@@ -303,16 +303,16 @@ describe('Select', () => {
303
303
  });
304
304
  it('Limit', () => {
305
305
  const limit = 10;
306
- const query = dist_1.Select(models_1.Person).limit(limit);
306
+ const query = (0, dist_1.Select)(models_1.Person).limit(limit);
307
307
  expect(query._limit).toBe(limit);
308
308
  });
309
309
  it('Offset', () => {
310
310
  const offset = 3;
311
- const query = dist_1.Select(models_1.Person).offset(offset);
311
+ const query = (0, dist_1.Select)(models_1.Person).offset(offset);
312
312
  expect(query._offset).toBe(offset);
313
313
  });
314
314
  it('subquery on self', () => {
315
- const query = dist_1.Select(models_1.Person).where(({ id }) => dist_2.exists(dist_1.Select(dist_1.alias(models_1.Person, 'person_filter')).where(({ id: _ }) => _.eq(id))));
315
+ const query = (0, dist_1.Select)(models_1.Person).where(({ id }) => (0, dist_2.exists)((0, dist_1.Select)((0, dist_1.alias)(models_1.Person, 'person_filter')).where(({ id: _ }) => _.eq(id))));
316
316
  const expectation = {
317
317
  _where: [{
318
318
  "_operands": [{
@@ -357,24 +357,24 @@ describe('Select', () => {
357
357
  __metadata("design:type", Date)
358
358
  ], PersonAction.prototype, "created", void 0);
359
359
  PersonAction = __decorate([
360
- dist_2.dbTable('actions')
360
+ (0, dist_2.dbTable)('actions')
361
361
  ], PersonAction);
362
362
  const ts = new Date(Date.now() - 3600);
363
- const query = dist_1.Select(models_1.Person)
363
+ const query = (0, dist_1.Select)(models_1.Person)
364
364
  .columns(({ uid }) => [
365
365
  uid,
366
- dist_1.alias(dist_1.Select(PersonAction)
367
- .columns(() => [dist_2.count()])
368
- .where(({ personId, action, created }) => dist_1.and(personId.eq(dist_1.of(models_1.Person, 'id')), action.eq('a'), created.gte(ts)))
366
+ (0, dist_1.alias)((0, dist_1.Select)(PersonAction)
367
+ .columns(() => [(0, dist_2.count)()])
368
+ .where(({ personId, action, created }) => (0, dist_1.and)(personId.eq((0, dist_1.of)(models_1.Person, 'id')), action.eq('a'), created.gte(ts)))
369
369
  .asScalar()
370
- .mul(1).add(dist_1.Select(PersonAction)
371
- .columns(() => [dist_2.count()])
372
- .where(({ personId, action, created }) => dist_1.and(personId.eq(dist_1.of(models_1.Person, 'id')), action.eq('b'), created.gte(ts)))
373
- .asScalar().mul(100)).add(dist_1.Select(PersonAction)
374
- .columns(() => [dist_2.count()])
375
- .where(({ personId, action, created }) => dist_1.and(personId.eq(dist_1.of(models_1.Person, 'id')), action.eq('c'), created.gte(ts)))
370
+ .mul(1).add((0, dist_1.Select)(PersonAction)
371
+ .columns(() => [(0, dist_2.count)()])
372
+ .where(({ personId, action, created }) => (0, dist_1.and)(personId.eq((0, dist_1.of)(models_1.Person, 'id')), action.eq('b'), created.gte(ts)))
373
+ .asScalar().mul(100)).add((0, dist_1.Select)(PersonAction)
374
+ .columns(() => [(0, dist_2.count)()])
375
+ .where(({ personId, action, created }) => (0, dist_1.and)(personId.eq((0, dist_1.of)(models_1.Person, 'id')), action.eq('c'), created.gte(ts)))
376
376
  .asScalar().mul(100)), 'score')
377
- ]).orderBy(() => [dist_1.desc(dist_1.of(null, 'score'))]);
377
+ ]).orderBy(() => [(0, dist_1.desc)((0, dist_1.of)(null, 'score'))]);
378
378
  const expected = [{ "_column": { "table": "Person", "name": "uid" } }, {
379
379
  "_alias": "score", "_operands": [{
380
380
  "_operator": "+", "_operands": [{
@@ -483,7 +483,7 @@ describe('Select', () => {
483
483
  });
484
484
  it('invalid sub queries', () => {
485
485
  try {
486
- dist_1.Select(models_1.Person).columns(['age', 'uid']).asScalar();
486
+ (0, dist_1.Select)(models_1.Person).columns(['age', 'uid']).asScalar();
487
487
  fail('expected to throw');
488
488
  }
489
489
  catch (e) {
@@ -493,12 +493,12 @@ describe('Select', () => {
493
493
  });
494
494
  describe('Insert', () => {
495
495
  it('Check query info', () => {
496
- const query = dist_1.Insert(models_1.Person);
496
+ const query = (0, dist_1.Insert)(models_1.Person);
497
497
  expect(query._type).toBe('INSERT');
498
498
  expect(query._table).toStrictEqual(tableInfo);
499
499
  });
500
500
  it('Insert record', () => {
501
- const query = dist_1.Insert(models_1.Person).values(person);
501
+ const query = (0, dist_1.Insert)(models_1.Person).values(person);
502
502
  const expectation = {
503
503
  id: person.id,
504
504
  name: person.name,
@@ -506,7 +506,7 @@ describe('Insert', () => {
506
506
  city: person.city,
507
507
  };
508
508
  expect(query._values).toStrictEqual(expectation);
509
- dist_1.Insert(models_1.Person).values(Object.assign(Object.assign({}, person), { uid: 'a80ec30e-791c-4499-a243-70af8b2bf7ba' }));
509
+ (0, dist_1.Insert)(models_1.Person).values(Object.assign(Object.assign({}, person), { uid: 'a80ec30e-791c-4499-a243-70af8b2bf7ba' }));
510
510
  });
511
511
  });
512
512
  describe('Upsert', () => {
@@ -514,13 +514,13 @@ describe('Upsert', () => {
514
514
  [dist_1.TableMetadataSymbol]: {}
515
515
  };
516
516
  it('Check query info', () => {
517
- const query = dist_1.Upsert(models_1.Person);
517
+ const query = (0, dist_1.Upsert)(models_1.Person);
518
518
  expect(query._type).toBe('UPSERT');
519
519
  expect(query._table).toStrictEqual(tableInfo);
520
520
  });
521
521
  it('Upsert record', () => {
522
- const defaultUpsert = dist_1.Upsert(models_1.Person).values(person);
523
- const withConflict = dist_1.Upsert(models_1.Person).values(person).conflict('idx');
522
+ const defaultUpsert = (0, dist_1.Upsert)(models_1.Person).values(person);
523
+ const withConflict = (0, dist_1.Upsert)(models_1.Person).values(person).conflict('idx');
524
524
  const expectation = {
525
525
  values: {
526
526
  id: person.id,
@@ -537,29 +537,29 @@ describe('Upsert', () => {
537
537
  });
538
538
  it('Should fail if table has no primary key', () => {
539
539
  expect(() => {
540
- dist_1.Upsert(infoMock).conflict();
540
+ (0, dist_1.Upsert)(infoMock).conflict();
541
541
  }).toThrowError('Current table has no primary key. Please provide unique index for upsert');
542
542
  });
543
543
  it('Should fail if table indexes meta is empty', () => {
544
544
  expect(() => {
545
- dist_1.Upsert(infoMock).conflict('id');
545
+ (0, dist_1.Upsert)(infoMock).conflict('id');
546
546
  }).toThrowError('Table indexes meta is empty');
547
547
  });
548
548
  it('Should fail if index is not declared', () => {
549
549
  expect(() => {
550
- dist_1.Upsert(models_1.Person).conflict('name');
550
+ (0, dist_1.Upsert)(models_1.Person).conflict('name');
551
551
  }).toThrowError(`Index name is not declared for table ${tableName}`);
552
552
  });
553
553
  });
554
554
  describe('Update', () => {
555
555
  it('Check query info', () => {
556
- const query = dist_1.Update(models_1.Person);
556
+ const query = (0, dist_1.Update)(models_1.Person);
557
557
  expect(query._type).toBe('UPDATE');
558
558
  expect(query._table).toStrictEqual(tableInfo);
559
559
  });
560
560
  it('Update record', () => {
561
561
  const limit = 10;
562
- const query = dist_1.Update(models_1.Person).values(person).where(({ id }) => id.eq(person.id)).limit(limit);
562
+ const query = (0, dist_1.Update)(models_1.Person).values(person).where(({ id }) => id.eq(person.id)).limit(limit);
563
563
  const expectation = {
564
564
  values: {
565
565
  id: person.id,
@@ -579,13 +579,13 @@ describe('Update', () => {
579
579
  });
580
580
  describe('Delete', () => {
581
581
  it('Check query info', () => {
582
- const query = dist_1.Delete(models_1.Person);
582
+ const query = (0, dist_1.Delete)(models_1.Person);
583
583
  expect(query._type).toBe('DELETE');
584
584
  expect(query._table).toStrictEqual(tableInfo);
585
585
  });
586
586
  it('Delete record', () => {
587
587
  const limit = 10;
588
- const query = dist_1.Delete(models_1.Person).where(({ id }) => id.eq(person.id)).limit(limit);
588
+ const query = (0, dist_1.Delete)(models_1.Person).where(({ id }) => id.eq(person.id)).limit(limit);
589
589
  const expectation = [{
590
590
  _operator: '=',
591
591
  _operands: [{ _column: { table: tableName, name: 'id' } }, person.id]
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const wrappers_1 = require("../src/wrappers");
13
+ const test_driver_1 = require("../src/test-driver");
14
+ describe('BaseExecutor', () => {
15
+ it('named params', () => __awaiter(void 0, void 0, void 0, function* () {
16
+ const sqlName = 'test';
17
+ const namedParam = new wrappers_1.NamedParameter(sqlName);
18
+ const executor = new test_driver_1.TestExecutor();
19
+ executor.mapper = (query) => {
20
+ expect(query).toBeDefined();
21
+ expect(query.params).toBeDefined();
22
+ expect(query.params[sqlName]).toBe(123);
23
+ return [];
24
+ };
25
+ executor.setNamedParameter(namedParam, 123);
26
+ yield executor.execute({});
27
+ }));
28
+ });
@@ -0,0 +1,24 @@
1
+ import {NamedParameter} from "../src/wrappers";
2
+ import {TestExecutor} from "../src/test-driver";
3
+
4
+ describe('BaseExecutor', () => {
5
+
6
+ it('named params', async () => {
7
+ const sqlName = 'test';
8
+ const namedParam = new NamedParameter(sqlName);
9
+
10
+ const executor = new TestExecutor();
11
+
12
+ executor.mapper = (query) => {
13
+ expect(query).toBeDefined()
14
+ expect(query.params).toBeDefined()
15
+ expect(query.params[sqlName]).toBe(123)
16
+ return []
17
+ }
18
+
19
+ executor.setNamedParameter(namedParam, 123)
20
+
21
+ await executor.execute({});
22
+ });
23
+
24
+ })
package/tests/models.js CHANGED
@@ -15,14 +15,14 @@ const UUID = {};
15
15
  let Person = class Person {
16
16
  };
17
17
  __decorate([
18
- src_1.dbField({
18
+ (0, src_1.dbField)({
19
19
  primaryKey: true,
20
20
  autoIncrement: true
21
21
  }),
22
22
  __metadata("design:type", Number)
23
23
  ], Person.prototype, "id", void 0);
24
24
  __decorate([
25
- src_1.dbField({
25
+ (0, src_1.dbField)({
26
26
  kind: UUID
27
27
  }),
28
28
  __metadata("design:type", String)
@@ -40,7 +40,7 @@ __decorate([
40
40
  __metadata("design:type", String)
41
41
  ], Person.prototype, "city", void 0);
42
42
  __decorate([
43
- src_1.dbFilterField({
43
+ (0, src_1.dbFilterField)({
44
44
  table: 'employee',
45
45
  keyField: 'person',
46
46
  valueField: 'title',
@@ -48,19 +48,19 @@ __decorate([
48
48
  __metadata("design:type", Array)
49
49
  ], Person.prototype, "profiles", void 0);
50
50
  __decorate([
51
- src_1.dbFilterField(primary => src_1.Select(Tag)
51
+ (0, src_1.dbFilterField)(primary => (0, src_1.Select)(Tag)
52
52
  .columns((x) => [x.name])
53
- .join(TagPerson, (a, b) => src_1.and(a.id.eq(b.tag), b.person.eq(primary)))),
53
+ .join(TagPerson, (a, b) => (0, src_1.and)(a.id.eq(b.tag), b.person.eq(primary)))),
54
54
  __metadata("design:type", Array)
55
55
  ], Person.prototype, "tags", void 0);
56
56
  Person = __decorate([
57
- src_1.dbTable('Person', [{ name: 'idx', fields: ['id'] }])
57
+ (0, src_1.dbTable)('Person', [{ name: 'idx', fields: ['id'] }])
58
58
  ], Person);
59
59
  exports.Person = Person;
60
60
  let Tag = class Tag {
61
61
  };
62
62
  __decorate([
63
- src_1.dbField({
63
+ (0, src_1.dbField)({
64
64
  primaryKey: true,
65
65
  autoIncrement: true
66
66
  }),
@@ -71,25 +71,25 @@ __decorate([
71
71
  __metadata("design:type", String)
72
72
  ], Tag.prototype, "name", void 0);
73
73
  Tag = __decorate([
74
- src_1.dbTable('Tag')
74
+ (0, src_1.dbTable)('Tag')
75
75
  ], Tag);
76
76
  exports.Tag = Tag;
77
77
  let TagPerson = class TagPerson {
78
78
  };
79
79
  __decorate([
80
- src_1.dbField({
80
+ (0, src_1.dbField)({
81
81
  primaryKey: true,
82
82
  }),
83
83
  __metadata("design:type", Number)
84
84
  ], TagPerson.prototype, "person", void 0);
85
85
  __decorate([
86
- src_1.dbField({
86
+ (0, src_1.dbField)({
87
87
  primaryKey: true,
88
88
  }),
89
89
  __metadata("design:type", Number)
90
90
  ], TagPerson.prototype, "tag", void 0);
91
91
  TagPerson = __decorate([
92
- src_1.dbTable('TagPerson')
92
+ (0, src_1.dbTable)('TagPerson')
93
93
  ], TagPerson);
94
94
  exports.TagPerson = TagPerson;
95
95
  let Employee = class Employee {
@@ -107,6 +107,6 @@ __decorate([
107
107
  __metadata("design:type", Number)
108
108
  ], Employee.prototype, "salary", void 0);
109
109
  Employee = __decorate([
110
- src_1.dbTable('Employee')
110
+ (0, src_1.dbTable)('Employee')
111
111
  ], Employee);
112
112
  exports.Employee = Employee;
@@ -36,7 +36,7 @@ function generatePersons(quantity) {
36
36
  describe('DbReader', () => {
37
37
  const persons = generatePersons(5);
38
38
  it('read raw', () => {
39
- const result = dist_1.reader(persons);
39
+ const result = (0, dist_1.reader)(persons);
40
40
  expect(result).toStrictEqual(persons);
41
41
  result.map(person => {
42
42
  expect(person).toBeInstanceOf(models_1.Person);
@@ -56,11 +56,11 @@ describe('DbReader', () => {
56
56
  __metadata("design:type", Number)
57
57
  ], Model.prototype, "id", void 0);
58
58
  __decorate([
59
- dist_1.dbField('raw'),
59
+ (0, dist_1.dbField)('raw'),
60
60
  __metadata("design:type", String)
61
61
  ], Model.prototype, "value", void 0);
62
62
  __decorate([
63
- dist_1.dbField({ kind: DB_JSON, model: [models_1.Person] }),
63
+ (0, dist_1.dbField)({ kind: DB_JSON, model: [models_1.Person] }),
64
64
  __metadata("design:type", Array)
65
65
  ], Model.prototype, "personal", void 0);
66
66
  Model = __decorate([
@@ -73,7 +73,7 @@ describe('DbReader', () => {
73
73
  personal: JSON.stringify(persons)
74
74
  };
75
75
  const expected = new Model(5, 'false', persons);
76
- const results = dist_1.reader([model], Model);
76
+ const results = (0, dist_1.reader)([model], Model);
77
77
  expect(results.length).toBe(1);
78
78
  const [result] = results;
79
79
  expect(result).toBeInstanceOf(Model);
@@ -92,37 +92,37 @@ describe('DbReader', () => {
92
92
  __metadata("design:type", Number)
93
93
  ], Model.prototype, "id", void 0);
94
94
  __decorate([
95
- dist_1.dbField('raw'),
95
+ (0, dist_1.dbField)('raw'),
96
96
  __metadata("design:type", String)
97
97
  ], Model.prototype, "value", void 0);
98
98
  __decorate([
99
- dist_1.dbField({ kind: DB_JSON, model: [models_1.Person] }),
99
+ (0, dist_1.dbField)({ kind: DB_JSON, model: [models_1.Person] }),
100
100
  __metadata("design:type", Array)
101
101
  ], Model.prototype, "personal", void 0);
102
102
  Model = __decorate([
103
103
  dist_1.dbTable,
104
104
  __metadata("design:paramtypes", [Object, Object, Object])
105
105
  ], Model);
106
- const results = dist_1.reader([], Model);
106
+ const results = (0, dist_1.reader)([], Model);
107
107
  expect(results.length).toBe(0);
108
108
  });
109
109
  it('read scalar', () => {
110
110
  const count = 10;
111
- const correctResult = dist_1.reader([{ field: count }], true);
111
+ const correctResult = (0, dist_1.reader)([{ field: count }], true);
112
112
  expect(correctResult).toBe(count);
113
113
  });
114
114
  it('read scalar from no data', () => {
115
115
  const fieldValue = 'string';
116
- const emptyData = dist_1.reader([], true);
116
+ const emptyData = (0, dist_1.reader)([], true);
117
117
  expect(emptyData).toBe(0);
118
118
  expect(() => {
119
- dist_1.reader([{ field: fieldValue }], true);
119
+ (0, dist_1.reader)([{ field: fieldValue }], true);
120
120
  }).toThrowError(`Invalid scalar "${fieldValue}", number expected.`);
121
121
  });
122
122
  it('read scalar from invalid data', () => {
123
123
  const fieldValue = 'string';
124
124
  expect(() => {
125
- dist_1.reader([{ field: fieldValue }], true);
125
+ (0, dist_1.reader)([{ field: fieldValue }], true);
126
126
  }).toThrowError(`Invalid scalar "${fieldValue}", number expected.`);
127
127
  });
128
128
  });