drizzle-orm 0.10.21 → 0.10.22

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.
@@ -60,6 +60,8 @@ class SelectAggregator extends abstractAggregator_1.default {
60
60
  this.appendFrom = (tableName) => {
61
61
  this._from.push('FROM ');
62
62
  this._from.push(tableName);
63
+ // this._from.push(`${tableName} AS ${tableName}_0`);
64
+ this._joinCache[tableName] = tableName;
63
65
  return this;
64
66
  };
65
67
  // Add select generator for second table also
@@ -70,6 +72,14 @@ class SelectAggregator extends abstractAggregator_1.default {
70
72
  const tableFrom = joinObject.join.fromColumn.getParentName();
71
73
  const tableTo = joinObject.join.toColumn.getParentName();
72
74
  const { type } = joinObject.join;
75
+ let fromAlias = '';
76
+ if (this._joinCache[tableFrom]) {
77
+ fromAlias = this._joinCache[tableFrom];
78
+ }
79
+ else {
80
+ fromAlias = `${tableFrom}${joinObject.id ? `_${joinObject.id}` : ''}`;
81
+ this._joinCache[tableFrom] = fromAlias;
82
+ }
73
83
  let selectString;
74
84
  if (joinObject.partial) {
75
85
  selectString = this.generateSelectArray(`${tableTo}${joinObject.id ? `_${joinObject.id}` : ''}`, Object.values(joinObject.partial), joinObject.id).join('');
@@ -85,19 +95,21 @@ class SelectAggregator extends abstractAggregator_1.default {
85
95
  this._join.push(tableTo);
86
96
  this._join.push(' ');
87
97
  this._join.push(`AS ${tableTo}${joinObject.id ? `_${joinObject.id}` : ''}`);
98
+ this._joinCache[tableTo] = `${tableTo}${joinObject.id ? `_${joinObject.id}` : ''}`;
88
99
  this._join.push('\n');
89
100
  this._join.push('ON ');
90
- if (this._joinCache[tableFrom]) {
91
- this._join.push(this._joinCache[tableFrom]);
92
- }
93
- else {
94
- this._join.push(tableFrom);
95
- this._joinCache[tableTo] = `${tableTo}${joinObject.id ? `_${joinObject.id}` : ''}`;
96
- }
101
+ this._join.push(fromAlias);
102
+ // if (this._joinCache[tableFrom]) {
103
+ // this._join.push(this._joinCache[tableFrom]);
104
+ // } else {
105
+ // this._join.push(tableFrom);
106
+ // this._joinCache[tableFrom] = `${tableFrom}${joinObject.id ? `_${joinObject.id}` : ''}`;
107
+ // }
97
108
  this._join.push('.');
98
109
  this._join.push(joinObject.join.fromColumn.getColumnName());
99
110
  this._join.push(' = ');
100
111
  this._join.push(`${tableTo}${joinObject.id ? `_${joinObject.id}` : ''}`);
112
+ // this._join.push(toAlias);
101
113
  this._join.push('.');
102
114
  this._join.push(joinObject.join.toColumn.getColumnName());
103
115
  }
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const abstractTable_1 = require("../../tables/abstractTable");
4
+ const usersTable_1 = require("./usersTable");
4
5
  class CitiesTable extends abstractTable_1.default {
5
6
  constructor() {
6
7
  super(...arguments);
7
8
  this.id = this.serial('id').primaryKey();
8
9
  this.foundationDate = this.timestamp('name').notNull();
9
10
  this.location = this.varchar('page', { size: 256 });
10
- this.userId = this.int('user_id').foreignKey(CitiesTable, (table) => table.id, { onUpdate: 'CASCADE' });
11
+ this.userId = this.int('user_id').foreignKey(usersTable_1.default, (table) => table.id, { onUpdate: 'CASCADE' });
11
12
  this.metadata = this.jsonb('metadata');
12
13
  }
13
14
  tableName() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-orm",
3
- "version": "0.10.21",
3
+ "version": "0.10.22",
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,50 +1,57 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const dbConnector_1 = require("./db/dbConnector");
4
- const citiesTable_1 = require("./docs/tables/citiesTable");
5
- const consoleLogger_1 = require("./logger/consoleLogger");
6
- const serializer_1 = require("./serializer/serializer");
7
- (async () => {
8
- try {
9
- const db = await new dbConnector_1.default()
10
- .connectionString('postgresql://postgres@127.0.0.1/migrator')
11
- .connect();
12
- const usersTable = new citiesTable_1.default(db);
13
- db.useLogger(new consoleLogger_1.default());
14
- const ser = new serializer_1.default();
15
- const res = ser.generate([usersTable], []);
16
- console.log(JSON.stringify(res, null, 2));
17
- // const f = {
18
- // id: count(usersTable.id),
19
- // };
20
- // type d = ExtractModel<typeof f>;
21
- // const res = await usersTable.select({
22
- // piska: count(),
23
- // mongodibil: count(usersTable.phone),
24
- // })
25
- // .where({
26
- // piska: eq(),
27
- // mongodibil: eq(usersTable.phone),
28
- // }).leftJoin(UsersTable, (table) => table.id, (table) => table.id)
29
- // .leftJoin(UsersTable, UsersTable, (table) => table.id, (table) => table.id)
30
- // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
31
- // .orderBy((table, join1, join2, join3) => [{table.id}, join1.id, join1.phone])
32
- // .execute();
33
- // const res = await usersTable.select()
34
- // // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
35
- // .leftJoin(UsersTable, (table) => table.foundationDate, (table) => table.id)
36
- // .leftJoin(UsersTable, UsersTable, (table) => table.role, (table) => table.id)
37
- // .leftJoin(UsersTable, UsersTable, (table) => table.role, (table) => table.id)
38
- // // .groupBy({
39
- // // usersTable: usersTable.id,
40
- // // firstJoin: [usersTable.id],
41
- // // secondJoin: usersTable.id,
42
- // // thirdJoin: usersTable.id,
43
- // // })
44
- // .execute();
45
- // console.log(res);
46
- }
47
- catch (e) {
48
- console.log(e);
49
- }
50
- })();
2
+ // import DbConnector from './db/dbConnector';
3
+ // import CitiesTable from './docs/tables/citiesTable';
4
+ // import UsersTable from './docs/tables/usersTable';
5
+ // import ConsoleLogger from './logger/consoleLogger';
6
+ // import MigrationSerializer from './serializer/serializer';
7
+ // import AbstractTable from './tables/abstractTable';
8
+ // (async () => {
9
+ // try {
10
+ // const db = await new DbConnector()
11
+ // .connectionString('postgresql://postgres@127.0.0.1/migrator')
12
+ // .connect();
13
+ // const usersTable = new UsersTable(db);
14
+ // const citiesTable = new CitiesTable(db);
15
+ // db.useLogger(new ConsoleLogger());
16
+ // const res = await usersTable.select()
17
+ // // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
18
+ // .leftJoin(CitiesTable, (table) => table.id, (table) => table.id)
19
+ // // .leftJoin(CitiesTable, UsersTable, (table) => table.userId, (table) => table.id)
20
+ // // .leftJoin(UsersTable, UsersTable, (table) => table.id, (table) => table.id)
21
+ // .execute();
22
+ // // const ser = new MigrationSerializer();
23
+ // // const res = ser.generate([usersTable as AbstractTable<UsersTable>], []);
24
+ // // console.log(JSON.stringify(res, null, 2));
25
+ // // const f = {
26
+ // // id: count(usersTable.id),
27
+ // // };
28
+ // // type d = ExtractModel<typeof f>;
29
+ // // const res = await usersTable.select({
30
+ // // piska: count(),
31
+ // // mongodibil: count(usersTable.phone),
32
+ // // })
33
+ // // .where({
34
+ // // piska: eq(),
35
+ // // mongodibil: eq(usersTable.phone),
36
+ // // }).leftJoin(UsersTable, (table) => table.id, (table) => table.id)
37
+ // // .leftJoin(UsersTable, UsersTable, (table) => table.id, (table) => table.id)
38
+ // // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
39
+ // // .orderBy((table, join1, join2, join3) => [{table.id}, join1.id, join1.phone])
40
+ // // .execute();
41
+ // // const res = await usersTable.select()
42
+ // // // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
43
+ // // .leftJoin(UsersTable, (table) => table.foundationDate, (table) => table.id)
44
+ // // .leftJoin(UsersTable, UsersTable, (table) => table.role, (table) => table.id)
45
+ // // .leftJoin(UsersTable, UsersTable, (table) => table.role, (table) => table.id)
46
+ // // // .groupBy({
47
+ // // // usersTable: usersTable.id,
48
+ // // // firstJoin: [usersTable.id],
49
+ // // // secondJoin: usersTable.id,
50
+ // // // thirdJoin: usersTable.id,
51
+ // // // })
52
+ // // .execute();
53
+ // // console.log(res);
54
+ // } catch (e) {
55
+ // console.log(e);
56
+ // }
57
+ // })();