drizzle-orm 0.10.31 → 0.10.34

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.
@@ -0,0 +1,16 @@
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
+ }
@@ -0,0 +1,9 @@
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
+ }
@@ -0,0 +1,22 @@
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;
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,15 @@
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;
@@ -0,0 +1,17 @@
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
+ }
@@ -0,0 +1,31 @@
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;
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,20 @@
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;
@@ -31,6 +31,7 @@ const crypto = __importStar(require("crypto"));
31
31
  const builders_1 = require("../builders");
32
32
  const transaction_1 = __importDefault(require("../builders/transaction/transaction"));
33
33
  const tables_1 = require("../tables");
34
+ const order_1 = __importDefault(require("../builders/highLvlBuilders/order"));
34
35
  class Migrator {
35
36
  constructor(db) {
36
37
  this.db = db;
@@ -59,10 +60,12 @@ class Migrator {
59
60
  }
60
61
  const migrationTable = new tables_1.MigrationsTable(this.db);
61
62
  await this.db.session().execute(builders_1.Create.table(migrationTable).build());
62
- const dbMigrations = await migrationTable.select().all();
63
- const lastDbMigration = dbMigrations.length > 0
64
- ? dbMigrations[dbMigrations.length - 1]
65
- : undefined;
63
+ const dbMigrations = await migrationTable.select()
64
+ .limit(1)
65
+ .orderBy((table) => table.createdAt, order_1.default.DESC)
66
+ .all();
67
+ const lastDbMigration = dbMigrations[0];
68
+ console.log('Last migration in database: ', lastDbMigration.hash);
66
69
  const files = fs.readdirSync(migrationFolderTo);
67
70
  const transaction = new transaction_1.default(this.db.session());
68
71
  await transaction.begin();
@@ -80,7 +83,10 @@ class Migrator {
80
83
  const min = Number(migrationFolder.slice(10, 12));
81
84
  const sec = Number(migrationFolder.slice(12, 14));
82
85
  const folderAsMillis = new Date(year, month, day, hour, min, sec).getTime();
86
+ console.log(`Check if migration ${migrationFolder} should be executed.`);
87
+ console.log(`Folder name to millis = ${folderAsMillis}`);
83
88
  if (!lastDbMigration || lastDbMigration.createdAt < folderAsMillis) {
89
+ console.log(`Executing ${migrationFolder} migration`);
84
90
  await this.db.session().execute(query);
85
91
  await migrationTable.insert({
86
92
  hash: this.generateHash(query),
@@ -91,10 +97,7 @@ class Migrator {
91
97
  await transaction.commit();
92
98
  }
93
99
  catch (e) {
94
- // if (this.db.logger()) {
95
- // this.db.logger()!.error(e);
96
- // }
97
- transaction.rollback();
100
+ await transaction.rollback();
98
101
  throw e;
99
102
  }
100
103
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "drizzle-orm",
3
- "version": "0.10.31",
3
+ "version": "0.10.34",
4
4
  "description": "",
5
- "main": "index.js",
6
- "types": "index.d.ts",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/lambda-direct/drizzle-orm.git",
package/test.d.ts CHANGED
@@ -1 +0,0 @@
1
- export {};
package/test.js CHANGED
@@ -1,65 +1,66 @@
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 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
- })();
2
+ // import { eq } from './builders/requestBuilders/where/static';
3
+ // import DbConnector from './db/dbConnector';
4
+ // import CitiesTable from './docs/tables/citiesTable';
5
+ // import UsersTable from './docs/tables/usersTable';
6
+ // import ConsoleLogger from './logger/consoleLogger';
7
+ // (async () => {
8
+ // try {
9
+ // const db = await new DbConnector()
10
+ // .connectionString('postgresql://postgres@127.0.0.1/migrator')
11
+ // .connect();
12
+ // db.useLogger(new ConsoleLogger());
13
+ // // const usersTable = new UsersTable(db);
14
+ // const citiesTable = new CitiesTable(db);
15
+ // const res = await citiesTable.update()
16
+ // // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
17
+ // .where(eq(citiesTable.location, 'YR'))
18
+ // .set({
19
+ // metadata: [{
20
+ // fallback_image: true,
21
+ // team_image: 'https://files.slack.com/files-pri/T016CCC3FE3-F03461UR9M5/clinic_team_photo_1.jpg?pub_secret=560c098bfb',
22
+ // image_alt_text: 'Generic Physiotherapy Clinic image 1',
23
+ // logo: '',
24
+ // logo_alt_text: ''
25
+ // }],
26
+ // })
27
+ // // .leftJoin(CitiesTable, UsersTable, (table) => table.userId, (table) => table.id)
28
+ // // .leftJoin(UsersTable, UsersTable, (table) => table.id, (table) => table.id)
29
+ // .execute();
30
+ // // console.log(res);
31
+ // // const ser = new MigrationSerializer();
32
+ // // const res = ser.generate([usersTable as AbstractTable<UsersTable>], []);
33
+ // // console.log(JSON.stringify(res, null, 2));
34
+ // // const f = {
35
+ // // id: count(usersTable.id),
36
+ // // };
37
+ // // type d = ExtractModel<typeof f>;
38
+ // // const res = await usersTable.select({
39
+ // // piska: count(),
40
+ // // mongodibil: count(usersTable.phone),
41
+ // // })
42
+ // // .where({
43
+ // // piska: eq(),
44
+ // // mongodibil: eq(usersTable.phone),
45
+ // // }).leftJoin(UsersTable, (table) => table.id, (table) => table.id)
46
+ // // .leftJoin(UsersTable, UsersTable, (table) => table.id, (table) => table.id)
47
+ // // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
48
+ // // .orderBy((table, join1, join2, join3) => [{table.id}, join1.id, join1.phone])
49
+ // // .execute();
50
+ // // const res = await usersTable.select()
51
+ // // // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
52
+ // // .leftJoin(UsersTable, (table) => table.foundationDate, (table) => table.id)
53
+ // // .leftJoin(UsersTable, UsersTable, (table) => table.role, (table) => table.id)
54
+ // // .leftJoin(UsersTable, UsersTable, (table) => table.role, (table) => table.id)
55
+ // // // .groupBy({
56
+ // // // usersTable: usersTable.id,
57
+ // // // firstJoin: [usersTable.id],
58
+ // // // secondJoin: usersTable.id,
59
+ // // // thirdJoin: usersTable.id,
60
+ // // // })
61
+ // // .execute();
62
+ // // console.log(res);
63
+ // } catch (e) {
64
+ // console.log(e);
65
+ // }
66
+ // })();