drizzle-orm 0.10.36 → 0.10.37

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
+ }
@@ -8,6 +8,11 @@ export declare enum Defaults {
8
8
  }
9
9
  declare type PgTimes = PgTimestamptz | PgTime | PgTimestamp;
10
10
  export declare type ExtractColumnType<T extends ColumnType> = T extends ColumnType<infer TCodeType> ? T extends PgTimes ? TCodeType | Defaults : TCodeType : never;
11
+ export declare class RawValue {
12
+ value: string;
13
+ constructor(value: string);
14
+ }
15
+ export declare const rawValue: (value: string) => RawValue;
11
16
  export declare abstract class AbstractColumn<T extends ColumnType, TNullable extends boolean = true, TAutoIncrement extends boolean = false, TParent extends AbstractTable<any> = any> {
12
17
  isNullableFlag: boolean;
13
18
  primaryKeyName?: string;
@@ -34,7 +39,7 @@ export declare abstract class AbstractColumn<T extends ColumnType, TNullable ext
34
39
  onDelete?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT';
35
40
  onUpdate?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT';
36
41
  }): AbstractColumn<T, TNullable, TAutoIncrement, TParent>;
37
- defaultValue: (value: ExtractColumnType<T>) => this;
42
+ defaultValue(value: ExtractColumnType<T> | RawValue): AbstractColumn<T, boolean, boolean, TParent>;
38
43
  abstract primaryKey(): AbstractColumn<T, boolean, boolean, TParent>;
39
44
  unique: () => this;
40
45
  abstract notNull(): AbstractColumn<T, boolean, boolean, TParent>;
@@ -45,6 +50,7 @@ export declare abstract class AbstractColumn<T extends ColumnType, TNullable ext
45
50
  }
46
51
  export declare class Column<T extends ColumnType, TNullable extends boolean = true, TAutoIncrement extends boolean = false, TParent extends AbstractTable<any> = any> extends AbstractColumn<T, TNullable, TAutoIncrement, TParent> {
47
52
  constructor(parent: TParent, columnName: string, columnType: T);
53
+ defaultValue: (value: ExtractColumnType<T> | RawValue) => Column<T, true, TAutoIncrement, TParent>;
48
54
  notNull(): Column<T, TAutoIncrement extends true ? true : TNullable extends true ? false : true, TAutoIncrement, TParent>;
49
55
  primaryKey(): Column<T, TAutoIncrement extends true ? true : false, TAutoIncrement, TParent>;
50
56
  foreignKey<ITable extends AbstractTable<ITable>>(table: new (db: DB) => ITable, callback: (table: ITable) => Column<any, boolean, boolean, ITable>, onConstraint?: {
@@ -58,6 +64,7 @@ export declare class Column<T extends ColumnType, TNullable extends boolean = tr
58
64
  }
59
65
  export declare class IndexedColumn<T extends ColumnType, TNullable extends boolean = true, TAutoIncrement extends boolean = false, TParent extends AbstractTable<any> = any> extends AbstractColumn<T, TNullable, TAutoIncrement, TParent> {
60
66
  constructor(parent: TParent, columnName: string, columnType: T, nullable: TNullable);
67
+ defaultValue: (value: ExtractColumnType<T> | RawValue) => IndexedColumn<T, true, TAutoIncrement, TParent>;
61
68
  notNull(): IndexedColumn<T, TAutoIncrement extends true ? true : TNullable extends true ? false : true, TAutoIncrement, TParent>;
62
69
  primaryKey(): IndexedColumn<T, TAutoIncrement extends true ? true : false, TAutoIncrement, TParent>;
63
70
  foreignKey<ITable extends AbstractTable<ITable>>(table: new (db: DB) => ITable, callback: (table: ITable) => Column<any, boolean, boolean, ITable>, onConstraint?: {
package/columns/column.js CHANGED
@@ -1,10 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IndexedColumn = exports.Column = exports.AbstractColumn = exports.Defaults = void 0;
3
+ exports.IndexedColumn = exports.Column = exports.AbstractColumn = exports.rawValue = exports.RawValue = exports.Defaults = void 0;
4
4
  var Defaults;
5
5
  (function (Defaults) {
6
6
  Defaults["CURRENT_TIMESTAMP"] = "CURRENT_TIMESTAMP";
7
7
  })(Defaults = exports.Defaults || (exports.Defaults = {}));
8
+ class RawValue {
9
+ constructor(value) {
10
+ this.value = value;
11
+ }
12
+ }
13
+ exports.RawValue = RawValue;
14
+ const rawValue = (value) => new RawValue(value);
15
+ exports.rawValue = rawValue;
8
16
  // eslint-disable-next-line max-len
9
17
  class AbstractColumn {
10
18
  constructor(parent, columnName, columnType) {
@@ -15,18 +23,6 @@ class AbstractColumn {
15
23
  this.getAlias = () => `${this.parentTableName.replace('.', '_')}_${this.columnName}`;
16
24
  this.getParent = () => this.parent;
17
25
  this.getParentName = () => this.parentTableName;
18
- this.defaultValue = (value) => {
19
- if (Defaults[value] !== undefined) {
20
- this.defaultParam = value;
21
- }
22
- else if (typeof value === 'boolean' || typeof value === 'number' || typeof value === 'bigint') {
23
- this.defaultParam = value;
24
- }
25
- else {
26
- this.defaultParam = `'${value}'`;
27
- }
28
- return this;
29
- };
30
26
  this.unique = () => {
31
27
  this.uniqueKeyName = this.columnName;
32
28
  return this;
@@ -40,12 +36,31 @@ class AbstractColumn {
40
36
  this.parentTableName = parent.tableName();
41
37
  this.parent = parent;
42
38
  }
39
+ defaultValue(value) {
40
+ if (value instanceof RawValue) {
41
+ this.defaultParam = value.value;
42
+ }
43
+ else if (Defaults[value] !== undefined) {
44
+ this.defaultParam = value;
45
+ }
46
+ else if (typeof value === 'boolean' || typeof value === 'number' || typeof value === 'bigint') {
47
+ this.defaultParam = value;
48
+ }
49
+ else {
50
+ this.defaultParam = `'${value}'`;
51
+ }
52
+ return this;
53
+ }
43
54
  }
44
55
  exports.AbstractColumn = AbstractColumn;
45
56
  // eslint-disable-next-line max-len
46
57
  class Column extends AbstractColumn {
47
58
  constructor(parent, columnName, columnType) {
48
59
  super(parent, columnName, columnType);
60
+ this.defaultValue = (value) => {
61
+ super.defaultValue(value);
62
+ return this;
63
+ };
49
64
  }
50
65
  notNull() {
51
66
  this.isNullableFlag = false;
@@ -74,6 +89,10 @@ exports.Column = Column;
74
89
  class IndexedColumn extends AbstractColumn {
75
90
  constructor(parent, columnName, columnType, nullable) {
76
91
  super(parent, columnName, columnType);
92
+ this.defaultValue = (value) => {
93
+ super.defaultValue(value);
94
+ return this;
95
+ };
77
96
  }
78
97
  notNull() {
79
98
  this.isNullableFlag = false;
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-orm",
3
- "version": "0.10.36",
3
+ "version": "0.10.37",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/test.d.ts CHANGED
@@ -1 +0,0 @@
1
- export {};
package/test.js CHANGED
@@ -1,65 +1,60 @@
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
+ // import MigrationSerializer from './serializer/serializer';
8
+ // import AbstractTable from './tables/abstractTable';
9
+ // (async () => {
10
+ // try {
11
+ // const db = await new DbConnector()
12
+ // .connectionString('postgresql://postgres@127.0.0.1/migrator')
13
+ // .connect();
14
+ // db.useLogger(new ConsoleLogger());
15
+ // const usersTable = new UsersTable(db);
16
+ // // const citiesTable = new CitiesTable(db);
17
+ // // const res = await citiesTable.update()
18
+ // // // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
19
+ // // .where(eq(citiesTable.location, 'YR'))
20
+ // // .set({
21
+ // // metadata: [{
22
+ // // fallback_image: true,
23
+ // // team_image: 'https://files.slack.com/files-pri/T016CCC3FE3-F03461UR9M5/clinic_team_photo_1.jpg?pub_secret=560c098bfb',
24
+ // // image_alt_text: 'Generic Physiotherapy Clinic image 1',
25
+ // // logo: '',
26
+ // // logo_alt_text: ''
27
+ // // }],
28
+ // // })
29
+ // // // .leftJoin(CitiesTable, UsersTable, (table) => table.userId, (table) => table.id)
30
+ // // // .leftJoin(UsersTable, UsersTable, (table) => table.id, (table) => table.id)
31
+ // // .execute();
32
+ // // console.log(res);
33
+ // const ser = new MigrationSerializer();
34
+ // const res = ser.generate([usersTable as AbstractTable<UsersTable>], []);
35
+ // console.log(JSON.stringify(res, null, 2));
36
+ // // const f = {
37
+ // // id: count(usersTable.id),
38
+ // // };
39
+ // // type d = ExtractModel<typeof f>;
40
+ // // const res = await usersTable.select()
41
+ // // .leftJoin(UsersTable, (table) => table.id, (table) => table.id)
42
+ // // .leftJoin(UsersTable, CitiesTable, (table) => table.id, (table) => table.id)
43
+ // // .execute();
44
+ // // const res = await usersTable.select()
45
+ // // // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
46
+ // // .leftJoin(UsersTable, (table) => table.foundationDate, (table) => table.id)
47
+ // // .leftJoin(UsersTable, UsersTable, (table) => table.role, (table) => table.id)
48
+ // // .leftJoin(UsersTable, UsersTable, (table) => table.role, (table) => table.id)
49
+ // // // .groupBy({
50
+ // // // usersTable: usersTable.id,
51
+ // // // firstJoin: [usersTable.id],
52
+ // // // secondJoin: usersTable.id,
53
+ // // // thirdJoin: usersTable.id,
54
+ // // // })
55
+ // // .execute();
56
+ // // console.log(res);
57
+ // } catch (e) {
58
+ // console.log(e);
59
+ // }
60
+ // })();