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.
- package/builders/aggregators/selectAggregator.js +19 -7
- package/docs/tables/citiesTable.js +2 -1
- package/package.json +1 -1
- package/test.d.ts +0 -1
- package/test.js +56 -49
|
@@ -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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
else {
|
|
94
|
-
|
|
95
|
-
|
|
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(
|
|
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
package/test.d.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/test.js
CHANGED
|
@@ -1,50 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
+
// })();
|