drizzle-orm 0.10.20 → 0.10.23
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
|
-
|
|
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
|
}
|
|
@@ -6,8 +6,11 @@ class SetObject extends updates_1.UpdateExpr {
|
|
|
6
6
|
super();
|
|
7
7
|
this.toQuery = (position) => {
|
|
8
8
|
const nextPosition = position || 1;
|
|
9
|
-
const
|
|
10
|
-
|
|
9
|
+
const valueToInsert = this._value === null || this._value === undefined
|
|
10
|
+
? this._value
|
|
11
|
+
: this._column.getColumnType().insertStrategy(this._value);
|
|
12
|
+
const query = `"${this._column.getColumnName()}"=$${nextPosition}`;
|
|
13
|
+
return { query, values: [valueToInsert] };
|
|
11
14
|
};
|
|
12
15
|
this._column = column;
|
|
13
16
|
this._value = value;
|
|
@@ -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/errors/builderError.js
CHANGED
|
@@ -17,7 +17,8 @@ class BuilderError extends Error {
|
|
|
17
17
|
Reason: ${reason.message}
|
|
18
18
|
Query builder: ${BuilderType[builderType]}
|
|
19
19
|
Table name: ${tableName}
|
|
20
|
-
Filter query: ${filter ? filter.toQuery() : 'undefined'}
|
|
20
|
+
Filter query: ${filter ? filter.toQuery().query : 'undefined'}
|
|
21
|
+
Values: ${filter ? filter.toQuery().values : 'undefined'}
|
|
21
22
|
Column names: ${columns.map((column) => column.getColumnName()).join(', ')}\n-----\n`;
|
|
22
23
|
}
|
|
23
24
|
}
|
package/package.json
CHANGED
package/serializer/serializer.js
CHANGED
|
@@ -60,7 +60,7 @@ class MigrationSerializer {
|
|
|
60
60
|
const referenced = value.getReferenced();
|
|
61
61
|
if (referenced) {
|
|
62
62
|
columnToReturn[value.getColumnName()].references = {
|
|
63
|
-
foreignKeyName: `${value.getParent().tableName()}_${value.getColumnName()}
|
|
63
|
+
foreignKeyName: `${value.getParent().tableName()}_${value.getColumnName()}_fkey`,
|
|
64
64
|
table: referenced.getParentName(),
|
|
65
65
|
column: referenced.getColumnName(),
|
|
66
66
|
onDelete: value.getOnDelete(),
|
package/test.js
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const static_1 = require("./builders/requestBuilders/where/static");
|
|
3
4
|
const dbConnector_1 = require("./db/dbConnector");
|
|
4
5
|
const citiesTable_1 = require("./docs/tables/citiesTable");
|
|
6
|
+
const usersTable_1 = require("./docs/tables/usersTable");
|
|
5
7
|
const consoleLogger_1 = require("./logger/consoleLogger");
|
|
6
|
-
const serializer_1 = require("./serializer/serializer");
|
|
7
8
|
(async () => {
|
|
8
9
|
try {
|
|
9
10
|
const db = await new dbConnector_1.default()
|
|
10
11
|
.connectionString('postgresql://postgres@127.0.0.1/migrator')
|
|
11
12
|
.connect();
|
|
12
|
-
const usersTable = new
|
|
13
|
+
const usersTable = new usersTable_1.default(db);
|
|
14
|
+
const citiesTable = new citiesTable_1.default(db);
|
|
13
15
|
db.useLogger(new consoleLogger_1.default());
|
|
14
|
-
const
|
|
15
|
-
const res =
|
|
16
|
-
|
|
16
|
+
const phone = undefined;
|
|
17
|
+
const res = await usersTable.update()
|
|
18
|
+
// .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
|
|
19
|
+
.where(static_1.eq(usersTable.id, 16))
|
|
20
|
+
.set({
|
|
21
|
+
phone,
|
|
22
|
+
})
|
|
23
|
+
// .leftJoin(CitiesTable, UsersTable, (table) => table.userId, (table) => table.id)
|
|
24
|
+
// .leftJoin(UsersTable, UsersTable, (table) => table.id, (table) => table.id)
|
|
25
|
+
.execute();
|
|
26
|
+
// const ser = new MigrationSerializer();
|
|
27
|
+
// const res = ser.generate([usersTable as AbstractTable<UsersTable>], []);
|
|
28
|
+
// console.log(JSON.stringify(res, null, 2));
|
|
17
29
|
// const f = {
|
|
18
30
|
// id: count(usersTable.id),
|
|
19
31
|
// };
|