drizzle-orm 0.10.35 → 0.10.36
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/migrator/migrator.js +5 -5
- package/package.json +1 -1
- package/test.d.ts +1 -0
- package/test.js +64 -65
- package/.pnpm-debug.log +0 -16
- package/data/citiesTable.d.ts +0 -9
- package/data/citiesTable.js +0 -22
- package/data/userGroupsTable.d.ts +0 -7
- package/data/userGroupsTable.js +0 -15
- package/data/usersTable.d.ts +0 -17
- package/data/usersTable.js +0 -31
- package/data/usersToUserGroups.d.ts +0 -7
- package/data/usersToUserGroups.js +0 -20
package/migrator/migrator.js
CHANGED
|
@@ -37,6 +37,7 @@ class Migrator {
|
|
|
37
37
|
this.db = db;
|
|
38
38
|
}
|
|
39
39
|
async migrate(configPath) {
|
|
40
|
+
var _a;
|
|
40
41
|
let migrationFolderTo;
|
|
41
42
|
if (typeof configPath === 'string') {
|
|
42
43
|
const configAsString = fs.readFileSync(path.resolve('.', configPath), 'utf8');
|
|
@@ -64,8 +65,8 @@ class Migrator {
|
|
|
64
65
|
.limit(1)
|
|
65
66
|
.orderBy((table) => table.createdAt, order_1.default.DESC)
|
|
66
67
|
.all();
|
|
67
|
-
const lastDbMigration = dbMigrations[0];
|
|
68
|
-
console.log('
|
|
68
|
+
const lastDbMigration = (_a = dbMigrations[0]) !== null && _a !== void 0 ? _a : undefined;
|
|
69
|
+
console.log('last migration: ', lastDbMigration === null || lastDbMigration === void 0 ? void 0 : lastDbMigration.hash);
|
|
69
70
|
const files = fs.readdirSync(migrationFolderTo);
|
|
70
71
|
const transaction = new transaction_1.default(this.db.session());
|
|
71
72
|
await transaction.begin();
|
|
@@ -83,10 +84,9 @@ class Migrator {
|
|
|
83
84
|
const min = Number(migrationFolder.slice(10, 12));
|
|
84
85
|
const sec = Number(migrationFolder.slice(12, 14));
|
|
85
86
|
const folderAsMillis = Date.UTC(year, month, day, hour, min, sec);
|
|
86
|
-
console.log(`
|
|
87
|
-
console.log(`Folder name to millis = ${folderAsMillis}`);
|
|
87
|
+
console.log(`check migration ${migrationFolder} {folderAsMillis}`);
|
|
88
88
|
if (!lastDbMigration || lastDbMigration.createdAt < folderAsMillis) {
|
|
89
|
-
console.log(`
|
|
89
|
+
console.log(`executing ${migrationFolder}`);
|
|
90
90
|
await this.db.session().execute(query);
|
|
91
91
|
await migrationTable.insert({
|
|
92
92
|
hash: this.generateHash(query),
|
package/package.json
CHANGED
package/test.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/test.js
CHANGED
|
@@ -1,66 +1,65 @@
|
|
|
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
|
-
//
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// })();
|
|
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 static_1 = require("./builders/requestBuilders/where/static");
|
|
7
|
+
const dbConnector_1 = __importDefault(require("./db/dbConnector"));
|
|
8
|
+
const citiesTable_1 = __importDefault(require("./docs/tables/citiesTable"));
|
|
9
|
+
const usersTable_1 = __importDefault(require("./docs/tables/usersTable"));
|
|
10
|
+
const consoleLogger_1 = __importDefault(require("./logger/consoleLogger"));
|
|
11
|
+
(async () => {
|
|
12
|
+
try {
|
|
13
|
+
const db = await new dbConnector_1.default()
|
|
14
|
+
.connectionString('postgresql://postgres@127.0.0.1/migrator')
|
|
15
|
+
.connect();
|
|
16
|
+
const usersTable = new usersTable_1.default(db);
|
|
17
|
+
const citiesTable = new citiesTable_1.default(db);
|
|
18
|
+
db.useLogger(new consoleLogger_1.default());
|
|
19
|
+
const phone = undefined;
|
|
20
|
+
const res = await usersTable.update()
|
|
21
|
+
// .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
|
|
22
|
+
.where(static_1.eq(usersTable.id, 16))
|
|
23
|
+
.set({
|
|
24
|
+
phone,
|
|
25
|
+
})
|
|
26
|
+
// .leftJoin(CitiesTable, UsersTable, (table) => table.userId, (table) => table.id)
|
|
27
|
+
// .leftJoin(UsersTable, UsersTable, (table) => table.id, (table) => table.id)
|
|
28
|
+
.execute();
|
|
29
|
+
// const ser = new MigrationSerializer();
|
|
30
|
+
// const res = ser.generate([usersTable as AbstractTable<UsersTable>], []);
|
|
31
|
+
// console.log(JSON.stringify(res, null, 2));
|
|
32
|
+
// const f = {
|
|
33
|
+
// id: count(usersTable.id),
|
|
34
|
+
// };
|
|
35
|
+
// type d = ExtractModel<typeof f>;
|
|
36
|
+
// const res = await usersTable.select({
|
|
37
|
+
// piska: count(),
|
|
38
|
+
// mongodibil: count(usersTable.phone),
|
|
39
|
+
// })
|
|
40
|
+
// .where({
|
|
41
|
+
// piska: eq(),
|
|
42
|
+
// mongodibil: eq(usersTable.phone),
|
|
43
|
+
// }).leftJoin(UsersTable, (table) => table.id, (table) => table.id)
|
|
44
|
+
// .leftJoin(UsersTable, UsersTable, (table) => table.id, (table) => table.id)
|
|
45
|
+
// .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
|
|
46
|
+
// .orderBy((table, join1, join2, join3) => [{table.id}, join1.id, join1.phone])
|
|
47
|
+
// .execute();
|
|
48
|
+
// const res = await usersTable.select()
|
|
49
|
+
// // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
|
|
50
|
+
// .leftJoin(UsersTable, (table) => table.foundationDate, (table) => table.id)
|
|
51
|
+
// .leftJoin(UsersTable, UsersTable, (table) => table.role, (table) => table.id)
|
|
52
|
+
// .leftJoin(UsersTable, UsersTable, (table) => table.role, (table) => table.id)
|
|
53
|
+
// // .groupBy({
|
|
54
|
+
// // usersTable: usersTable.id,
|
|
55
|
+
// // firstJoin: [usersTable.id],
|
|
56
|
+
// // secondJoin: usersTable.id,
|
|
57
|
+
// // thirdJoin: usersTable.id,
|
|
58
|
+
// // })
|
|
59
|
+
// .execute();
|
|
60
|
+
// console.log(res);
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
console.log(e);
|
|
64
|
+
}
|
|
65
|
+
})();
|
package/.pnpm-debug.log
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"0 debug pnpm:scope": {
|
|
3
|
-
"selected": 1,
|
|
4
|
-
"workspacePrefix": "/Users/andrewsherman/IdeaProjects/datalayer-orm"
|
|
5
|
-
},
|
|
6
|
-
"1 error pnpm": {
|
|
7
|
-
"code": "ERR_PNPM_GIT_NOT_UNCLEAN",
|
|
8
|
-
"hint": "If you want to disable Git checks on publish, set the \"git-checks\" setting to \"false\", or run again with \"--no-git-checks\".",
|
|
9
|
-
"err": {
|
|
10
|
-
"name": "pnpm",
|
|
11
|
-
"message": "Unclean working tree. Commit or stash changes first.",
|
|
12
|
-
"code": "ERR_PNPM_GIT_NOT_UNCLEAN",
|
|
13
|
-
"stack": "pnpm: Unclean working tree. Commit or stash changes first.\n at Object.handler [as publish] (/Users/andrewsherman/.nvm/versions/node/v12.20.1/lib/node_modules/pnpm/dist/pnpm.cjs:177118:17)\n at processTicksAndRejections (internal/process/task_queues.js:97:5)\n at async /Users/andrewsherman/.nvm/versions/node/v12.20.1/lib/node_modules/pnpm/dist/pnpm.cjs:182194:21\n at async run (/Users/andrewsherman/.nvm/versions/node/v12.20.1/lib/node_modules/pnpm/dist/pnpm.cjs:182168:34)\n at async runPnpm (/Users/andrewsherman/.nvm/versions/node/v12.20.1/lib/node_modules/pnpm/dist/pnpm.cjs:182387:5)\n at async /Users/andrewsherman/.nvm/versions/node/v12.20.1/lib/node_modules/pnpm/dist/pnpm.cjs:182379:7"
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
package/data/citiesTable.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AbstractTable } from '..';
|
|
2
|
-
export default class CitiesTable extends AbstractTable<CitiesTable> {
|
|
3
|
-
id: import("..").Column<import("../columns/types/pgSerial").default, true, true, this>;
|
|
4
|
-
foundationDate: import("..").Column<import("..").PgTimestamp, false, false, this>;
|
|
5
|
-
location: import("..").Column<import("..").PgVarChar, true, false, this>;
|
|
6
|
-
userId: import("..").Column<import("..").PgInteger, true, false, this>;
|
|
7
|
-
metadata: import("..").Column<import("..").PgJsonb<any[]>, true, false, this>;
|
|
8
|
-
tableName(): string;
|
|
9
|
-
}
|
package/data/citiesTable.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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 __1 = require("..");
|
|
7
|
-
const usersTable_1 = __importDefault(require("./usersTable"));
|
|
8
|
-
class CitiesTable extends __1.AbstractTable {
|
|
9
|
-
constructor() {
|
|
10
|
-
super(...arguments);
|
|
11
|
-
this.id = this.serial('id').primaryKey();
|
|
12
|
-
this.foundationDate = this.timestamp('name').notNull();
|
|
13
|
-
this.location = this.varchar('page', { size: 256 });
|
|
14
|
-
this.userId = this.int('user_id').foreignKey(usersTable_1.default, (table) => table.id, { onUpdate: 'CASCADE' });
|
|
15
|
-
this.metadata = this.jsonb('metadata');
|
|
16
|
-
}
|
|
17
|
-
// public metadataArray = this.jsonb<CityMeta[]>('metadata_array');
|
|
18
|
-
tableName() {
|
|
19
|
-
return 'cities';
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.default = CitiesTable;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AbstractTable } from "..";
|
|
2
|
-
export default class UserGroupsTable extends AbstractTable<UserGroupsTable> {
|
|
3
|
-
id: import("..").Column<import("../columns/types/pgSerial").default, true, true, this>;
|
|
4
|
-
name: import("..").Column<import("..").PgVarChar, true, false, this>;
|
|
5
|
-
description: import("..").Column<import("..").PgVarChar, true, false, this>;
|
|
6
|
-
tableName(): string;
|
|
7
|
-
}
|
package/data/userGroupsTable.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const __1 = require("..");
|
|
4
|
-
class UserGroupsTable extends __1.AbstractTable {
|
|
5
|
-
constructor() {
|
|
6
|
-
super(...arguments);
|
|
7
|
-
this.id = this.serial('id').primaryKey();
|
|
8
|
-
this.name = this.varchar('name');
|
|
9
|
-
this.description = this.varchar('description');
|
|
10
|
-
}
|
|
11
|
-
tableName() {
|
|
12
|
-
return 'user_groups';
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.default = UserGroupsTable;
|
package/data/usersTable.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { AbstractTable } from "..";
|
|
2
|
-
export declare const rolesEnum: import("../types/type").default<"foo" | "bar" | "baz">;
|
|
3
|
-
export default class UsersTable extends AbstractTable<UsersTable> {
|
|
4
|
-
id: import("..").Column<import("../columns/types/pgSerial").default, true, true, this>;
|
|
5
|
-
fullName: import("..").Column<import("..").PgText, true, false, this>;
|
|
6
|
-
phone: import("..").Column<import("..").PgVarChar, true, false, this>;
|
|
7
|
-
media: import("..").Column<import("..").PgJsonb<string[]>, true, false, this>;
|
|
8
|
-
decimalField: import("..").Column<import("..").PgBigDecimal, false, false, this>;
|
|
9
|
-
bigIntField: import("..").Column<import("..").PgBigInt, true, false, this>;
|
|
10
|
-
role: import("..").Column<import("../columns/types/pgEnum").default<"foo" | "bar" | "baz">, false, false, this>;
|
|
11
|
-
createdAt: import("..").Column<import("..").PgTimestamp, false, false, this>;
|
|
12
|
-
updatedAt: import("..").Column<import("..").PgTimestamp, true, false, this>;
|
|
13
|
-
isArchived: import("..").Column<import("..").PgBoolean, true, false, this>;
|
|
14
|
-
phoneFullNameIndex: import("../indexes/tableIndex").default;
|
|
15
|
-
phoneIndex: import("../indexes/tableIndex").default;
|
|
16
|
-
tableName(): string;
|
|
17
|
-
}
|
package/data/usersTable.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable max-classes-per-file */
|
|
3
|
-
// import { Defaults } from '../../columns/column';
|
|
4
|
-
// import { rolesEnum } from '../types/rolesType';
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.rolesEnum = void 0;
|
|
7
|
-
const __1 = require("..");
|
|
8
|
-
const type_1 = require("../types/type");
|
|
9
|
-
exports.rolesEnum = type_1.createEnum({ alias: 'test-enum', values: ['foo', 'bar', 'baz'] });
|
|
10
|
-
class UsersTable extends __1.AbstractTable {
|
|
11
|
-
constructor() {
|
|
12
|
-
super(...arguments);
|
|
13
|
-
this.id = this.serial('id').primaryKey();
|
|
14
|
-
this.fullName = this.text('full_name');
|
|
15
|
-
this.phone = this.varchar('phone', { size: 256 });
|
|
16
|
-
this.media = this.jsonb('media');
|
|
17
|
-
this.decimalField = this.decimal('test', { precision: 100, scale: 2 }).notNull();
|
|
18
|
-
this.bigIntField = this.bigint('test1', 'max_bytes_53');
|
|
19
|
-
this.role = this.type(exports.rolesEnum, 'name_in_table').notNull();
|
|
20
|
-
this.createdAt = this.timestamp('created_at').notNull();
|
|
21
|
-
// public createdAtWithTimezone = this.timestamptz('created_at');
|
|
22
|
-
this.updatedAt = this.timestamp('updated_at').defaultValue(__1.Defaults.CURRENT_TIMESTAMP);
|
|
23
|
-
this.isArchived = this.bool('is_archived').defaultValue(false);
|
|
24
|
-
this.phoneFullNameIndex = this.index([this.phone, this.fullName]);
|
|
25
|
-
this.phoneIndex = this.uniqueIndex(this.phone);
|
|
26
|
-
}
|
|
27
|
-
tableName() {
|
|
28
|
-
return 'users';
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
exports.default = UsersTable;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AbstractTable } from '..';
|
|
2
|
-
export default class UsersToUserGroupsTable extends AbstractTable<UsersToUserGroupsTable> {
|
|
3
|
-
groupId: import("..").Column<import("..").PgInteger, true, false, this>;
|
|
4
|
-
userId: import("..").Column<import("..").PgInteger, true, false, this>;
|
|
5
|
-
manyToManyIndex: import("../indexes/tableIndex").default;
|
|
6
|
-
tableName(): string;
|
|
7
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
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 __1 = require("..");
|
|
7
|
-
const userGroupsTable_1 = __importDefault(require("./userGroupsTable"));
|
|
8
|
-
const usersTable_1 = __importDefault(require("./usersTable"));
|
|
9
|
-
class UsersToUserGroupsTable extends __1.AbstractTable {
|
|
10
|
-
constructor() {
|
|
11
|
-
super(...arguments);
|
|
12
|
-
this.groupId = this.int('city_id').foreignKey(userGroupsTable_1.default, (table) => table.id, { onDelete: 'CASCADE' });
|
|
13
|
-
this.userId = this.int('user_id').foreignKey(usersTable_1.default, (table) => table.id, { onDelete: 'CASCADE' });
|
|
14
|
-
this.manyToManyIndex = this.index([this.groupId, this.userId]);
|
|
15
|
-
}
|
|
16
|
-
tableName() {
|
|
17
|
-
return 'users_to_user_groups';
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.default = UsersToUserGroupsTable;
|