drizzle-orm 0.10.17 → 0.10.18

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.
@@ -19,19 +19,21 @@ export declare abstract class AbstractColumn<T extends ColumnType, TNullable ext
19
19
  protected columnType: T;
20
20
  protected columnName: string;
21
21
  protected defaultParam: any;
22
- protected referenced: AbstractColumn<T, boolean, boolean, TParent>;
22
+ protected referenced: AbstractColumn<T, boolean, boolean>;
23
23
  constructor(parent: TParent, columnName: string, columnType: T);
24
24
  getOnDelete: () => string | undefined;
25
25
  getOnUpdate: () => string | undefined;
26
26
  getAlias: () => string;
27
27
  getParent: () => AbstractTable<any>;
28
28
  getParentName: () => string;
29
- abstract foreignKey<ITable extends AbstractTable<ITable>>(table: {
30
- new (db: DB): ITable;
31
- }, callback: (table: ITable) => AbstractColumn<any, boolean, boolean, TParent>, onConstraint: {
29
+ abstract foreignKey<ITable extends AbstractTable<ITable>>(table: new (db: DB) => ITable, callback: (table: ITable) => Column<any, boolean, boolean, ITable>, onConstraint?: {
32
30
  onDelete?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT';
33
31
  onUpdate?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT';
34
- }): AbstractColumn<T, TNullable, TAutoIncrement>;
32
+ }): AbstractColumn<T, TNullable, TAutoIncrement, TParent>;
33
+ abstract selfForeignKey(column: Column<any, boolean, boolean, TParent>, onConstraint?: {
34
+ onDelete?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT';
35
+ onUpdate?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT';
36
+ }): AbstractColumn<T, TNullable, TAutoIncrement, TParent>;
35
37
  defaultValue: (value: ExtractColumnType<T>) => this;
36
38
  abstract primaryKey(): AbstractColumn<T, boolean, boolean, TParent>;
37
39
  unique: () => this;
@@ -45,11 +47,11 @@ export declare class Column<T extends ColumnType, TNullable extends boolean = tr
45
47
  constructor(parent: TParent, columnName: string, columnType: T);
46
48
  notNull(): Column<T, TAutoIncrement extends true ? true : TNullable extends true ? false : true, TAutoIncrement, TParent>;
47
49
  primaryKey(): Column<T, TAutoIncrement extends true ? true : false, TAutoIncrement, TParent>;
48
- foreignKey(table: new (db: DB) => TParent, callback: (table: this) => Column<any, boolean, boolean, TParent>, onConstraint?: {
50
+ foreignKey<ITable extends AbstractTable<ITable>>(table: new (db: DB) => ITable, callback: (table: ITable) => Column<any, boolean, boolean, ITable>, onConstraint?: {
49
51
  onDelete?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT';
50
52
  onUpdate?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT';
51
53
  }): Column<T, TNullable, TAutoIncrement, TParent>;
52
- foreignKey<ITable extends AbstractTable<ITable>>(table: new (db: DB) => ITable, callback: (table: ITable) => Column<any, boolean, boolean, ITable>, onConstraint?: {
54
+ selfForeignKey(column: Column<any, boolean, boolean, TParent>, onConstraint?: {
53
55
  onDelete?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT';
54
56
  onUpdate?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT';
55
57
  }): Column<T, TNullable, TAutoIncrement, TParent>;
@@ -58,7 +60,11 @@ export declare class IndexedColumn<T extends ColumnType, TNullable extends boole
58
60
  constructor(parent: TParent, columnName: string, columnType: T, nullable: TNullable);
59
61
  notNull(): IndexedColumn<T, TAutoIncrement extends true ? true : TNullable extends true ? false : true, TAutoIncrement, TParent>;
60
62
  primaryKey(): IndexedColumn<T, TAutoIncrement extends true ? true : false, TAutoIncrement, TParent>;
61
- foreignKey<ITable extends AbstractTable<ITable>>(table: new (db: DB) => ITable, callback: (table: ITable) => IndexedColumn<T, boolean, boolean, TParent>, onConstraint?: {
63
+ foreignKey<ITable extends AbstractTable<ITable>>(table: new (db: DB) => ITable, callback: (table: ITable) => Column<any, boolean, boolean, ITable>, onConstraint?: {
64
+ onDelete?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT';
65
+ onUpdate?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT';
66
+ }): IndexedColumn<T, TNullable, TAutoIncrement, TParent>;
67
+ selfForeignKey<ITable extends AbstractTable<ITable>>(column: Column<any, boolean, boolean, TParent>, onConstraint?: {
62
68
  onDelete?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT';
63
69
  onUpdate?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT';
64
70
  }): IndexedColumn<T, TNullable, TAutoIncrement, TParent>;
package/columns/column.js CHANGED
@@ -56,19 +56,18 @@ class Column extends AbstractColumn {
56
56
  return this;
57
57
  }
58
58
  foreignKey(table, callback, onConstraint) {
59
- let tableInstance;
60
- // eslint-disable-next-line new-cap
61
- if (typeof this !== typeof this.getParent()) {
62
- tableInstance = this.getParent().db.create(table);
63
- }
64
- else {
65
- tableInstance = this;
66
- }
59
+ const tableInstance = this.getParent().db.create(table);
67
60
  this.referenced = callback(tableInstance);
68
61
  this.onDelete = (onConstraint === null || onConstraint === void 0 ? void 0 : onConstraint.onDelete) ? `ON DELETE ${onConstraint.onDelete}` : undefined;
69
62
  this.onUpdate = (onConstraint === null || onConstraint === void 0 ? void 0 : onConstraint.onUpdate) ? `ON UPDATE ${onConstraint.onUpdate}` : undefined;
70
63
  return this;
71
64
  }
65
+ selfForeignKey(column, onConstraint) {
66
+ this.referenced = column;
67
+ this.onDelete = (onConstraint === null || onConstraint === void 0 ? void 0 : onConstraint.onDelete) ? `ON DELETE ${onConstraint.onDelete}` : undefined;
68
+ this.onUpdate = (onConstraint === null || onConstraint === void 0 ? void 0 : onConstraint.onUpdate) ? `ON UPDATE ${onConstraint.onUpdate}` : undefined;
69
+ return this;
70
+ }
72
71
  }
73
72
  exports.Column = Column;
74
73
  // eslint-disable-next-line max-len
@@ -92,5 +91,11 @@ class IndexedColumn extends AbstractColumn {
92
91
  this.onUpdate = (onConstraint === null || onConstraint === void 0 ? void 0 : onConstraint.onUpdate) ? `ON UPDATE ${onConstraint.onUpdate}` : undefined;
93
92
  return this;
94
93
  }
94
+ selfForeignKey(column, onConstraint) {
95
+ this.referenced = column;
96
+ this.onDelete = (onConstraint === null || onConstraint === void 0 ? void 0 : onConstraint.onDelete) ? `ON DELETE ${onConstraint.onDelete}` : undefined;
97
+ this.onUpdate = (onConstraint === null || onConstraint === void 0 ? void 0 : onConstraint.onUpdate) ? `ON UPDATE ${onConstraint.onUpdate}` : undefined;
98
+ return this;
99
+ }
95
100
  }
96
101
  exports.IndexedColumn = IndexedColumn;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-orm",
3
- "version": "0.10.17",
3
+ "version": "0.10.18",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/test.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const dbConnector_1 = require("./db/dbConnector");
4
- const usersTable_1 = require("./docs/tables/usersTable");
4
+ const citiesTable_1 = require("./docs/tables/citiesTable");
5
5
  const consoleLogger_1 = require("./logger/consoleLogger");
6
6
  const serializer_1 = require("./serializer/serializer");
7
7
  (async () => {
@@ -9,7 +9,7 @@ const serializer_1 = require("./serializer/serializer");
9
9
  const db = await new dbConnector_1.default()
10
10
  .connectionString('postgresql://postgres@127.0.0.1/migrator')
11
11
  .connect();
12
- const usersTable = new usersTable_1.default(db);
12
+ const usersTable = new citiesTable_1.default(db);
13
13
  db.useLogger(new consoleLogger_1.default());
14
14
  const ser = new serializer_1.default();
15
15
  const res = ser.generate([usersTable], []);