drizzle-orm 0.9.8 → 0.9.12
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/types/columnType.d.ts +1 -1
- package/columns/types/pgBigDecimal.d.ts +1 -1
- package/columns/types/pgBigDecimal.js +1 -1
- package/columns/types/pgBigInt.d.ts +1 -1
- package/columns/types/pgBigInt.js +1 -1
- package/columns/types/pgInteger.d.ts +1 -1
- package/columns/types/pgInteger.js +1 -1
- package/columns/types/pgSmallInt.d.ts +8 -0
- package/columns/types/pgSmallInt.js +15 -0
- package/package.json +1 -1
- package/serializer/serializer.js +2 -3
- package/tables/abstractTable.d.ts +6 -0
- package/tables/abstractTable.js +5 -0
- package/tables/index.d.ts +1 -0
- package/test.js +11 -9
|
@@ -3,5 +3,5 @@ export default abstract class ColumnType<TCodeType = {}> {
|
|
|
3
3
|
protected abstract dbName: string;
|
|
4
4
|
abstract getDbName(): string;
|
|
5
5
|
abstract insertStrategy(value: TCodeType): string;
|
|
6
|
-
abstract selectStrategy(value: any): TCodeType;
|
|
6
|
+
abstract selectStrategy(value: any): TCodeType | undefined;
|
|
7
7
|
}
|
|
@@ -6,5 +6,5 @@ export default class PgBigDecimal extends ColumnType<number> {
|
|
|
6
6
|
constructor(precision?: number, scale?: number);
|
|
7
7
|
getDbName: () => string;
|
|
8
8
|
insertStrategy: (value: number) => string;
|
|
9
|
-
selectStrategy(value: string): number;
|
|
9
|
+
selectStrategy(value: string): number | undefined;
|
|
10
10
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const columnType_1 = require("./columnType");
|
|
4
|
+
class PgSmallInt extends columnType_1.default {
|
|
5
|
+
constructor() {
|
|
6
|
+
super();
|
|
7
|
+
this.getDbName = () => this.dbName;
|
|
8
|
+
this.insertStrategy = (value) => `${value}`;
|
|
9
|
+
this.dbName = 'SMALLINT';
|
|
10
|
+
}
|
|
11
|
+
selectStrategy(value) {
|
|
12
|
+
return value ? parseInt(value, 10) : undefined;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.default = PgSmallInt;
|
package/package.json
CHANGED
package/serializer/serializer.js
CHANGED
|
@@ -15,7 +15,6 @@ class MigrationSerializer {
|
|
|
15
15
|
const columnToReturn = {};
|
|
16
16
|
const indexToReturn = {};
|
|
17
17
|
for (const properties of tableEntries) {
|
|
18
|
-
const key = properties[0];
|
|
19
18
|
const value = properties[1];
|
|
20
19
|
if (value instanceof tableIndex_1.default) {
|
|
21
20
|
const columns = value.getColumns();
|
|
@@ -33,7 +32,7 @@ class MigrationSerializer {
|
|
|
33
32
|
};
|
|
34
33
|
}
|
|
35
34
|
if (value instanceof columns_1.Column) {
|
|
36
|
-
columnToReturn[
|
|
35
|
+
columnToReturn[value.getColumnName()] = {
|
|
37
36
|
name: value.getColumnName(),
|
|
38
37
|
type: value.isAutoIncrement() ? 'serial' : value.getColumnType().getDbName(),
|
|
39
38
|
primaryKey: !!value.primaryKeyName,
|
|
@@ -43,7 +42,7 @@ class MigrationSerializer {
|
|
|
43
42
|
};
|
|
44
43
|
const referenced = value.getReferenced();
|
|
45
44
|
if (referenced) {
|
|
46
|
-
columnToReturn[
|
|
45
|
+
columnToReturn[value.getColumnName()].references = {
|
|
47
46
|
foreignKeyName: `${value.getParent().tableName()}_${value.getColumnName()}_fk`,
|
|
48
47
|
table: referenced.getParentName(),
|
|
49
48
|
column: referenced.getColumnName(),
|
|
@@ -63,6 +63,12 @@ export default abstract class AbstractTable<TTable extends AbstractTable<TTable>
|
|
|
63
63
|
protected int(name: string, params: {
|
|
64
64
|
notNull: true;
|
|
65
65
|
}): Column<PgInteger, false>;
|
|
66
|
+
protected smallInt(name: string, params?: {
|
|
67
|
+
notNull: false;
|
|
68
|
+
}): Column<PgInteger, true>;
|
|
69
|
+
protected smallInt(name: string, params: {
|
|
70
|
+
notNull: true;
|
|
71
|
+
}): Column<PgInteger, false>;
|
|
66
72
|
protected timestamp(name: string, params?: {
|
|
67
73
|
notNull: false;
|
|
68
74
|
}): Column<PgTimestamp, true>;
|
package/tables/abstractTable.js
CHANGED
|
@@ -16,6 +16,7 @@ const pgBigInt_1 = require("../columns/types/pgBigInt");
|
|
|
16
16
|
const pgEnum_1 = require("../columns/types/pgEnum");
|
|
17
17
|
const column_1 = require("../columns/column");
|
|
18
18
|
const tableIndex_1 = require("../indexes/tableIndex");
|
|
19
|
+
const pgSmallInt_1 = require("../columns/types/pgSmallInt");
|
|
19
20
|
class AbstractTable {
|
|
20
21
|
constructor(db) {
|
|
21
22
|
this.withLogger = (logger) => {
|
|
@@ -79,6 +80,10 @@ class AbstractTable {
|
|
|
79
80
|
var _a;
|
|
80
81
|
return new column_1.Column(this, name, new pgInteger_1.default(), (_a = !(params === null || params === void 0 ? void 0 : params.notNull)) !== null && _a !== void 0 ? _a : false);
|
|
81
82
|
}
|
|
83
|
+
smallInt(name, params = {}) {
|
|
84
|
+
var _a;
|
|
85
|
+
return new column_1.Column(this, name, new pgSmallInt_1.default(), (_a = !(params === null || params === void 0 ? void 0 : params.notNull)) !== null && _a !== void 0 ? _a : false);
|
|
86
|
+
}
|
|
82
87
|
timestamp(name, params = {}) {
|
|
83
88
|
var _a;
|
|
84
89
|
return new column_1.Column(this, name, new pgTimestamp_1.default(), (_a = !(params === null || params === void 0 ? void 0 : params.notNull)) !== null && _a !== void 0 ? _a : false);
|
package/tables/index.d.ts
CHANGED
package/test.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const _1 = require(".");
|
|
4
4
|
const usersTable_1 = require("./docs/tables/usersTable");
|
|
5
|
-
const serializer_1 = require("./serializer/serializer");
|
|
6
5
|
// import { Pool } from 'pg';
|
|
7
6
|
// import { DB } from '.';
|
|
8
7
|
// import { DB, DbConnector } from '.';
|
|
@@ -20,12 +19,14 @@ const fromTypeFile = (filepath) => {
|
|
|
20
19
|
(async () => {
|
|
21
20
|
try {
|
|
22
21
|
const db = await new _1.DbConnector()
|
|
23
|
-
.connectionString('postgresql://postgres@127.0.0.1/
|
|
22
|
+
.connectionString('postgresql://postgres@127.0.0.1/migrator')
|
|
24
23
|
.connect();
|
|
25
|
-
const ser = new
|
|
26
|
-
const d = db.create(
|
|
27
|
-
const f = ser.generate([d], []);
|
|
28
|
-
console.log(JSON.stringify(f, null, 2));
|
|
24
|
+
// const ser = new MigrationSerializer();
|
|
25
|
+
// const d = db.create(UsersTable) as unknown as AbstractTable<any>;
|
|
26
|
+
// const f = ser.generate([d], []);
|
|
27
|
+
// console.log(JSON.stringify(f, null, 2));
|
|
28
|
+
// await drizzle.migrator(db).migrate('src/drizzle.config.yaml');
|
|
29
|
+
// drizzle.migrator(db).migrate({ migrationFolder: '' });
|
|
29
30
|
// const typesFileNames = fs.readdirSync('/Users/andrewsherman/IdeaProjects/datalayer-orm/src/examples/types');
|
|
30
31
|
// typesFileNames.forEach((filename) => {
|
|
31
32
|
// const types = fromTypeFile(`./examples/types/${filename.split('.')[0]}`);
|
|
@@ -38,9 +39,10 @@ const fromTypeFile = (filepath) => {
|
|
|
38
39
|
// const db = await new DbConnector()
|
|
39
40
|
// .connectionString('postgresql://postgres@127.0.0.1/drizzle')
|
|
40
41
|
// .connect();
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
//
|
|
42
|
+
const usersTable = new usersTable_1.default(db);
|
|
43
|
+
const res = await db.session().execute(_1.Create.table(db.create(usersTable_1.default)).build());
|
|
44
|
+
// await usersTable.insert({
|
|
45
|
+
// }).execute();
|
|
44
46
|
// if (res.isLeft()) {
|
|
45
47
|
// console.log(res.value.reason);
|
|
46
48
|
// } else {
|