drizzle-orm 0.10.2 → 0.10.3

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,14 @@
1
+ import AbstractTable from '../../tables/abstractTable';
2
+ interface CityMeta {
3
+ population: number;
4
+ connection: string;
5
+ }
6
+ export default class CitiesTable extends AbstractTable<CitiesTable> {
7
+ id: import("../..").Column<import("../../columns/types/pgSerial").default, true, true, this>;
8
+ foundationDate: import("../..").Column<import("../..").PgTimestamp, false, false, this>;
9
+ location: import("../..").Column<import("../..").PgVarChar, true, false, this>;
10
+ userId: import("../..").Column<import("../..").PgInteger, true, false, this>;
11
+ metadata: import("../..").Column<import("../..").PgJsonb<CityMeta>, true, false, this>;
12
+ tableName(): string;
13
+ }
14
+ export {};
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const abstractTable_1 = require("../../tables/abstractTable");
4
+ class CitiesTable extends abstractTable_1.default {
5
+ constructor() {
6
+ super(...arguments);
7
+ this.id = this.serial('id').primaryKey();
8
+ this.foundationDate = this.timestamp('name').notNull();
9
+ this.location = this.varchar('page', { size: 256 });
10
+ this.userId = this.int('user_id').foreignKey(CitiesTable, (table) => table.id, { onUpdate: 'CASCADE' });
11
+ this.metadata = this.jsonb('metadata');
12
+ }
13
+ tableName() {
14
+ return 'cities';
15
+ }
16
+ }
17
+ exports.default = CitiesTable;
@@ -0,0 +1,7 @@
1
+ import AbstractTable from '../../tables/abstractTable';
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 abstractTable_1 = require("../../tables/abstractTable");
4
+ class UserGroupsTable extends abstractTable_1.default {
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,16 @@
1
+ import AbstractTable from '../../tables/abstractTable';
2
+ export declare const rolesEnum: import("../../types/type").default<"user" | "guest" | "admin">;
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, true, this>;
10
+ createdAt: import("../..").Column<import("../..").PgTimestamp, false, false, this>;
11
+ createdAtWithTimezone: import("../..").Column<import("../../columns/types/pgTimestamptz").default, true, false, this>;
12
+ isArchived: import("../..").Column<import("../..").PgBoolean, true, false, this>;
13
+ phoneFullNameIndex: import("../../indexes/tableIndex").default;
14
+ phoneIndex: import("../../indexes/tableIndex").default;
15
+ tableName(): string;
16
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rolesEnum = void 0;
4
+ /* eslint-disable max-classes-per-file */
5
+ // import { Defaults } from '../../columns/column';
6
+ const abstractTable_1 = require("../../tables/abstractTable");
7
+ const type_1 = require("../../types/type");
8
+ // import { rolesEnum } from '../types/rolesType';
9
+ exports.rolesEnum = type_1.createEnum({ alias: 'test-enum', values: ['user', 'guest', 'admin'] });
10
+ class UsersTable extends abstractTable_1.default {
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
+ // public role = this.type(rolesEnum, 'name_in_table', { notNull: true });
20
+ this.createdAt = this.timestamp('created_at').notNull();
21
+ this.createdAtWithTimezone = this.timestamptz('created_at_time_zone');
22
+ // public updatedAt = this.timestamp('updated_at').defaultValue(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 '../../tables/abstractTable';
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,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const abstractTable_1 = require("../../tables/abstractTable");
4
+ const userGroupsTable_1 = require("./userGroupsTable");
5
+ const usersTable_1 = require("./usersTable");
6
+ class UsersToUserGroupsTable extends abstractTable_1.default {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.groupId = this.int('city_id').foreignKey(userGroupsTable_1.default, (table) => table.id, { onDelete: 'CASCADE' });
10
+ this.userId = this.int('user_id').foreignKey(usersTable_1.default, (table) => table.id, { onDelete: 'CASCADE' });
11
+ this.manyToManyIndex = this.index([this.groupId, this.userId]);
12
+ }
13
+ tableName() {
14
+ return 'users_to_user_groups';
15
+ }
16
+ }
17
+ exports.default = UsersToUserGroupsTable;
@@ -0,0 +1 @@
1
+ export declare const rolesEnum: import("../../types/type").default<"foo" | "bar" | "baz">;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rolesEnum = void 0;
4
+ const type_1 = require("../../types/type");
5
+ // eslint-disable-next-line import/prefer-default-export
6
+ exports.rolesEnum = type_1.createEnum({ alias: 'test-enum', values: ['foo', 'bar', 'baz'] });
@@ -22,7 +22,7 @@ class Migrator {
22
22
  const entry = split.trim().split(':');
23
23
  const key = entry[0];
24
24
  const value = entry[1].trim().replace(/['"]+/g, '');
25
- if (key === 'migrationFolder') {
25
+ if (key === 'migrationRootFolder') {
26
26
  // proceed value
27
27
  migrationFolderTo = value;
28
28
  }
@@ -48,7 +48,15 @@ class Migrator {
48
48
  const migrationFiles = fs.readdirSync(`${migrationFolderTo}/${migrationFolder}`);
49
49
  const migrationFile = migrationFiles.filter((file) => file === 'migration.sql')[0];
50
50
  const query = fs.readFileSync(`${migrationFolderTo}/${migrationFolder}/${migrationFile}`).toString();
51
- const folderAsMillis = new Date(migrationFolder).getTime();
51
+ const year = Number(migrationFolder.slice(0, 4));
52
+ // second param for Date() is month index, that started from 0, so we need
53
+ // to decrement a value for month
54
+ const month = Number(migrationFolder.slice(4, 6)) - 1;
55
+ const day = Number(migrationFolder.slice(6, 8));
56
+ const hour = Number(migrationFolder.slice(8, 10));
57
+ const min = Number(migrationFolder.slice(10, 12));
58
+ const sec = Number(migrationFolder.slice(12, 14));
59
+ const folderAsMillis = new Date(year, month, day, hour, min, sec).getTime();
52
60
  if (!lastDbMigration || lastDbMigration.createdAt < folderAsMillis) {
53
61
  await this.db.session().execute(query);
54
62
  await migrationTable.insert({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-orm",
3
- "version": "0.10.2",
3
+ "version": "0.10.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/test.js CHANGED
@@ -1,11 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const _1 = require(".");
4
- const citiesTable_1 = require("./docs/tables/citiesTable");
5
- const usersTable_1 = require("./docs/tables/usersTable");
6
- const usersToUserGroups_1 = require("./docs/tables/usersToUserGroups");
7
4
  const consoleLogger_1 = require("./logger/consoleLogger");
8
- const serializer_1 = require("./serializer/serializer");
9
5
  // import { Pool } from 'pg';
10
6
  // import { DB } from '.';
11
7
  // import { DB, DbConnector } from '.';
@@ -26,18 +22,41 @@ const fromTypeFile = (filepath) => {
26
22
  .connectionString('postgresql://postgres@127.0.0.1/migrator')
27
23
  .connect();
28
24
  db.useLogger(new consoleLogger_1.default());
29
- const table = new usersTable_1.default(db);
30
- const cities = new citiesTable_1.default(db);
31
- const d = new usersToUserGroups_1.default(db);
32
- const serializer = new serializer_1.default();
33
- const res = serializer.generate([table], []);
34
- console.log(JSON.stringify(res, null, 2));
25
+ // const table = new UsersTable(db);
26
+ // const cities = new CitiesTable(db);
27
+ // const d = new UsersToUserGroupsTable(db);
28
+ // SELECT * FROM users WHERE id = $1 and name = $2
29
+ // const res = notEq(table.id, 1).toQuery();
30
+ // const res1 = and([notEq(table.id, 1), like(table.phone, 'phone')]).toQuery();
31
+ // const res2 = and([
32
+ // or([
33
+ // notEq(table.id, 1),
34
+ // like(table.phone, 'phone')]),
35
+ // or([notEq(table.id, 2),
36
+ // like(table.phone, 'phone2'),
37
+ // and([notEq(table.id, 1),
38
+ // eq(table.isArchived, true),
39
+ // ]),
40
+ // ]),
41
+ // ]).toQuery();
42
+ // const res3 = and([notEq(table.id, 2),
43
+ // like(table.phone, 'phone2'),
44
+ // or([
45
+ // notEq(table.id, 1),
46
+ // like(table.phone, 'phone')]),
47
+ // ]).toQuery();
48
+ // // console.log(res);
49
+ // console.log(res2);
50
+ // console.log(res3);
51
+ // const serializer = new MigrationSerializer();
52
+ // const res = serializer.generate([table], []);
53
+ // console.log(JSON.stringify(res, null, 2));
35
54
  // fs.writeFileSync('introspected.json', JSON.stringify(res, null, 2), 'utf8');
36
55
  // const ser = new MigrationSerializer();
37
56
  // const d = db.create(UsersTable) as unknown as AbstractTable<any>;
38
57
  // const f = ser.generate([d], []);
39
58
  // console.log(JSON.stringify(f, null, 2));
40
- // await drizzle.migrator(db).migrate('drizzle.config.yaml');
59
+ await _1.drizzle.migrator(db).migrate('drizzle.config.yml');
41
60
  // await drizzle.migrator(db).migrate({ migrationFolder: 'drizzle' });
42
61
  // const typesFileNames = fs.readdirSync('/Users/andrewsherman/IdeaProjects/datalayer-orm/src/examples/types');
43
62
  // typesFileNames.forEach((filename) => {