drizzle-orm 0.10.1 → 0.10.2
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.
- package/columns/column.d.ts +5 -5
- package/package.json +1 -1
- package/serializer/serializer.js +13 -1
- package/test.js +5 -1
package/columns/column.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ 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>;
|
|
22
|
+
protected referenced: AbstractColumn<T, boolean, boolean, TParent>;
|
|
23
23
|
constructor(parent: TParent, columnName: string, columnType: T);
|
|
24
24
|
getOnDelete: () => string | undefined;
|
|
25
25
|
getOnUpdate: () => string | undefined;
|
|
@@ -28,16 +28,16 @@ export declare abstract class AbstractColumn<T extends ColumnType, TNullable ext
|
|
|
28
28
|
getParentName: () => string;
|
|
29
29
|
abstract foreignKey<ITable extends AbstractTable<ITable>>(table: {
|
|
30
30
|
new (db: DB): ITable;
|
|
31
|
-
}, callback: (table: ITable) => AbstractColumn<T, boolean, boolean>, onConstraint: {
|
|
31
|
+
}, callback: (table: ITable) => AbstractColumn<T, boolean, boolean, TParent>, onConstraint: {
|
|
32
32
|
onDelete?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT';
|
|
33
33
|
onUpdate?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT';
|
|
34
34
|
}): AbstractColumn<T, TNullable, TAutoIncrement>;
|
|
35
35
|
defaultValue: (value: ExtractColumnType<T>) => this;
|
|
36
|
-
abstract primaryKey(): AbstractColumn<T, boolean, boolean>;
|
|
36
|
+
abstract primaryKey(): AbstractColumn<T, boolean, boolean, TParent>;
|
|
37
37
|
unique: () => this;
|
|
38
|
-
abstract notNull(): AbstractColumn<T, boolean, boolean>;
|
|
38
|
+
abstract notNull(): AbstractColumn<T, boolean, boolean, TParent>;
|
|
39
39
|
getColumnName: () => string;
|
|
40
|
-
getReferenced: () => AbstractColumn<T, boolean, boolean>;
|
|
40
|
+
getReferenced: () => AbstractColumn<T, boolean, boolean, TParent>;
|
|
41
41
|
getColumnType: () => T;
|
|
42
42
|
getDefaultValue: () => any;
|
|
43
43
|
}
|
package/package.json
CHANGED
package/serializer/serializer.js
CHANGED
|
@@ -38,10 +38,22 @@ class MigrationSerializer {
|
|
|
38
38
|
name: value.getColumnName(),
|
|
39
39
|
type: value.getColumnType().getDbName(),
|
|
40
40
|
primaryKey: !!value.primaryKeyName,
|
|
41
|
-
unique: !!value.uniqueKeyName,
|
|
41
|
+
// unique: !!value.uniqueKeyName,
|
|
42
42
|
default: value.getDefaultValue() === null ? undefined : value.getDefaultValue(),
|
|
43
43
|
notNull: !value.isNullableFlag,
|
|
44
44
|
};
|
|
45
|
+
if (value.uniqueKeyName) {
|
|
46
|
+
const indexName = `${value.getParent().tableName()}_${value.getColumnName()}_index`;
|
|
47
|
+
const indexColumnToReturn = {};
|
|
48
|
+
indexColumnToReturn[value.getColumnName()] = {
|
|
49
|
+
name: value.getColumnName(),
|
|
50
|
+
};
|
|
51
|
+
indexToReturn[indexName] = {
|
|
52
|
+
name: indexName,
|
|
53
|
+
columns: indexColumnToReturn,
|
|
54
|
+
isUnique: true,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
45
57
|
const referenced = value.getReferenced();
|
|
46
58
|
if (referenced) {
|
|
47
59
|
columnToReturn[value.getColumnName()].references = {
|
package/test.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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");
|
|
4
6
|
const usersToUserGroups_1 = require("./docs/tables/usersToUserGroups");
|
|
5
7
|
const consoleLogger_1 = require("./logger/consoleLogger");
|
|
6
8
|
const serializer_1 = require("./serializer/serializer");
|
|
@@ -24,7 +26,9 @@ const fromTypeFile = (filepath) => {
|
|
|
24
26
|
.connectionString('postgresql://postgres@127.0.0.1/migrator')
|
|
25
27
|
.connect();
|
|
26
28
|
db.useLogger(new consoleLogger_1.default());
|
|
27
|
-
const table = new
|
|
29
|
+
const table = new usersTable_1.default(db);
|
|
30
|
+
const cities = new citiesTable_1.default(db);
|
|
31
|
+
const d = new usersToUserGroups_1.default(db);
|
|
28
32
|
const serializer = new serializer_1.default();
|
|
29
33
|
const res = serializer.generate([table], []);
|
|
30
34
|
console.log(JSON.stringify(res, null, 2));
|