drizzle-orm 0.9.3 → 0.9.4

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.
@@ -2,21 +2,21 @@ import DB from '../db/db';
2
2
  import { AbstractTable } from '../tables';
3
3
  import ColumnType from './types/columnType';
4
4
  declare type ExtractColumnType<T extends ColumnType> = T extends ColumnType<infer TCodeType> ? TCodeType : never;
5
- declare type OnConstraint = OnDelete | OnUpdate;
6
5
  export declare enum OnDelete {
7
- RESTRICT = 0,
8
- CASCADE = 1
6
+ RESTRICT = "ON DELETE RESTRICT",
7
+ CASCADE = "ON DELETE CASCADE"
9
8
  }
10
9
  export declare enum OnUpdate {
11
- RESTRICT = 0,
12
- CASCADE = 1
10
+ RESTRICT = "ON UPDATE RESTRICT",
11
+ CASCADE = "ON UPDATE RESTRICT"
13
12
  }
14
13
  export declare abstract class AbstractColumn<T extends ColumnType, TNullable extends boolean = true, TAutoIncrement extends boolean = false> {
15
14
  isNullableFlag: TNullable;
16
15
  autoIncrementType: TAutoIncrement;
17
16
  primaryKeyName?: string;
18
17
  uniqueKeyName?: string;
19
- protected onConstraint?: OnConstraint;
18
+ protected onDelete?: string;
19
+ protected onUpdate?: string;
20
20
  protected parent: AbstractTable<any>;
21
21
  protected parentTableName: string;
22
22
  protected columnType: T;
@@ -25,12 +25,14 @@ export declare abstract class AbstractColumn<T extends ColumnType, TNullable ext
25
25
  protected defaultParam: any;
26
26
  protected referenced: AbstractColumn<T, boolean, boolean>;
27
27
  constructor(parent: AbstractTable<any>, columnName: string, columnType: T, nullable: TNullable);
28
+ getOnDelete: () => string | undefined;
29
+ getOnUpdate: () => string | undefined;
28
30
  getAlias: () => string;
29
31
  getParent: () => AbstractTable<any>;
30
32
  getParentName: () => string;
31
33
  abstract foreignKey<ITable extends AbstractTable<ITable>>(table: {
32
34
  new (db: DB): ITable;
33
- }, callback: (table: ITable) => AbstractColumn<T, boolean, boolean>, onConstraint?: OnConstraint): AbstractColumn<T, TNullable, TAutoIncrement>;
35
+ }, callback: (table: ITable) => AbstractColumn<T, boolean, boolean>, onDelete?: OnDelete, onUpdate?: OnUpdate): AbstractColumn<T, TNullable, TAutoIncrement>;
34
36
  defaultValue: (value: ExtractColumnType<T>) => this;
35
37
  abstract autoIncrement(): AbstractColumn<T, boolean, boolean>;
36
38
  abstract primaryKey(): AbstractColumn<T, boolean, boolean>;
@@ -46,14 +48,14 @@ export declare class Column<T extends ColumnType, TNullable extends boolean = tr
46
48
  constructor(parent: AbstractTable<any>, columnName: string, columnType: T, nullable: TNullable);
47
49
  serial(): Column<T, false, true>;
48
50
  primaryKey(): Column<T, TAutoIncrement extends true ? true : false, TAutoIncrement>;
49
- foreignKey<ITable extends AbstractTable<ITable>>(table: new (db: DB) => ITable, callback: (table: ITable) => Column<T, boolean, boolean>, onConstraint?: OnConstraint): Column<T, TNullable, TAutoIncrement>;
51
+ foreignKey<ITable extends AbstractTable<ITable>>(table: new (db: DB) => ITable, callback: (table: ITable) => Column<T, boolean, boolean>, onDelete?: OnDelete, onUpdate?: OnUpdate): Column<T, TNullable, TAutoIncrement>;
50
52
  autoIncrement(): IndexedColumn<T, true, true>;
51
53
  }
52
54
  export declare class IndexedColumn<T extends ColumnType, TNullable extends boolean = true, TAutoIncrement extends boolean = false> extends AbstractColumn<T, TNullable, TAutoIncrement> {
53
55
  constructor(parent: AbstractTable<any>, columnName: string, columnType: T, nullable: TNullable);
54
56
  serial(): IndexedColumn<T, false, true>;
55
57
  primaryKey(): IndexedColumn<T, TAutoIncrement extends true ? true : false, TAutoIncrement>;
56
- foreignKey<ITable extends AbstractTable<ITable>>(table: new (db: DB) => ITable, callback: (table: ITable) => IndexedColumn<T, boolean, boolean>, onConstraint?: OnConstraint): IndexedColumn<T, TNullable, TAutoIncrement>;
58
+ foreignKey<ITable extends AbstractTable<ITable>>(table: new (db: DB) => ITable, callback: (table: ITable) => IndexedColumn<T, boolean, boolean>, onDelete?: OnDelete, onUpdate?: OnUpdate): IndexedColumn<T, TNullable, TAutoIncrement>;
57
59
  autoIncrement(): IndexedColumn<T, true, true>;
58
60
  }
59
61
  export {};
package/columns/column.js CHANGED
@@ -3,19 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IndexedColumn = exports.Column = exports.AbstractColumn = exports.OnUpdate = exports.OnDelete = void 0;
4
4
  var OnDelete;
5
5
  (function (OnDelete) {
6
- OnDelete[OnDelete["RESTRICT"] = 0] = "RESTRICT";
7
- OnDelete[OnDelete["CASCADE"] = 1] = "CASCADE";
6
+ OnDelete["RESTRICT"] = "ON DELETE RESTRICT";
7
+ OnDelete["CASCADE"] = "ON DELETE CASCADE";
8
8
  })(OnDelete = exports.OnDelete || (exports.OnDelete = {}));
9
9
  var OnUpdate;
10
10
  (function (OnUpdate) {
11
- OnUpdate[OnUpdate["RESTRICT"] = 0] = "RESTRICT";
12
- OnUpdate[OnUpdate["CASCADE"] = 1] = "CASCADE";
11
+ OnUpdate["RESTRICT"] = "ON UPDATE RESTRICT";
12
+ OnUpdate["CASCADE"] = "ON UPDATE RESTRICT";
13
13
  })(OnUpdate = exports.OnUpdate || (exports.OnUpdate = {}));
14
14
  // eslint-disable-next-line max-len
15
15
  class AbstractColumn {
16
16
  constructor(parent, columnName, columnType, nullable) {
17
17
  this.autoIncrementFlag = false;
18
18
  this.defaultParam = null;
19
+ this.getOnDelete = () => this.onDelete;
20
+ this.getOnUpdate = () => this.onUpdate;
19
21
  this.getAlias = () => `${this.parentTableName.replace('.', '_')}_${this.columnName}`;
20
22
  this.getParent = () => this.parent;
21
23
  this.getParentName = () => this.parentTableName;
@@ -54,10 +56,11 @@ class Column extends AbstractColumn {
54
56
  // eslint-disable-next-line max-len
55
57
  return this;
56
58
  }
57
- foreignKey(table, callback, onConstraint) {
59
+ foreignKey(table, callback, onDelete, onUpdate) {
58
60
  const tableInstance = this.getParent().db.create(table);
59
61
  this.referenced = callback(tableInstance);
60
- this.onConstraint = onConstraint;
62
+ this.onDelete = onDelete;
63
+ this.onUpdate = onUpdate;
61
64
  return this;
62
65
  }
63
66
  autoIncrement() {
@@ -80,10 +83,11 @@ class IndexedColumn extends AbstractColumn {
80
83
  // eslint-disable-next-line max-len
81
84
  return this;
82
85
  }
83
- foreignKey(table, callback, onConstraint) {
86
+ foreignKey(table, callback, onDelete, onUpdate) {
84
87
  // eslint-disable-next-line new-cap
85
88
  this.referenced = callback(this.getParent().db.create(table));
86
- this.onConstraint = onConstraint;
89
+ this.onDelete = onDelete;
90
+ this.onUpdate = onUpdate;
87
91
  return this;
88
92
  }
89
93
  autoIncrement() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-orm",
3
- "version": "0.9.3",
3
+ "version": "0.9.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -6,6 +6,8 @@ interface ColumnAsObject {
6
6
  type?: string;
7
7
  primaryKey?: boolean;
8
8
  unique?: boolean;
9
+ onDelete?: string;
10
+ onUpdate?: string;
9
11
  default?: any;
10
12
  notNull?: boolean;
11
13
  references?: {
@@ -37,7 +37,8 @@ class MigrationSerializer {
37
37
  name: value.getColumnName(),
38
38
  type: value.isAutoIncrement() ? 'serial' : value.getColumnType().getDbName(),
39
39
  primaryKey: !!value.primaryKeyName,
40
- // autoincrement: value.isAutoIncrement(),
40
+ onDelete: value.getOnDelete(),
41
+ onUpdate: value.getOnUpdate(),
41
42
  unique: !!value.uniqueKeyName,
42
43
  default: value.getDefaultValue() === null ? undefined : value.getDefaultValue(),
43
44
  notNull: !value.isNullableFlag,