drizzle-orm 0.10.39 → 0.10.42

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.
Files changed (61) hide show
  1. package/builders/aggregators/deleteAggregator.js +1 -1
  2. package/builders/aggregators/insertAggregator.js +5 -2
  3. package/builders/aggregators/selectAggregator.js +1 -1
  4. package/builders/aggregators/updateAggregator.js +5 -2
  5. package/builders/highLvlBuilders/deleteRequestBuilder.js +1 -1
  6. package/builders/highLvlBuilders/insertRequestBuilder.js +1 -1
  7. package/builders/highLvlBuilders/selectRequestBuilder.js +2 -1
  8. package/builders/highLvlBuilders/updateRequestBuilder.js +2 -2
  9. package/builders/joinBuilders/builders/abstractJoinBuilder.js +1 -3
  10. package/builders/requestBuilders/updates/combine.d.ts +5 -1
  11. package/builders/requestBuilders/updates/combine.js +2 -2
  12. package/builders/requestBuilders/updates/increment.d.ts +5 -1
  13. package/builders/requestBuilders/updates/increment.js +1 -1
  14. package/builders/requestBuilders/updates/setObjects.d.ts +5 -1
  15. package/builders/requestBuilders/updates/setObjects.js +2 -2
  16. package/builders/requestBuilders/updates/updates.d.ts +5 -1
  17. package/builders/requestBuilders/updates/updates.js +0 -1
  18. package/builders/requestBuilders/where/and.d.ts +8 -3
  19. package/builders/requestBuilders/where/and.js +2 -2
  20. package/builders/requestBuilders/where/const.d.ts +8 -1
  21. package/builders/requestBuilders/where/const.js +4 -5
  22. package/builders/requestBuilders/where/constArray.d.ts +8 -1
  23. package/builders/requestBuilders/where/constArray.js +4 -4
  24. package/builders/requestBuilders/where/eqWhere.d.ts +8 -3
  25. package/builders/requestBuilders/where/eqWhere.js +3 -3
  26. package/builders/requestBuilders/where/greater.d.ts +8 -3
  27. package/builders/requestBuilders/where/greater.js +3 -3
  28. package/builders/requestBuilders/where/greaterEq.d.ts +8 -3
  29. package/builders/requestBuilders/where/greaterEq.js +3 -3
  30. package/builders/requestBuilders/where/in.d.ts +8 -3
  31. package/builders/requestBuilders/where/in.js +3 -3
  32. package/builders/requestBuilders/where/isNotNull.d.ts +8 -3
  33. package/builders/requestBuilders/where/isNotNull.js +2 -2
  34. package/builders/requestBuilders/where/isNull.d.ts +8 -3
  35. package/builders/requestBuilders/where/isNull.js +2 -2
  36. package/builders/requestBuilders/where/less.d.ts +8 -3
  37. package/builders/requestBuilders/where/less.js +3 -3
  38. package/builders/requestBuilders/where/lessEq.d.ts +8 -3
  39. package/builders/requestBuilders/where/lessEq.js +3 -3
  40. package/builders/requestBuilders/where/like.d.ts +8 -3
  41. package/builders/requestBuilders/where/like.js +3 -3
  42. package/builders/requestBuilders/where/notEqWhere.d.ts +8 -3
  43. package/builders/requestBuilders/where/notEqWhere.js +3 -3
  44. package/builders/requestBuilders/where/or.d.ts +8 -3
  45. package/builders/requestBuilders/where/or.js +2 -2
  46. package/builders/requestBuilders/where/rawWhere.d.ts +8 -1
  47. package/builders/requestBuilders/where/rawWhere.js +1 -1
  48. package/builders/requestBuilders/where/var.d.ts +8 -3
  49. package/builders/requestBuilders/where/var.js +1 -1
  50. package/builders/requestBuilders/where/where.d.ts +7 -2
  51. package/builders/requestBuilders/where/where.js +0 -1
  52. package/db/session.d.ts +3 -0
  53. package/db/session.js +6 -0
  54. package/errors/builderError.d.ts +2 -1
  55. package/errors/builderError.js +3 -3
  56. package/index.d.ts +2 -0
  57. package/index.js +2 -0
  58. package/migrator/migrator.js +4 -0
  59. package/package.json +1 -1
  60. package/test.d.ts +0 -1
  61. package/test.js +103 -63
@@ -13,7 +13,7 @@ class DeleteAggregator extends abstractAggregator_1.default {
13
13
  this._delete = ['DELETE'];
14
14
  this.filters = (filters) => {
15
15
  if (filters) {
16
- const filterQuery = filters.toQuery();
16
+ const filterQuery = filters.toQuery({ session: this._table.db.session() });
17
17
  this._filters.push('WHERE ');
18
18
  this._filters.push(filterQuery.query);
19
19
  this._values = filterQuery.values;
@@ -43,7 +43,7 @@ class InsertAggregator extends abstractAggregator_1.default {
43
43
  if (isKeyExistsInValue) {
44
44
  if (valueToInsert !== undefined && valueToInsert !== null) {
45
45
  position += 1;
46
- this._query.push(`$${position}`);
46
+ this._query.push(this._table.db.session().parametrized(position));
47
47
  this._values.push(column.getColumnType().insertStrategy(valueToInsert));
48
48
  }
49
49
  else {
@@ -73,7 +73,10 @@ class InsertAggregator extends abstractAggregator_1.default {
73
73
  if (updates) {
74
74
  const currentPointerPosition = this._values.length > 0
75
75
  ? this._values.length + 1 : undefined;
76
- const updatesQuery = updates.toQuery(currentPointerPosition);
76
+ const updatesQuery = updates.toQuery({
77
+ position: currentPointerPosition,
78
+ session: this._table.db.session(),
79
+ });
77
80
  this._onConflict.push('DO UPDATE\n');
78
81
  this._onConflict.push(`SET ${updatesQuery.query}`);
79
82
  this._values.push(...updatesQuery.values);
@@ -24,7 +24,7 @@ class SelectAggregator extends abstractAggregator_1.default {
24
24
  this._joinCache = {};
25
25
  this.filters = (filters) => {
26
26
  if (filters) {
27
- const queryBuilder = filters.toQuery(1, this._joinCache);
27
+ const queryBuilder = filters.toQuery({ position: 1, tableCache: this._joinCache, session: this._table.db.session() });
28
28
  this._filters.push('WHERE ');
29
29
  this._filters.push(queryBuilder.query);
30
30
  this._values = queryBuilder.values;
@@ -15,7 +15,10 @@ class UpdateAggregator extends abstractAggregator_1.default {
15
15
  this.where = (filters) => {
16
16
  if (filters) {
17
17
  const currentPointerPosition = this._values.length > 0 ? this._values.length + 1 : undefined;
18
- const filterQuery = filters.toQuery(currentPointerPosition);
18
+ const filterQuery = filters.toQuery({
19
+ position: currentPointerPosition,
20
+ session: this._table.db.session(),
21
+ });
19
22
  this._filters.push('WHERE ');
20
23
  this._filters.push(filterQuery.query);
21
24
  this._values.push(...filterQuery.values);
@@ -28,7 +31,7 @@ class UpdateAggregator extends abstractAggregator_1.default {
28
31
  return this;
29
32
  };
30
33
  this.set = (updates) => {
31
- const setQuery = updates.toQuery();
34
+ const setQuery = updates.toQuery({ session: this._table.db.session() });
32
35
  this._updates.push(`\nSET ${setQuery.query}`);
33
36
  this._values.push(...setQuery.values);
34
37
  return this;
@@ -48,7 +48,7 @@ class DeleteTRB extends abstractRequestBuilder_1.default {
48
48
  values = builderResult.values;
49
49
  }
50
50
  catch (e) {
51
- throw new builderError_1.default(builderError_1.BuilderType.DELETE, this._table.tableName(), this._columns, e, this._filter);
51
+ throw new builderError_1.default(builderError_1.BuilderType.DELETE, this._table.tableName(), this._columns, e, this._session, this._filter);
52
52
  }
53
53
  if (this._logger) {
54
54
  this._logger.info(`Deleting from ${this._table.tableName()} using query:\n ${query}`);
@@ -59,7 +59,7 @@ class InsertTRB extends abstractRequestBuilder_1.default {
59
59
  values = builderResult.values;
60
60
  }
61
61
  catch (e) {
62
- throw new builderError_1.default(builderError_1.BuilderType.INSERT, this._table.tableName(), this._columns, e);
62
+ throw new builderError_1.default(builderError_1.BuilderType.INSERT, this._table.tableName(), this._columns, e, this._session);
63
63
  }
64
64
  if (this._logger) {
65
65
  this._logger.info(`Inserting to ${this._table.tableName()} using query:\n ${query}\n${values}`);
@@ -68,10 +68,11 @@ class SelectTRB extends abstractRequestBuilder_1.default {
68
68
  values = builderResult.values;
69
69
  }
70
70
  catch (e) {
71
- throw new builderError_1.default(builderError_1.BuilderType.SELECT, this._table.tableName(), this._columns, e, this._filter);
71
+ throw new builderError_1.default(builderError_1.BuilderType.SELECT, this._table.tableName(), this._columns, e, this._session, this._filter);
72
72
  }
73
73
  if (this._logger) {
74
74
  this._logger.info(`Selecting from ${this._table.tableName()} using query:\n ${query}`);
75
+ this._logger.info(`Values for query:\n ${values}`);
75
76
  }
76
77
  const result = await this._session.execute(query, values);
77
78
  if (this.__partial) {
@@ -66,11 +66,11 @@ class UpdateTRB extends abstractRequestBuilder_1.default {
66
66
  values = builderResult.values;
67
67
  }
68
68
  catch (e) {
69
- throw new builderError_1.default(builderError_1.BuilderType.UPDATE, this._table.tableName(), this._columns, e, this._filter);
69
+ throw new builderError_1.default(builderError_1.BuilderType.UPDATE, this._table.tableName(), this._columns, e, this._session, this._filter);
70
70
  }
71
71
  if (this._logger) {
72
72
  this._logger.info(`Updating ${this._table.tableName()} using query:\n ${query}`);
73
- console.log(values);
73
+ this._logger.info(`Values used for update:\n ${values}`);
74
74
  }
75
75
  const result = await this._session.execute(query, values);
76
76
  return responseMapper_1.default.map(this._mappedServiceToDb, result);
@@ -52,10 +52,8 @@ class AbstractJoined {
52
52
  values = builderResult.values;
53
53
  }
54
54
  catch (e) {
55
- throw new builderError_1.default(builderError_1.BuilderType.JOINED_SELECT, this._table.tableName(), Object.values(this._table.mapServiceToDb()), e, this._filter);
55
+ throw new builderError_1.default(builderError_1.BuilderType.JOINED_SELECT, this._table.tableName(), Object.values(this._table.mapServiceToDb()), e, this._session, this._filter);
56
56
  }
57
- console.log(query);
58
- console.log(values);
59
57
  const result = await this._session.execute(query, values);
60
58
  return this.mapResponse(result);
61
59
  };
@@ -1,8 +1,12 @@
1
1
  import { UpdateExpr } from './updates';
2
+ import { ISession } from '../../../db/session';
2
3
  export default class Combine extends UpdateExpr {
3
4
  private _setters;
4
5
  constructor(setters: Array<UpdateExpr>);
5
- toQuery: (position?: number | undefined) => {
6
+ toQuery: ({ position, session, }: {
7
+ position?: number | undefined;
8
+ session: ISession;
9
+ }) => {
6
10
  query: string;
7
11
  values: Array<any>;
8
12
  };
@@ -4,13 +4,13 @@ const updates_1 = require("./updates");
4
4
  class Combine extends updates_1.UpdateExpr {
5
5
  constructor(setters) {
6
6
  super();
7
- this.toQuery = (position) => {
7
+ this.toQuery = ({ position, session, }) => {
8
8
  let nextPosition = position || 1;
9
9
  const response = [];
10
10
  const valuesResult = [];
11
11
  for (let index = 0; index < this._setters.length; index += 1) {
12
12
  const setter = this._setters[index];
13
- const expressionResult = setter.toQuery(nextPosition);
13
+ const expressionResult = setter.toQuery({ position: nextPosition, session });
14
14
  valuesResult.push(...expressionResult.values);
15
15
  response.push(expressionResult.query);
16
16
  nextPosition += expressionResult.values.length;
@@ -1,12 +1,16 @@
1
1
  import { AbstractColumn } from '../../../columns/column';
2
2
  import ColumnType from '../../../columns/types/columnType';
3
3
  import { UpdateCustomExpr } from './updates';
4
+ import { ISession } from '../../../db/session';
4
5
  export default class Increment<T extends AbstractColumn<ColumnType<any>, boolean, boolean>> extends UpdateCustomExpr<T> {
5
6
  private _column;
6
7
  private _value;
7
8
  constructor(value: number);
8
9
  setColumn: (column: T) => UpdateCustomExpr<T>;
9
- toQuery: () => {
10
+ toQuery: ({ position, session, }: {
11
+ position?: number | undefined;
12
+ session: ISession;
13
+ }) => {
10
14
  query: string;
11
15
  values: Array<any>;
12
16
  };
@@ -8,7 +8,7 @@ class Increment extends updates_1.UpdateCustomExpr {
8
8
  this._column = column;
9
9
  return this;
10
10
  };
11
- this.toQuery = () => {
11
+ this.toQuery = ({ position, session, }) => {
12
12
  const query = `${this._column.getColumnName()} = ${this._column.getColumnName()} + ${this._value}`;
13
13
  return { query, values: [] };
14
14
  };
@@ -1,11 +1,15 @@
1
1
  import { AbstractColumn } from '../../../columns/column';
2
2
  import ColumnType from '../../../columns/types/columnType';
3
3
  import { UpdateExpr } from './updates';
4
+ import { ISession } from '../../../db/session';
4
5
  export default class SetObject<T extends AbstractColumn<ColumnType<any>, boolean, boolean>> extends UpdateExpr {
5
6
  private _column;
6
7
  private _value;
7
8
  constructor(column: T, value: any);
8
- toQuery: (position?: number | undefined) => {
9
+ toQuery: ({ position, session, }: {
10
+ position?: number | undefined;
11
+ session: ISession;
12
+ }) => {
9
13
  query: string;
10
14
  values: Array<any>;
11
15
  };
@@ -4,12 +4,12 @@ const updates_1 = require("./updates");
4
4
  class SetObject extends updates_1.UpdateExpr {
5
5
  constructor(column, value) {
6
6
  super();
7
- this.toQuery = (position) => {
7
+ this.toQuery = ({ position, session, }) => {
8
8
  const nextPosition = position || 1;
9
9
  const valueToInsert = this._value === null || this._value === undefined
10
10
  ? this._value
11
11
  : this._column.getColumnType().insertStrategy(this._value);
12
- const query = `"${this._column.getColumnName()}"=$${nextPosition}`;
12
+ const query = `"${this._column.getColumnName()}"=${session.parametrized(nextPosition)}`;
13
13
  return { query, values: [valueToInsert] };
14
14
  };
15
15
  this._column = column;
@@ -1,5 +1,9 @@
1
+ import { ISession } from '../../../db/session';
1
2
  export declare abstract class UpdateExpr {
2
- abstract toQuery(position?: number): {
3
+ abstract toQuery({ position, session, }: {
4
+ position?: number;
5
+ session: ISession;
6
+ }): {
3
7
  query: string;
4
8
  values: Array<any>;
5
9
  };
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UpdateCustomExpr = exports.UpdateExpr = void 0;
4
- /* eslint-disable max-classes-per-file */
5
4
  class UpdateExpr {
6
5
  }
7
6
  exports.UpdateExpr = UpdateExpr;
@@ -1,10 +1,15 @@
1
1
  import Expr from './where';
2
+ import { ISession } from '../../../db/session';
2
3
  export default class And extends Expr {
3
4
  private expressions;
4
5
  constructor(expressions: Expr[]);
5
- toQuery: (position?: number | undefined, tableCache?: {
6
- [tableName: string]: string;
7
- } | undefined) => {
6
+ toQuery: ({ position, tableCache, session, }: {
7
+ position?: number | undefined;
8
+ tableCache?: {
9
+ [tableName: string]: string;
10
+ } | undefined;
11
+ session: ISession;
12
+ }) => {
8
13
  query: string;
9
14
  values: Array<any>;
10
15
  };
@@ -8,13 +8,13 @@ const where_1 = __importDefault(require("./where"));
8
8
  class And extends where_1.default {
9
9
  constructor(expressions) {
10
10
  super();
11
- this.toQuery = (position, tableCache) => {
11
+ this.toQuery = ({ position, tableCache, session, }) => {
12
12
  let nextPosition = position || 1;
13
13
  const result = ['('];
14
14
  const valuesResult = [];
15
15
  for (let i = 0; i < this.expressions.length; i += 1) {
16
16
  const expression = this.expressions[i];
17
- const expressionResult = expression.toQuery(nextPosition, tableCache);
17
+ const expressionResult = expression.toQuery({ position: nextPosition, tableCache, session });
18
18
  valuesResult.push(...expressionResult.values);
19
19
  result.push(expressionResult.query);
20
20
  nextPosition += expressionResult.values.length;
@@ -1,8 +1,15 @@
1
+ import { ISession } from '../../../db/session';
1
2
  import Expr from './where';
2
3
  export default class Const extends Expr {
3
4
  private value;
4
5
  constructor(value: any);
5
- toQuery: (position?: number | undefined) => {
6
+ toQuery: ({ position, tableCache, session, }: {
7
+ position?: number | undefined;
8
+ tableCache?: {
9
+ [tableName: string]: string;
10
+ } | undefined;
11
+ session: ISession;
12
+ }) => {
6
13
  query: string;
7
14
  values: Array<any>;
8
15
  };
@@ -3,21 +3,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- /* eslint-disable no-return-assign */
7
6
  const ecranate_1 = require("../../../utils/ecranate");
8
7
  const where_1 = __importDefault(require("./where"));
9
8
  class Const extends where_1.default {
10
9
  constructor(value) {
11
10
  super();
12
- this.toQuery = (position) => {
11
+ this.toQuery = ({ position, tableCache, session, }) => {
13
12
  const nextPosition = position || 1;
14
13
  if (this.value instanceof Date) {
15
- return { query: `$${nextPosition}`, values: [`${this.value.toISOString()}`] };
14
+ return { query: session.parametrized(nextPosition), values: [`${this.value.toISOString()}`] };
16
15
  }
17
16
  if (ecranate_1.shouldEcranate(this.value)) {
18
- return { query: `$${nextPosition}`, values: [`${this.value.toString()}`] };
17
+ return { query: session.parametrized(nextPosition), values: [`${this.value.toString()}`] };
19
18
  }
20
- return { query: `$${nextPosition}`, values: [this.value] };
19
+ return { query: session.parametrized(nextPosition), values: [this.value] };
21
20
  };
22
21
  this.value = value;
23
22
  }
@@ -1,8 +1,15 @@
1
1
  import Expr from './where';
2
+ import { ISession } from '../../../db/session';
2
3
  export default class ConstArray extends Expr {
3
4
  private values;
4
5
  constructor(values: Array<any>);
5
- toQuery: (position?: number | undefined) => {
6
+ toQuery: ({ position, tableCache, session, }: {
7
+ position?: number | undefined;
8
+ tableCache?: {
9
+ [tableName: string]: string;
10
+ } | undefined;
11
+ session: ISession;
12
+ }) => {
6
13
  query: string;
7
14
  values: Array<any>;
8
15
  };
@@ -8,22 +8,22 @@ const where_1 = __importDefault(require("./where"));
8
8
  class ConstArray extends where_1.default {
9
9
  constructor(values) {
10
10
  super();
11
- this.toQuery = (position) => {
11
+ this.toQuery = ({ position, tableCache, session, }) => {
12
12
  let nextPosition = position || 1;
13
13
  const finalArray = [];
14
14
  const finalValues = [];
15
15
  for (let i = 0; i < this.values.length; i += 1) {
16
16
  const value = this.values[i];
17
17
  if (value instanceof Date) {
18
- finalArray.push(`$${nextPosition}`);
18
+ finalArray.push(session.parametrized(nextPosition));
19
19
  finalValues.push(`${value.toISOString()}`);
20
20
  }
21
21
  else if (ecranate_1.shouldEcranate(value)) {
22
- finalArray.push(`$${nextPosition}`);
22
+ finalArray.push(session.parametrized(nextPosition));
23
23
  finalValues.push(`${value.toString()}`);
24
24
  }
25
25
  else {
26
- finalArray.push(`$${nextPosition}`);
26
+ finalArray.push(session.parametrized(nextPosition));
27
27
  finalValues.push(value);
28
28
  }
29
29
  if (i < this.values.length - 1) {
@@ -1,11 +1,16 @@
1
1
  import Expr from './where';
2
+ import { ISession } from '../../../db/session';
2
3
  export default class EqWhere extends Expr {
3
4
  private left;
4
5
  private right;
5
6
  constructor(left: Expr, right: Expr);
6
- toQuery: (position?: number | undefined, tableCache?: {
7
- [tableName: string]: string;
8
- } | undefined) => {
7
+ toQuery: ({ position, tableCache, session, }: {
8
+ position?: number | undefined;
9
+ tableCache?: {
10
+ [tableName: string]: string;
11
+ } | undefined;
12
+ session: ISession;
13
+ }) => {
9
14
  query: string;
10
15
  values: Array<any>;
11
16
  };
@@ -8,9 +8,9 @@ const where_1 = __importDefault(require("./where"));
8
8
  class EqWhere extends where_1.default {
9
9
  constructor(left, right) {
10
10
  super();
11
- this.toQuery = (position, tableCache) => {
12
- const rightPreparedValues = this.right.toQuery(position, tableCache);
13
- const leftPreparedValues = this.left.toQuery(position, tableCache);
11
+ this.toQuery = ({ position, tableCache, session, }) => {
12
+ const rightPreparedValues = this.right.toQuery({ position, tableCache, session });
13
+ const leftPreparedValues = this.left.toQuery({ position, tableCache, session });
14
14
  return { query: `${leftPreparedValues.query}=${rightPreparedValues.query}`, values: [...leftPreparedValues.values, ...rightPreparedValues.values] };
15
15
  };
16
16
  this.left = left;
@@ -1,4 +1,5 @@
1
1
  import Expr from './where';
2
+ import { ISession } from '../../../db/session';
2
3
  export default class Greater extends Expr {
3
4
  private left;
4
5
  private right;
@@ -6,9 +7,13 @@ export default class Greater extends Expr {
6
7
  left: Expr;
7
8
  right: Expr;
8
9
  });
9
- toQuery: (position: number, tableCache?: {
10
- [tableName: string]: string;
11
- } | undefined) => {
10
+ toQuery: ({ position, tableCache, session, }: {
11
+ position?: number | undefined;
12
+ tableCache?: {
13
+ [tableName: string]: string;
14
+ } | undefined;
15
+ session: ISession;
16
+ }) => {
12
17
  query: string;
13
18
  values: Array<any>;
14
19
  };
@@ -8,9 +8,9 @@ const where_1 = __importDefault(require("./where"));
8
8
  class Greater extends where_1.default {
9
9
  constructor({ left, right }) {
10
10
  super();
11
- this.toQuery = (position, tableCache) => {
12
- const rightPreparedValues = this.right.toQuery(position, tableCache);
13
- const leftPreparedValues = this.left.toQuery(position, tableCache);
11
+ this.toQuery = ({ position, tableCache, session, }) => {
12
+ const rightPreparedValues = this.right.toQuery({ position, tableCache, session });
13
+ const leftPreparedValues = this.left.toQuery({ position, tableCache, session });
14
14
  return { query: `${leftPreparedValues.query} > ${rightPreparedValues.query}`, values: [...leftPreparedValues.values, ...rightPreparedValues.values] };
15
15
  };
16
16
  this.left = left;
@@ -1,4 +1,5 @@
1
1
  import Expr from './where';
2
+ import { ISession } from '../../../db/session';
2
3
  export default class GreaterEq extends Expr {
3
4
  private left;
4
5
  private right;
@@ -6,9 +7,13 @@ export default class GreaterEq extends Expr {
6
7
  left: Expr;
7
8
  right: Expr;
8
9
  });
9
- toQuery: (position: number, tableCache?: {
10
- [tableName: string]: string;
11
- } | undefined) => {
10
+ toQuery: ({ position, tableCache, session, }: {
11
+ position?: number | undefined;
12
+ tableCache?: {
13
+ [tableName: string]: string;
14
+ } | undefined;
15
+ session: ISession;
16
+ }) => {
12
17
  query: string;
13
18
  values: Array<any>;
14
19
  };
@@ -8,9 +8,9 @@ const where_1 = __importDefault(require("./where"));
8
8
  class GreaterEq extends where_1.default {
9
9
  constructor({ left, right }) {
10
10
  super();
11
- this.toQuery = (position, tableCache) => {
12
- const rightPreparedValues = this.right.toQuery(position, tableCache);
13
- const leftPreparedValues = this.left.toQuery(position, tableCache);
11
+ this.toQuery = ({ position, tableCache, session, }) => {
12
+ const rightPreparedValues = this.right.toQuery({ position, tableCache, session });
13
+ const leftPreparedValues = this.left.toQuery({ position, tableCache, session });
14
14
  return { query: `${leftPreparedValues.query} >= ${rightPreparedValues.query}`, values: [...leftPreparedValues.values, ...rightPreparedValues.values] };
15
15
  };
16
16
  this.left = left;
@@ -1,11 +1,16 @@
1
1
  import Expr from './where';
2
+ import { ISession } from '../../../db/session';
2
3
  export default class In extends Expr {
3
4
  private left;
4
5
  private right;
5
6
  constructor(left: Expr, right: Expr);
6
- toQuery: (position?: number | undefined, tableCache?: {
7
- [tableName: string]: string;
8
- } | undefined) => {
7
+ toQuery: ({ position, tableCache, session, }: {
8
+ position?: number | undefined;
9
+ tableCache?: {
10
+ [tableName: string]: string;
11
+ } | undefined;
12
+ session: ISession;
13
+ }) => {
9
14
  query: string;
10
15
  values: Array<any>;
11
16
  };
@@ -8,9 +8,9 @@ const where_1 = __importDefault(require("./where"));
8
8
  class In extends where_1.default {
9
9
  constructor(left, right) {
10
10
  super();
11
- this.toQuery = (position, tableCache) => {
12
- const rightPreparedValues = this.right.toQuery(position, tableCache);
13
- const leftPreparedValues = this.left.toQuery(position, tableCache);
11
+ this.toQuery = ({ position, tableCache, session, }) => {
12
+ const rightPreparedValues = this.right.toQuery({ position, tableCache, session });
13
+ const leftPreparedValues = this.left.toQuery({ position, tableCache, session });
14
14
  return { query: `${leftPreparedValues.query} in (${rightPreparedValues.query})`, values: [...leftPreparedValues.values, ...rightPreparedValues.values] };
15
15
  };
16
16
  this.left = left;
@@ -1,10 +1,15 @@
1
1
  import Expr from './where';
2
+ import { ISession } from '../../../db/session';
2
3
  export default class IsNotNull extends Expr {
3
4
  private left;
4
5
  constructor(left: Expr);
5
- toQuery: (position?: number | undefined, tableCache?: {
6
- [tableName: string]: string;
7
- } | undefined) => {
6
+ toQuery: ({ position, tableCache, session, }: {
7
+ position?: number | undefined;
8
+ tableCache?: {
9
+ [tableName: string]: string;
10
+ } | undefined;
11
+ session: ISession;
12
+ }) => {
8
13
  query: string;
9
14
  values: Array<any>;
10
15
  };
@@ -8,8 +8,8 @@ const where_1 = __importDefault(require("./where"));
8
8
  class IsNotNull extends where_1.default {
9
9
  constructor(left) {
10
10
  super();
11
- this.toQuery = (position, tableCache) => {
12
- const leftPreparedValues = this.left.toQuery(position, tableCache);
11
+ this.toQuery = ({ position, tableCache, session, }) => {
12
+ const leftPreparedValues = this.left.toQuery({ position, tableCache, session });
13
13
  return { query: `${leftPreparedValues.query} is not null`, values: leftPreparedValues.values };
14
14
  };
15
15
  this.left = left;
@@ -1,10 +1,15 @@
1
1
  import Expr from './where';
2
+ import { ISession } from '../../../db/session';
2
3
  export default class IsNull extends Expr {
3
4
  private left;
4
5
  constructor(left: Expr);
5
- toQuery: (position?: number | undefined, tableCache?: {
6
- [tableName: string]: string;
7
- } | undefined) => {
6
+ toQuery: ({ position, tableCache, session, }: {
7
+ position?: number | undefined;
8
+ tableCache?: {
9
+ [tableName: string]: string;
10
+ } | undefined;
11
+ session: ISession;
12
+ }) => {
8
13
  query: string;
9
14
  values: Array<any>;
10
15
  };
@@ -8,8 +8,8 @@ const where_1 = __importDefault(require("./where"));
8
8
  class IsNull extends where_1.default {
9
9
  constructor(left) {
10
10
  super();
11
- this.toQuery = (position, tableCache) => {
12
- const leftPreparedValues = this.left.toQuery(position, tableCache);
11
+ this.toQuery = ({ position, tableCache, session, }) => {
12
+ const leftPreparedValues = this.left.toQuery({ position, tableCache, session });
13
13
  return { query: `${leftPreparedValues.query} is null`, values: leftPreparedValues.values };
14
14
  };
15
15
  this.left = left;
@@ -1,4 +1,5 @@
1
1
  import Expr from './where';
2
+ import { ISession } from '../../../db/session';
2
3
  export default class Less extends Expr {
3
4
  private left;
4
5
  private right;
@@ -6,9 +7,13 @@ export default class Less extends Expr {
6
7
  left: Expr;
7
8
  right: Expr;
8
9
  });
9
- toQuery: (position?: number | undefined, tableCache?: {
10
- [tableName: string]: string;
11
- } | undefined) => {
10
+ toQuery: ({ position, tableCache, session, }: {
11
+ position?: number | undefined;
12
+ tableCache?: {
13
+ [tableName: string]: string;
14
+ } | undefined;
15
+ session: ISession;
16
+ }) => {
12
17
  query: string;
13
18
  values: Array<any>;
14
19
  };
@@ -8,9 +8,9 @@ const where_1 = __importDefault(require("./where"));
8
8
  class Less extends where_1.default {
9
9
  constructor({ left, right }) {
10
10
  super();
11
- this.toQuery = (position, tableCache) => {
12
- const rightPreparedValues = this.right.toQuery(position, tableCache);
13
- const leftPreparedValues = this.left.toQuery(position, tableCache);
11
+ this.toQuery = ({ position, tableCache, session, }) => {
12
+ const rightPreparedValues = this.right.toQuery({ position, tableCache, session });
13
+ const leftPreparedValues = this.left.toQuery({ position, tableCache, session });
14
14
  return { query: `${leftPreparedValues.query} < ${rightPreparedValues.query}`, values: [...leftPreparedValues.values, ...rightPreparedValues.values] };
15
15
  };
16
16
  this.left = left;
@@ -1,4 +1,5 @@
1
1
  import Expr from './where';
2
+ import { ISession } from '../../../db/session';
2
3
  export default class LessEq extends Expr {
3
4
  private left;
4
5
  private right;
@@ -6,9 +7,13 @@ export default class LessEq extends Expr {
6
7
  left: Expr;
7
8
  right: Expr;
8
9
  });
9
- toQuery: (position?: number | undefined, tableCache?: {
10
- [tableName: string]: string;
11
- } | undefined) => {
10
+ toQuery: ({ position, tableCache, session, }: {
11
+ position?: number | undefined;
12
+ tableCache?: {
13
+ [tableName: string]: string;
14
+ } | undefined;
15
+ session: ISession;
16
+ }) => {
12
17
  query: string;
13
18
  values: Array<any>;
14
19
  };
@@ -8,9 +8,9 @@ const where_1 = __importDefault(require("./where"));
8
8
  class LessEq extends where_1.default {
9
9
  constructor({ left, right }) {
10
10
  super();
11
- this.toQuery = (position, tableCache) => {
12
- const rightPreparedValues = this.right.toQuery(position, tableCache);
13
- const leftPreparedValues = this.left.toQuery(position, tableCache);
11
+ this.toQuery = ({ position, tableCache, session, }) => {
12
+ const rightPreparedValues = this.right.toQuery({ position, tableCache, session });
13
+ const leftPreparedValues = this.left.toQuery({ position, tableCache, session });
14
14
  return { query: `${leftPreparedValues.query} <= ${rightPreparedValues.query}`, values: [...leftPreparedValues.values, ...rightPreparedValues.values] };
15
15
  };
16
16
  this.left = left;
@@ -1,11 +1,16 @@
1
1
  import Expr from './where';
2
+ import { ISession } from '../../../db/session';
2
3
  export default class Like extends Expr {
3
4
  private left;
4
5
  private right;
5
6
  constructor(left: Expr, right: Expr);
6
- toQuery: (position?: number | undefined, tableCache?: {
7
- [tableName: string]: string;
8
- } | undefined) => {
7
+ toQuery: ({ position, tableCache, session, }: {
8
+ position?: number | undefined;
9
+ tableCache?: {
10
+ [tableName: string]: string;
11
+ } | undefined;
12
+ session: ISession;
13
+ }) => {
9
14
  query: string;
10
15
  values: Array<any>;
11
16
  };
@@ -8,9 +8,9 @@ const where_1 = __importDefault(require("./where"));
8
8
  class Like extends where_1.default {
9
9
  constructor(left, right) {
10
10
  super();
11
- this.toQuery = (position, tableCache) => {
12
- const rightPreparedValues = this.right.toQuery(position, tableCache);
13
- const leftPreparedValues = this.left.toQuery(position, tableCache);
11
+ this.toQuery = ({ position, tableCache, session, }) => {
12
+ const rightPreparedValues = this.right.toQuery({ position, tableCache, session });
13
+ const leftPreparedValues = this.left.toQuery({ position, tableCache, session });
14
14
  return { query: `${leftPreparedValues.query} like ${rightPreparedValues.query}`, values: [...leftPreparedValues.values, ...rightPreparedValues.values] };
15
15
  };
16
16
  this.left = left;
@@ -1,11 +1,16 @@
1
1
  import Expr from './where';
2
+ import { ISession } from '../../../db/session';
2
3
  export default class NotEqWhere extends Expr {
3
4
  private left;
4
5
  private right;
5
6
  constructor(left: Expr, right: Expr);
6
- toQuery: (position?: number | undefined, tableCache?: {
7
- [tableName: string]: string;
8
- } | undefined) => {
7
+ toQuery: ({ position, tableCache, session, }: {
8
+ position?: number | undefined;
9
+ tableCache?: {
10
+ [tableName: string]: string;
11
+ } | undefined;
12
+ session: ISession;
13
+ }) => {
9
14
  query: string;
10
15
  values: Array<any>;
11
16
  };
@@ -8,9 +8,9 @@ const where_1 = __importDefault(require("./where"));
8
8
  class NotEqWhere extends where_1.default {
9
9
  constructor(left, right) {
10
10
  super();
11
- this.toQuery = (position, tableCache) => {
12
- const rightPreparedValues = this.right.toQuery(position, tableCache);
13
- const leftPreparedValues = this.left.toQuery(position, tableCache);
11
+ this.toQuery = ({ position, tableCache, session, }) => {
12
+ const rightPreparedValues = this.right.toQuery({ position, tableCache, session });
13
+ const leftPreparedValues = this.left.toQuery({ position, tableCache, session });
14
14
  return { query: `${leftPreparedValues.query}!=${rightPreparedValues.query}`, values: [...leftPreparedValues.values, ...rightPreparedValues.values] };
15
15
  };
16
16
  this.left = left;
@@ -1,10 +1,15 @@
1
1
  import Expr from './where';
2
+ import { ISession } from '../../../db/session';
2
3
  export default class Or extends Expr {
3
4
  private expressions;
4
5
  constructor(expressions: Expr[]);
5
- toQuery: (position?: number | undefined, tableCache?: {
6
- [tableName: string]: string;
7
- } | undefined) => {
6
+ toQuery: ({ position, tableCache, session, }: {
7
+ position?: number | undefined;
8
+ tableCache?: {
9
+ [tableName: string]: string;
10
+ } | undefined;
11
+ session: ISession;
12
+ }) => {
8
13
  query: string;
9
14
  values: Array<any>;
10
15
  };
@@ -8,13 +8,13 @@ const where_1 = __importDefault(require("./where"));
8
8
  class Or extends where_1.default {
9
9
  constructor(expressions) {
10
10
  super();
11
- this.toQuery = (position, tableCache) => {
11
+ this.toQuery = ({ position, tableCache, session, }) => {
12
12
  let nextPosition = position || 1;
13
13
  const result = ['('];
14
14
  const valuesResult = [];
15
15
  for (let i = 0; i < this.expressions.length; i += 1) {
16
16
  const expression = this.expressions[i];
17
- const expressionResult = expression.toQuery(nextPosition, tableCache);
17
+ const expressionResult = expression.toQuery({ position: nextPosition, tableCache, session });
18
18
  valuesResult.push(...expressionResult.values);
19
19
  result.push(expressionResult.query);
20
20
  nextPosition += expressionResult.values.length;
@@ -1,8 +1,15 @@
1
1
  import Expr from './where';
2
+ import { ISession } from '../../../db/session';
2
3
  export default class RawWhere extends Expr {
3
4
  private custom;
4
5
  constructor(custom: string);
5
- toQuery: () => {
6
+ toQuery: ({ position, tableCache, session, }: {
7
+ position?: number | undefined;
8
+ tableCache?: {
9
+ [tableName: string]: string;
10
+ } | undefined;
11
+ session: ISession;
12
+ }) => {
6
13
  query: string;
7
14
  values: Array<any>;
8
15
  };
@@ -9,7 +9,7 @@ class RawWhere extends where_1.default {
9
9
  constructor(custom) {
10
10
  super();
11
11
  this.custom = custom;
12
- this.toQuery = () => ({ query: this.custom, values: [] });
12
+ this.toQuery = ({ position, tableCache, session, }) => ({ query: this.custom, values: [] });
13
13
  }
14
14
  }
15
15
  exports.default = RawWhere;
@@ -1,12 +1,17 @@
1
1
  import { AbstractColumn } from '../../../columns/column';
2
2
  import ColumnType from '../../../columns/types/columnType';
3
3
  import Expr from './where';
4
+ import { ISession } from '../../../db/session';
4
5
  export default class Var<T extends AbstractColumn<ColumnType<any>, boolean, boolean>> extends Expr {
5
6
  private column;
6
7
  constructor(column: T);
7
- toQuery: (postition?: number | undefined, tableCache?: {
8
- [tableName: string]: string;
9
- } | undefined) => {
8
+ toQuery: ({ position, tableCache, session, }: {
9
+ position?: number | undefined;
10
+ tableCache?: {
11
+ [tableName: string]: string;
12
+ } | undefined;
13
+ session: ISession;
14
+ }) => {
10
15
  query: string;
11
16
  values: Array<any>;
12
17
  };
@@ -8,7 +8,7 @@ const where_1 = __importDefault(require("./where"));
8
8
  class Var extends where_1.default {
9
9
  constructor(column) {
10
10
  super();
11
- this.toQuery = (postition, tableCache) => {
11
+ this.toQuery = ({ position, tableCache, session, }) => {
12
12
  const tableName = tableCache && tableCache[this.column.getParentName()] ? tableCache[this.column.getParentName()] : this.column.getParentName();
13
13
  return { query: `${tableName}.${ecranate_1.ecranate(this.column.getColumnName())}`, values: [] };
14
14
  };
@@ -1,6 +1,11 @@
1
+ import { ISession } from '../../../db/session';
1
2
  export default abstract class Expr {
2
- abstract toQuery(position?: number, tableCache?: {
3
- [tableName: string]: string;
3
+ abstract toQuery({ position, tableCache, session, }: {
4
+ position?: number;
5
+ tableCache?: {
6
+ [tableName: string]: string;
7
+ };
8
+ session: ISession;
4
9
  }): {
5
10
  query: string;
6
11
  values: Array<any>;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- /* eslint-disable max-classes-per-file */
4
3
  class Expr {
5
4
  }
6
5
  exports.default = Expr;
package/db/session.d.ts CHANGED
@@ -1,9 +1,12 @@
1
1
  import { Pool, QueryResult } from 'pg';
2
2
  export declare abstract class ISession {
3
+ constructor();
3
4
  abstract execute(query: string, values?: Array<any>): Promise<QueryResult<any>>;
5
+ abstract parametrized(num: number): string;
4
6
  }
5
7
  export default class Session extends ISession {
6
8
  private pool;
7
9
  constructor(pool: Pool);
8
10
  execute(query: string, values?: Array<any>): Promise<QueryResult<any>>;
11
+ parametrized(num: number): string;
9
12
  }
package/db/session.js CHANGED
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ISession = void 0;
4
4
  class ISession {
5
+ // eslint-disable-next-line @typescript-eslint/no-useless-constructor
6
+ constructor() {
7
+ }
5
8
  }
6
9
  exports.ISession = ISession;
7
10
  class Session extends ISession {
@@ -12,5 +15,8 @@ class Session extends ISession {
12
15
  async execute(query, values) {
13
16
  return this.pool.query(query, values || []);
14
17
  }
18
+ parametrized(num) {
19
+ return `$${num}`;
20
+ }
15
21
  }
16
22
  exports.default = Session;
@@ -1,6 +1,7 @@
1
1
  import Expr from '../builders/requestBuilders/where/where';
2
2
  import { AbstractColumn } from '../columns/column';
3
3
  import ColumnType from '../columns/types/columnType';
4
+ import { ISession } from '../db/session';
4
5
  export declare enum BuilderType {
5
6
  SELECT = 0,
6
7
  JOINED_SELECT = 1,
@@ -10,5 +11,5 @@ export declare enum BuilderType {
10
11
  UPDATE = 5
11
12
  }
12
13
  export default class BuilderError extends Error {
13
- constructor(builderType: BuilderType, tableName: string, columns: AbstractColumn<ColumnType>[], reason: Error, filter?: Expr);
14
+ constructor(builderType: BuilderType, tableName: string, columns: AbstractColumn<ColumnType>[], reason: Error, session: ISession, filter?: Expr);
14
15
  }
@@ -11,14 +11,14 @@ var BuilderType;
11
11
  BuilderType[BuilderType["UPDATE"] = 5] = "UPDATE";
12
12
  })(BuilderType = exports.BuilderType || (exports.BuilderType = {}));
13
13
  class BuilderError extends Error {
14
- constructor(builderType, tableName, columns, reason, filter) {
14
+ constructor(builderType, tableName, columns, reason, session, filter) {
15
15
  super('');
16
16
  this.message = ` Error while building select query from ${tableName}\n-----\nIf you see current error, please create [github issue](https://github.com/lambda-direct/drizzle-orm/issues) and provide following information\n
17
17
  Reason: ${reason.message}
18
18
  Query builder: ${BuilderType[builderType]}
19
19
  Table name: ${tableName}
20
- Filter query: ${filter ? filter.toQuery().query : 'undefined'}
21
- Values: ${filter ? filter.toQuery().values : 'undefined'}
20
+ Filter query: ${filter ? filter.toQuery({ session }).query : 'undefined'}
21
+ Values: ${filter ? filter.toQuery({ session }).values : 'undefined'}
22
22
  Column names: ${columns.map((column) => column.getColumnName()).join(', ')}\n-----\n`;
23
23
  }
24
24
  }
package/index.d.ts CHANGED
@@ -5,6 +5,8 @@ export * from './db';
5
5
  export * from './builders';
6
6
  export * from './columns';
7
7
  export * from './tables';
8
+ export * from './logger/consoleLogger';
9
+ export * from './logger/abstractLogger';
8
10
  export declare const drizzle: {
9
11
  connect(config: ClientConfig): Promise<DB>;
10
12
  migrator(db: DB): Migrator;
package/index.js CHANGED
@@ -20,6 +20,8 @@ __exportStar(require("./db"), exports);
20
20
  __exportStar(require("./builders"), exports);
21
21
  __exportStar(require("./columns"), exports);
22
22
  __exportStar(require("./tables"), exports);
23
+ __exportStar(require("./logger/consoleLogger"), exports);
24
+ __exportStar(require("./logger/abstractLogger"), exports);
23
25
  exports.drizzle = {
24
26
  async connect(config) {
25
27
  const dbConnector = new db_1.DbConnector().params(config);
@@ -22,6 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
+ /* eslint-disable no-continue */
25
26
  /* eslint-disable no-restricted-syntax */
26
27
  /* eslint-disable import/export */
27
28
  /* eslint-disable max-classes-per-file */
@@ -72,6 +73,9 @@ class Migrator {
72
73
  await transaction.begin();
73
74
  try {
74
75
  for await (const migrationFolder of files) {
76
+ if (migrationFolder === '.DS_Store') {
77
+ continue;
78
+ }
75
79
  const migrationFiles = fs.readdirSync(`${migrationFolderTo}/${migrationFolder}`);
76
80
  const migrationFile = migrationFiles.filter((file) => file === 'migration.sql')[0];
77
81
  const query = fs.readFileSync(`${migrationFolderTo}/${migrationFolder}/${migrationFile}`).toString();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-orm",
3
- "version": "0.10.39",
3
+ "version": "0.10.42",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/test.d.ts CHANGED
@@ -1 +0,0 @@
1
- export {};
package/test.js CHANGED
@@ -1,64 +1,104 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const dbConnector_1 = __importDefault(require("./db/dbConnector"));
7
- const usersTable_1 = __importDefault(require("./docs/tables/usersTable"));
8
- const consoleLogger_1 = __importDefault(require("./logger/consoleLogger"));
9
- const serializer_1 = __importDefault(require("./serializer/serializer"));
10
- (async () => {
11
- try {
12
- const db = await new dbConnector_1.default()
13
- .connectionString('postgresql://postgres@127.0.0.1/migrator')
14
- .connect();
15
- db.useLogger(new consoleLogger_1.default());
16
- const usersTable = new usersTable_1.default(db);
17
- // const citiesTable = new CitiesTable(db);
18
- // await usersTable.insert({
19
- // });
20
- // const res = await citiesTable.update()
21
- // // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
22
- // .where(eq(citiesTable.location, 'YR'))
23
- // .set({
24
- // metadata: [{
25
- // fallback_image: true,
26
- // team_image: 'https://files.slack.com/files-pri/T016CCC3FE3-F03461UR9M5/clinic_team_photo_1.jpg?pub_secret=560c098bfb',
27
- // image_alt_text: 'Generic Physiotherapy Clinic image 1',
28
- // logo: '',
29
- // logo_alt_text: ''
30
- // }],
31
- // })
32
- // // .leftJoin(CitiesTable, UsersTable, (table) => table.userId, (table) => table.id)
33
- // // .leftJoin(UsersTable, UsersTable, (table) => table.id, (table) => table.id)
34
- // .execute();
35
- // console.log(res);
36
- const ser = new serializer_1.default();
37
- const res = ser.generate([usersTable], []);
38
- console.log(JSON.stringify(res, null, 2));
39
- // const f = {
40
- // id: count(usersTable.id),
41
- // };
42
- // type d = ExtractModel<typeof f>;
43
- // const res = await usersTable.select()
44
- // .leftJoin(UsersTable, (table) => table.id, (table) => table.id)
45
- // .leftJoin(UsersTable, CitiesTable, (table) => table.id, (table) => table.id)
46
- // .execute();
47
- // const res = await usersTable.select()
48
- // // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
49
- // .leftJoin(UsersTable, (table) => table.foundationDate, (table) => table.id)
50
- // .leftJoin(UsersTable, UsersTable, (table) => table.role, (table) => table.id)
51
- // .leftJoin(UsersTable, UsersTable, (table) => table.role, (table) => table.id)
52
- // // .groupBy({
53
- // // usersTable: usersTable.id,
54
- // // firstJoin: [usersTable.id],
55
- // // secondJoin: usersTable.id,
56
- // // thirdJoin: usersTable.id,
57
- // // })
58
- // .execute();
59
- // console.log(res);
60
- }
61
- catch (e) {
62
- console.log(e);
63
- }
64
- })();
2
+ // import { QueryResult } from 'pg';
3
+ // import { drizzle } from '.';
4
+ // import {
5
+ // and, eq, greater, isNotNull, less, or,
6
+ // } from './builders';
7
+ // import { DB } from './db';
8
+ // import DbConnector from './db/dbConnector';
9
+ // import Session, { ISession } from './db/session';
10
+ // import UsersTable from './docs/tables/usersTable';
11
+ // import ConsoleLogger from './logger/consoleLogger';
12
+ // class KnexSession extends ISession {
13
+ // public execute(query: string, values?: any[]): Promise<QueryResult<any>> {
14
+ // console.log(query);
15
+ // console.log(values);
16
+ // return { rows: [] } as any;
17
+ // }
18
+ // public parametrized(num: number): string {
19
+ // return `?${num}`;
20
+ // }
21
+ // }
22
+ // (async () => {
23
+ // try {
24
+ // // const db = await new DbConnector()
25
+ // // .connectionString('postgresql://postgres@127.0.0.1/migrator')
26
+ // // .connect();
27
+ // const db = new DB(new KnexSession());
28
+ // // db.useLogger(new ConsoleLogger());
29
+ // const usersTable = new UsersTable(db);
30
+ // await usersTable.select().where(or([
31
+ // and([eq(usersTable.role, 'bar'), less(usersTable.phone, 'd')]),
32
+ // eq(usersTable.role, 'bar'),
33
+ // greater(usersTable.decimalField, 1),
34
+ // ])).execute();
35
+ // await usersTable.delete().where(or([
36
+ // and([eq(usersTable.role, 'bar'), less(usersTable.phone, 'd')]),
37
+ // eq(usersTable.role, 'bar'),
38
+ // greater(usersTable.decimalField, 1),
39
+ // ])).execute();
40
+ // await usersTable.update().where(or([
41
+ // and([eq(usersTable.role, 'bar'), less(usersTable.phone, 'd')]),
42
+ // eq(usersTable.role, 'bar'),
43
+ // greater(usersTable.decimalField, 1),
44
+ // ])).set({
45
+ // isArchived: false,
46
+ // role: 'bar',
47
+ // }).execute();
48
+ // await usersTable.insert({
49
+ // isArchived: false,
50
+ // role: 'bar',
51
+ // decimalField: 12,
52
+ // createdAt: new Date(),
53
+ // }).execute();
54
+ // // drizzle.migrator(db).migrate({ migrationFolder: 'drizzle' });
55
+ // // type g = ReturnType<typeof usersTable.updatedAt.getColumnType>['codeType'];
56
+ // // type f = ExtractColumnType<typeof usersTable.updatedAt>;
57
+ // // type f1 = ExtractColumnType1<f>;
58
+ // // const citiesTable = new CitiesTable(db);
59
+ // // await usersTable.insert({
60
+ // // });
61
+ // // const res = await citiesTable.update()
62
+ // // // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
63
+ // // .where(eq(citiesTable.location, 'YR'))
64
+ // // .set({
65
+ // // metadata: [{
66
+ // // fallback_image: true,
67
+ // // team_image: 'https://files.slack.com/files-pri/T016CCC3FE3-F03461UR9M5/clinic_team_photo_1.jpg?pub_secret=560c098bfb',
68
+ // // image_alt_text: 'Generic Physiotherapy Clinic image 1',
69
+ // // logo: '',
70
+ // // logo_alt_text: ''
71
+ // // }],
72
+ // // })
73
+ // // // .leftJoin(CitiesTable, UsersTable, (table) => table.userId, (table) => table.id)
74
+ // // // .leftJoin(UsersTable, UsersTable, (table) => table.id, (table) => table.id)
75
+ // // .execute();
76
+ // // console.log(res);
77
+ // // const ser = new MigrationSerializer();
78
+ // // const res = ser.generate([usersTable as AbstractTable<UsersTable>], []);
79
+ // // console.log(JSON.stringify(res, null, 2));
80
+ // // const f = {
81
+ // // id: count(usersTable.id),
82
+ // // };
83
+ // // type d = ExtractModel<typeof f>;
84
+ // // const res = await usersTable.select()
85
+ // // .leftJoin(UsersTable, (table) => table.id, (table) => table.id)
86
+ // // .leftJoin(UsersTable, CitiesTable, (table) => table.id, (table) => table.id)
87
+ // // .execute();
88
+ // // const res = await usersTable.select()
89
+ // // // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
90
+ // // .leftJoin(UsersTable, (table) => table.foundationDate, (table) => table.id)
91
+ // // .leftJoin(UsersTable, UsersTable, (table) => table.role, (table) => table.id)
92
+ // // .leftJoin(UsersTable, UsersTable, (table) => table.role, (table) => table.id)
93
+ // // // .groupBy({
94
+ // // // usersTable: usersTable.id,
95
+ // // // firstJoin: [usersTable.id],
96
+ // // // secondJoin: usersTable.id,
97
+ // // // thirdJoin: usersTable.id,
98
+ // // // })
99
+ // // .execute();
100
+ // // console.log(res);
101
+ // } catch (e) {
102
+ // console.log(e);
103
+ // }
104
+ // })();