@ignisia/sql 0.2.2 → 0.3.0
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/dist/cjs/column/constants.d.cts +58 -5
- package/dist/cjs/column/constants.js +79 -22
- package/dist/cjs/column/index.d.cts +1 -0
- package/dist/cjs/column/index.js +30 -10
- package/dist/cjs/column/utils.d.cts +133 -0
- package/dist/cjs/column/utils.js +34 -0
- package/dist/cjs/database/alter.d.cts +3 -2
- package/dist/cjs/database/alter.js +15 -15
- package/dist/cjs/database/column.d.cts +3 -2
- package/dist/cjs/database/column.js +9 -7
- package/dist/cjs/database/contract.d.cts +3 -2
- package/dist/cjs/database/index.d.cts +3 -2
- package/dist/cjs/database/index.js +14 -1
- package/dist/cjs/database/table.d.cts +3 -2
- package/dist/cjs/database/table.js +12 -4
- package/dist/cjs/database/types.d.cts +2 -1
- package/dist/cjs/database/wrapper.d.cts +17 -21
- package/dist/cjs/database/wrapper.js +44 -52
- package/dist/cjs/{index---zaMa69.d.cts → index-2jl8MRfX.d.cts} +4 -2
- package/dist/cjs/{index-CwiFQh0I.d.cts → index-CnQVnCEI.d.cts} +80 -46
- package/dist/cjs/index.d.cts +3 -2
- package/dist/cjs/migration/index.d.cts +3 -2
- package/dist/cjs/migration/runner.js +1 -1
- package/dist/cjs/migration/type.d.cts +3 -2
- package/dist/cjs/query/builder.d.cts +2 -1
- package/dist/cjs/query/condition.d.cts +2 -1
- package/dist/cjs/query/condition.js +5 -2
- package/dist/cjs/query/contract.d.cts +3 -2
- package/dist/cjs/query/helper.d.cts +2 -1
- package/dist/cjs/query/index.d.cts +2 -1
- package/dist/cjs/query/index.js +16 -7
- package/dist/cjs/query/join.d.cts +2 -1
- package/dist/cjs/query/sql.d.cts +5 -4
- package/dist/cjs/query/sql.js +36 -8
- package/dist/cjs/query/types.d.cts +2 -1
- package/dist/cjs/query/utilities.d.cts +4 -1
- package/dist/cjs/query/utilities.js +15 -5
- package/dist/cjs/table/constants.d.cts +1 -0
- package/dist/cjs/table/constants.js +1 -0
- package/dist/cjs/table/index.d.cts +2 -1
- package/dist/cjs/table/index.js +29 -9
- package/dist/cjs/table/types.d.cts +2 -1
- package/dist/cjs/table/utilities.d.cts +2 -1
- package/dist/esm/column/constants.d.ts +58 -5
- package/dist/esm/column/constants.js +78 -23
- package/dist/esm/column/index.d.ts +1 -0
- package/dist/esm/column/index.js +30 -10
- package/dist/esm/column/utils.d.ts +133 -0
- package/dist/esm/column/utils.js +32 -0
- package/dist/esm/database/alter.d.ts +3 -2
- package/dist/esm/database/alter.js +15 -15
- package/dist/esm/database/column.d.ts +3 -2
- package/dist/esm/database/column.js +9 -7
- package/dist/esm/database/contract.d.ts +3 -2
- package/dist/esm/database/index.d.ts +3 -2
- package/dist/esm/database/index.js +15 -2
- package/dist/esm/database/table.d.ts +3 -2
- package/dist/esm/database/table.js +12 -4
- package/dist/esm/database/types.d.ts +2 -1
- package/dist/esm/database/wrapper.d.ts +17 -21
- package/dist/esm/database/wrapper.js +43 -53
- package/dist/esm/{index-DFrpzXEn.d.ts → index-BXOAxB_h.d.ts} +4 -2
- package/dist/esm/{index-FMT0YEO7.d.ts → index-BdpoD4zk.d.ts} +80 -46
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/migration/index.d.ts +3 -2
- package/dist/esm/migration/runner.js +1 -1
- package/dist/esm/migration/type.d.ts +3 -2
- package/dist/esm/query/builder.d.ts +2 -1
- package/dist/esm/query/condition.d.ts +2 -1
- package/dist/esm/query/condition.js +5 -2
- package/dist/esm/query/contract.d.ts +3 -2
- package/dist/esm/query/helper.d.ts +2 -1
- package/dist/esm/query/index.d.ts +2 -1
- package/dist/esm/query/index.js +16 -7
- package/dist/esm/query/join.d.ts +2 -1
- package/dist/esm/query/sql.d.ts +5 -4
- package/dist/esm/query/sql.js +36 -8
- package/dist/esm/query/types.d.ts +2 -1
- package/dist/esm/query/utilities.d.ts +4 -1
- package/dist/esm/query/utilities.js +15 -5
- package/dist/esm/table/constants.d.ts +1 -0
- package/dist/esm/table/constants.js +1 -0
- package/dist/esm/table/index.d.ts +2 -1
- package/dist/esm/table/index.js +29 -9
- package/dist/esm/table/types.d.ts +2 -1
- package/dist/esm/table/utilities.d.ts +2 -1
- package/package.json +1 -1
|
@@ -24,76 +24,131 @@ var AcceptedColumnTypes = {
|
|
|
24
24
|
var ColumnTypeMapping = {
|
|
25
25
|
[AcceptedColumnTypes.INTEGER]: {
|
|
26
26
|
[Dialect.SQLITE]: "INTEGER",
|
|
27
|
-
[Dialect.POSTGRES]: "INTEGER"
|
|
27
|
+
[Dialect.POSTGRES]: "INTEGER",
|
|
28
|
+
[Dialect.MYSQL]: "INT"
|
|
28
29
|
},
|
|
29
30
|
[AcceptedColumnTypes.STRING]: {
|
|
30
31
|
[Dialect.SQLITE]: "TEXT",
|
|
31
|
-
[Dialect.POSTGRES]: "VARCHAR"
|
|
32
|
+
[Dialect.POSTGRES]: "VARCHAR",
|
|
33
|
+
[Dialect.MYSQL]: "VARCHAR"
|
|
32
34
|
},
|
|
33
35
|
[AcceptedColumnTypes.BOOLEAN]: {
|
|
34
36
|
[Dialect.SQLITE]: "INTEGER",
|
|
35
|
-
[Dialect.POSTGRES]: "BOOLEAN"
|
|
37
|
+
[Dialect.POSTGRES]: "BOOLEAN",
|
|
38
|
+
[Dialect.MYSQL]: "TINYINT"
|
|
36
39
|
},
|
|
37
40
|
[AcceptedColumnTypes.DATE]: {
|
|
38
41
|
[Dialect.SQLITE]: "TEXT",
|
|
39
|
-
[Dialect.POSTGRES]: "DATE"
|
|
42
|
+
[Dialect.POSTGRES]: "DATE",
|
|
43
|
+
[Dialect.MYSQL]: "DATE"
|
|
40
44
|
},
|
|
41
45
|
[AcceptedColumnTypes.FLOAT]: {
|
|
42
46
|
[Dialect.SQLITE]: "REAL",
|
|
43
|
-
[Dialect.POSTGRES]: "FLOAT"
|
|
47
|
+
[Dialect.POSTGRES]: "FLOAT",
|
|
48
|
+
[Dialect.MYSQL]: "FLOAT PRECISION"
|
|
44
49
|
},
|
|
45
50
|
[AcceptedColumnTypes.DECIMAL]: {
|
|
46
|
-
[Dialect.SQLITE]: "
|
|
47
|
-
[Dialect.POSTGRES]: "DECIMAL"
|
|
51
|
+
[Dialect.SQLITE]: "NUMERIC",
|
|
52
|
+
[Dialect.POSTGRES]: "DECIMAL",
|
|
53
|
+
[Dialect.MYSQL]: "DECIMAL"
|
|
48
54
|
},
|
|
49
55
|
[AcceptedColumnTypes.BIGINT]: {
|
|
50
|
-
[Dialect.SQLITE]: "
|
|
51
|
-
[Dialect.POSTGRES]: "BIGINT"
|
|
56
|
+
[Dialect.SQLITE]: "INTEGER",
|
|
57
|
+
[Dialect.POSTGRES]: "BIGINT",
|
|
58
|
+
[Dialect.MYSQL]: "BIGINT"
|
|
52
59
|
},
|
|
53
60
|
[AcceptedColumnTypes.TEXT]: {
|
|
54
61
|
[Dialect.SQLITE]: "TEXT",
|
|
55
|
-
[Dialect.POSTGRES]: "TEXT"
|
|
62
|
+
[Dialect.POSTGRES]: "TEXT",
|
|
63
|
+
[Dialect.MYSQL]: "TEXT"
|
|
56
64
|
},
|
|
57
65
|
[AcceptedColumnTypes.BLOB]: {
|
|
58
66
|
[Dialect.SQLITE]: "BLOB",
|
|
59
|
-
[Dialect.POSTGRES]: "BYTEA"
|
|
67
|
+
[Dialect.POSTGRES]: "BYTEA",
|
|
68
|
+
[Dialect.MYSQL]: "BLOB"
|
|
60
69
|
},
|
|
61
70
|
[AcceptedColumnTypes.JSON]: {
|
|
62
71
|
[Dialect.SQLITE]: "TEXT",
|
|
63
|
-
[Dialect.POSTGRES]: "JSONB"
|
|
72
|
+
[Dialect.POSTGRES]: "JSONB",
|
|
73
|
+
[Dialect.MYSQL]: "JSON"
|
|
64
74
|
},
|
|
65
75
|
[AcceptedColumnTypes.VARCHAR]: {
|
|
66
|
-
[Dialect.SQLITE]: "
|
|
67
|
-
[Dialect.POSTGRES]: "VARCHAR"
|
|
76
|
+
[Dialect.SQLITE]: "VARCHAR",
|
|
77
|
+
[Dialect.POSTGRES]: "VARCHAR",
|
|
78
|
+
[Dialect.MYSQL]: "VARCHAR"
|
|
68
79
|
},
|
|
69
80
|
[AcceptedColumnTypes.TIME]: {
|
|
70
81
|
[Dialect.SQLITE]: "TEXT",
|
|
71
|
-
[Dialect.POSTGRES]: "TIME"
|
|
82
|
+
[Dialect.POSTGRES]: "TIME",
|
|
83
|
+
[Dialect.MYSQL]: "TIME"
|
|
72
84
|
},
|
|
73
85
|
[AcceptedColumnTypes.TIMESTAMP]: {
|
|
74
86
|
[Dialect.SQLITE]: "TEXT",
|
|
75
|
-
[Dialect.POSTGRES]: "TIMESTAMP"
|
|
87
|
+
[Dialect.POSTGRES]: "TIMESTAMP",
|
|
88
|
+
[Dialect.MYSQL]: "DATETIME"
|
|
76
89
|
},
|
|
77
90
|
[AcceptedColumnTypes.DOUBLE]: {
|
|
78
91
|
[Dialect.SQLITE]: "REAL",
|
|
79
|
-
[Dialect.POSTGRES]: "DOUBLE PRECISION"
|
|
92
|
+
[Dialect.POSTGRES]: "DOUBLE PRECISION",
|
|
93
|
+
[Dialect.MYSQL]: "DOUBLE PRECISION"
|
|
80
94
|
},
|
|
81
95
|
[AcceptedColumnTypes.DATETIME]: {
|
|
82
96
|
[Dialect.SQLITE]: "TEXT",
|
|
83
|
-
[Dialect.POSTGRES]: "TIMESTAMP"
|
|
97
|
+
[Dialect.POSTGRES]: "TIMESTAMP",
|
|
98
|
+
[Dialect.MYSQL]: "DATETIME"
|
|
84
99
|
},
|
|
85
100
|
[AcceptedColumnTypes.DATEONLY]: {
|
|
86
101
|
[Dialect.SQLITE]: "TEXT",
|
|
87
|
-
[Dialect.POSTGRES]: "DATE"
|
|
102
|
+
[Dialect.POSTGRES]: "DATE",
|
|
103
|
+
[Dialect.MYSQL]: "DATE"
|
|
88
104
|
},
|
|
89
105
|
[AcceptedColumnTypes.ENUM]: {
|
|
90
106
|
[Dialect.SQLITE]: "TEXT",
|
|
91
|
-
[Dialect.POSTGRES]: "TEXT"
|
|
107
|
+
[Dialect.POSTGRES]: "TEXT",
|
|
108
|
+
[Dialect.MYSQL]: "TEXT"
|
|
92
109
|
},
|
|
93
110
|
[AcceptedColumnTypes.SERIAL]: {
|
|
94
|
-
[Dialect.SQLITE]: "INTEGER
|
|
95
|
-
[Dialect.POSTGRES]: "SERIAL"
|
|
111
|
+
[Dialect.SQLITE]: "INTEGER",
|
|
112
|
+
[Dialect.POSTGRES]: "SERIAL",
|
|
113
|
+
[Dialect.MYSQL]: "INT"
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
var ColumnProperties = {
|
|
117
|
+
NOT_NULL: "NOT_NULL",
|
|
118
|
+
UNIQUE: "UNIQUE",
|
|
119
|
+
DEFAULT: "DEFAULT",
|
|
120
|
+
AUTO_INCREMENT: "AUTO_INCREMENT",
|
|
121
|
+
PRIMARY_KEY: "PRIMARY_KEY"
|
|
122
|
+
};
|
|
123
|
+
var ColumnPropertyMapping = {
|
|
124
|
+
[ColumnProperties.NOT_NULL]: {
|
|
125
|
+
[Dialect.SQLITE]: "NOT NULL",
|
|
126
|
+
[Dialect.POSTGRES]: "NOT NULL",
|
|
127
|
+
[Dialect.MYSQL]: "NOT NULL"
|
|
128
|
+
},
|
|
129
|
+
[ColumnProperties.UNIQUE]: {
|
|
130
|
+
[Dialect.SQLITE]: "UNIQUE",
|
|
131
|
+
[Dialect.POSTGRES]: "UNIQUE",
|
|
132
|
+
[Dialect.MYSQL]: "UNIQUE"
|
|
133
|
+
},
|
|
134
|
+
[ColumnProperties.DEFAULT]: {
|
|
135
|
+
[Dialect.SQLITE]: "DEFAULT",
|
|
136
|
+
[Dialect.POSTGRES]: "DEFAULT",
|
|
137
|
+
[Dialect.MYSQL]: "DEFAULT"
|
|
138
|
+
},
|
|
139
|
+
[ColumnProperties.AUTO_INCREMENT]: {
|
|
140
|
+
// sqlite does not support AUTOINCREMENT
|
|
141
|
+
[Dialect.SQLITE]: "AUTOINCREMENT",
|
|
142
|
+
// postgres does not support AUTOINCREMENT
|
|
143
|
+
[Dialect.POSTGRES]: "AUTOINCREMENT",
|
|
144
|
+
// Exists only for mysql since mysql supports AUTOINCREMENT
|
|
145
|
+
[Dialect.MYSQL]: "AUTO_INCREMENT"
|
|
146
|
+
},
|
|
147
|
+
[ColumnProperties.PRIMARY_KEY]: {
|
|
148
|
+
[Dialect.SQLITE]: "PRIMARY KEY",
|
|
149
|
+
[Dialect.POSTGRES]: "PRIMARY KEY",
|
|
150
|
+
[Dialect.MYSQL]: "PRIMARY KEY"
|
|
96
151
|
}
|
|
97
152
|
};
|
|
98
153
|
|
|
99
|
-
export { AcceptedColumnTypes, ColumnTypeMapping };
|
|
154
|
+
export { AcceptedColumnTypes, ColumnProperties, ColumnPropertyMapping, ColumnTypeMapping };
|
|
@@ -31,6 +31,7 @@ declare class Column<Type extends AcceptedColumnTypes = AcceptedColumnTypes, Val
|
|
|
31
31
|
dialect<DbDialect extends Dialect>(dialect: DbDialect): Column<Type, Values, Options, ColumnValue, Value, Definition & {
|
|
32
32
|
dialect: DbDialect;
|
|
33
33
|
}>;
|
|
34
|
+
clone(): Column<Type, Values, Options, ColumnValue, Value, {}>;
|
|
34
35
|
toQuery(): {
|
|
35
36
|
query: string;
|
|
36
37
|
params: never[];
|
package/dist/esm/column/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Dialect } from '../table/constants.js';
|
|
2
|
+
import { deepClone } from '../utilities.js';
|
|
2
3
|
import { ColumnTypeMapping, AcceptedColumnTypes } from './constants.js';
|
|
4
|
+
import { columnProperty } from './utils.js';
|
|
3
5
|
|
|
4
6
|
// src/column/index.ts
|
|
5
7
|
var Column = class _Column {
|
|
@@ -58,40 +60,58 @@ var Column = class _Column {
|
|
|
58
60
|
this.definition.dialect = dialect;
|
|
59
61
|
return this;
|
|
60
62
|
}
|
|
63
|
+
clone() {
|
|
64
|
+
const column = new _Column({
|
|
65
|
+
type: this.type,
|
|
66
|
+
...this.length && { length: this.length },
|
|
67
|
+
...this.enums.length && { values: this.enums }
|
|
68
|
+
});
|
|
69
|
+
Object.assign(column.definition, deepClone(this.definition));
|
|
70
|
+
return column;
|
|
71
|
+
}
|
|
61
72
|
toQuery() {
|
|
62
73
|
if (!this.definition.dialect) {
|
|
63
74
|
throw new Error("No DB Dialect defined");
|
|
64
75
|
}
|
|
65
|
-
const
|
|
66
|
-
|
|
76
|
+
const type = ColumnTypeMapping[this.type][this.definition.dialect];
|
|
77
|
+
const properties = columnProperty(this.definition.dialect);
|
|
78
|
+
let sql = type + (this.length ? `(${this.length})` : "");
|
|
67
79
|
if (this.definition.primaryKey) {
|
|
68
|
-
sql +=
|
|
80
|
+
sql += ` ${properties.PRIMARY_KEY}`;
|
|
69
81
|
}
|
|
70
82
|
if (this.definition.autoIncrement || this.type === AcceptedColumnTypes.SERIAL) {
|
|
71
83
|
const isPrimaryKey = !!this.definition.primaryKey;
|
|
84
|
+
const sqls = [];
|
|
72
85
|
if (this.definition.dialect === Dialect.POSTGRES) {
|
|
73
|
-
|
|
86
|
+
sqls.push(type);
|
|
87
|
+
if (isPrimaryKey) {
|
|
88
|
+
sqls.push(properties.PRIMARY_KEY);
|
|
89
|
+
}
|
|
90
|
+
sql = sqls.join(" ");
|
|
74
91
|
} else {
|
|
75
92
|
if (this.type !== AcceptedColumnTypes.SERIAL) {
|
|
76
|
-
sql +=
|
|
93
|
+
sql += ` ${properties.AUTO_INCREMENT}`;
|
|
77
94
|
} else {
|
|
78
|
-
|
|
79
|
-
if (
|
|
95
|
+
sqls.push(type);
|
|
96
|
+
if (isPrimaryKey) {
|
|
97
|
+
sqls.push(properties.PRIMARY_KEY);
|
|
98
|
+
}
|
|
99
|
+
sqls.push(properties.AUTO_INCREMENT);
|
|
80
100
|
sql = sqls.join(" ");
|
|
81
101
|
}
|
|
82
102
|
}
|
|
83
103
|
}
|
|
84
104
|
if (this.definition.notNull) {
|
|
85
|
-
sql +=
|
|
105
|
+
sql += ` ${properties.NOT_NULL}`;
|
|
86
106
|
}
|
|
87
107
|
if (this.definition.unique) {
|
|
88
|
-
sql +=
|
|
108
|
+
sql += ` ${properties.UNIQUE}`;
|
|
89
109
|
}
|
|
90
110
|
if (this.definition.default !== void 0) {
|
|
91
111
|
const value = this.definition.default;
|
|
92
112
|
const isString = typeof this.definition.default === "string";
|
|
93
113
|
const finalValue = isString ? `'${value}'` : value;
|
|
94
|
-
sql += ` DEFAULT ${finalValue}`;
|
|
114
|
+
sql += ` ${properties.DEFAULT} ${finalValue}`;
|
|
95
115
|
}
|
|
96
116
|
return { query: sql, params: [] };
|
|
97
117
|
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Dialect } from '../table/constants.js';
|
|
2
|
+
import { ColumnProperties } from './constants.js';
|
|
3
|
+
|
|
4
|
+
declare function getColumnProperty<DbDialect extends Dialect>(dialect: DbDialect, property: ColumnProperties): ({
|
|
5
|
+
sqlite: string;
|
|
6
|
+
postgres: string;
|
|
7
|
+
mysql: string;
|
|
8
|
+
} | {
|
|
9
|
+
sqlite: string;
|
|
10
|
+
postgres: string;
|
|
11
|
+
mysql: string;
|
|
12
|
+
} | {
|
|
13
|
+
sqlite: string;
|
|
14
|
+
postgres: string;
|
|
15
|
+
mysql: string;
|
|
16
|
+
} | {
|
|
17
|
+
sqlite: string;
|
|
18
|
+
postgres: string;
|
|
19
|
+
mysql: string;
|
|
20
|
+
} | {
|
|
21
|
+
sqlite: string;
|
|
22
|
+
postgres: string;
|
|
23
|
+
mysql: string;
|
|
24
|
+
})[DbDialect];
|
|
25
|
+
declare function columnProperty<DbDialect extends Dialect>(dialect: DbDialect): {
|
|
26
|
+
NOT_NULL: ({
|
|
27
|
+
sqlite: string;
|
|
28
|
+
postgres: string;
|
|
29
|
+
mysql: string;
|
|
30
|
+
} | {
|
|
31
|
+
sqlite: string;
|
|
32
|
+
postgres: string;
|
|
33
|
+
mysql: string;
|
|
34
|
+
} | {
|
|
35
|
+
sqlite: string;
|
|
36
|
+
postgres: string;
|
|
37
|
+
mysql: string;
|
|
38
|
+
} | {
|
|
39
|
+
sqlite: string;
|
|
40
|
+
postgres: string;
|
|
41
|
+
mysql: string;
|
|
42
|
+
} | {
|
|
43
|
+
sqlite: string;
|
|
44
|
+
postgres: string;
|
|
45
|
+
mysql: string;
|
|
46
|
+
})[DbDialect];
|
|
47
|
+
UNIQUE: ({
|
|
48
|
+
sqlite: string;
|
|
49
|
+
postgres: string;
|
|
50
|
+
mysql: string;
|
|
51
|
+
} | {
|
|
52
|
+
sqlite: string;
|
|
53
|
+
postgres: string;
|
|
54
|
+
mysql: string;
|
|
55
|
+
} | {
|
|
56
|
+
sqlite: string;
|
|
57
|
+
postgres: string;
|
|
58
|
+
mysql: string;
|
|
59
|
+
} | {
|
|
60
|
+
sqlite: string;
|
|
61
|
+
postgres: string;
|
|
62
|
+
mysql: string;
|
|
63
|
+
} | {
|
|
64
|
+
sqlite: string;
|
|
65
|
+
postgres: string;
|
|
66
|
+
mysql: string;
|
|
67
|
+
})[DbDialect];
|
|
68
|
+
DEFAULT: ({
|
|
69
|
+
sqlite: string;
|
|
70
|
+
postgres: string;
|
|
71
|
+
mysql: string;
|
|
72
|
+
} | {
|
|
73
|
+
sqlite: string;
|
|
74
|
+
postgres: string;
|
|
75
|
+
mysql: string;
|
|
76
|
+
} | {
|
|
77
|
+
sqlite: string;
|
|
78
|
+
postgres: string;
|
|
79
|
+
mysql: string;
|
|
80
|
+
} | {
|
|
81
|
+
sqlite: string;
|
|
82
|
+
postgres: string;
|
|
83
|
+
mysql: string;
|
|
84
|
+
} | {
|
|
85
|
+
sqlite: string;
|
|
86
|
+
postgres: string;
|
|
87
|
+
mysql: string;
|
|
88
|
+
})[DbDialect];
|
|
89
|
+
AUTO_INCREMENT: ({
|
|
90
|
+
sqlite: string;
|
|
91
|
+
postgres: string;
|
|
92
|
+
mysql: string;
|
|
93
|
+
} | {
|
|
94
|
+
sqlite: string;
|
|
95
|
+
postgres: string;
|
|
96
|
+
mysql: string;
|
|
97
|
+
} | {
|
|
98
|
+
sqlite: string;
|
|
99
|
+
postgres: string;
|
|
100
|
+
mysql: string;
|
|
101
|
+
} | {
|
|
102
|
+
sqlite: string;
|
|
103
|
+
postgres: string;
|
|
104
|
+
mysql: string;
|
|
105
|
+
} | {
|
|
106
|
+
sqlite: string;
|
|
107
|
+
postgres: string;
|
|
108
|
+
mysql: string;
|
|
109
|
+
})[DbDialect];
|
|
110
|
+
PRIMARY_KEY: ({
|
|
111
|
+
sqlite: string;
|
|
112
|
+
postgres: string;
|
|
113
|
+
mysql: string;
|
|
114
|
+
} | {
|
|
115
|
+
sqlite: string;
|
|
116
|
+
postgres: string;
|
|
117
|
+
mysql: string;
|
|
118
|
+
} | {
|
|
119
|
+
sqlite: string;
|
|
120
|
+
postgres: string;
|
|
121
|
+
mysql: string;
|
|
122
|
+
} | {
|
|
123
|
+
sqlite: string;
|
|
124
|
+
postgres: string;
|
|
125
|
+
mysql: string;
|
|
126
|
+
} | {
|
|
127
|
+
sqlite: string;
|
|
128
|
+
postgres: string;
|
|
129
|
+
mysql: string;
|
|
130
|
+
})[DbDialect];
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export { columnProperty, getColumnProperty };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ColumnPropertyMapping, ColumnProperties } from './constants.js';
|
|
2
|
+
|
|
3
|
+
// src/column/utils.ts
|
|
4
|
+
function getColumnProperty(dialect, property) {
|
|
5
|
+
return ColumnPropertyMapping[property][dialect];
|
|
6
|
+
}
|
|
7
|
+
function columnProperty(dialect) {
|
|
8
|
+
return {
|
|
9
|
+
[ColumnProperties.NOT_NULL]: getColumnProperty(
|
|
10
|
+
dialect,
|
|
11
|
+
ColumnProperties.NOT_NULL
|
|
12
|
+
),
|
|
13
|
+
[ColumnProperties.UNIQUE]: getColumnProperty(
|
|
14
|
+
dialect,
|
|
15
|
+
ColumnProperties.UNIQUE
|
|
16
|
+
),
|
|
17
|
+
[ColumnProperties.DEFAULT]: getColumnProperty(
|
|
18
|
+
dialect,
|
|
19
|
+
ColumnProperties.DEFAULT
|
|
20
|
+
),
|
|
21
|
+
[ColumnProperties.AUTO_INCREMENT]: getColumnProperty(
|
|
22
|
+
dialect,
|
|
23
|
+
ColumnProperties.AUTO_INCREMENT
|
|
24
|
+
),
|
|
25
|
+
[ColumnProperties.PRIMARY_KEY]: getColumnProperty(
|
|
26
|
+
dialect,
|
|
27
|
+
ColumnProperties.PRIMARY_KEY
|
|
28
|
+
)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { columnProperty, getColumnProperty };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { D as Database } from '../index-
|
|
1
|
+
import { D as Database } from '../index-BXOAxB_h.js';
|
|
2
2
|
import { Column } from '../column/index.js';
|
|
3
3
|
import { AcceptedColumnTypes } from '../column/constants.js';
|
|
4
|
-
import { T as Table, D as DatabaseDefinition } from '../index-
|
|
4
|
+
import { T as Table, D as DatabaseDefinition } from '../index-BdpoD4zk.js';
|
|
5
5
|
import { Dialect } from '../table/constants.js';
|
|
6
|
+
import 'bun';
|
|
6
7
|
import '../query/constants.js';
|
|
7
8
|
import '../column/types.js';
|
|
8
9
|
import '../types.js';
|
|
@@ -5,9 +5,9 @@ async function alterColumnType(tableName, columnName, newType) {
|
|
|
5
5
|
if (this.dialect === Dialect.SQLITE) {
|
|
6
6
|
throw new Error("SQLite does not support ALTER COLUMN TYPE directly.");
|
|
7
7
|
}
|
|
8
|
-
await this.client.exec(
|
|
9
|
-
`ALTER TABLE ${tableName} ALTER COLUMN ${columnName} TYPE ${newType}`
|
|
10
|
-
);
|
|
8
|
+
await this.client.exec({
|
|
9
|
+
sql: `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} TYPE ${newType}`
|
|
10
|
+
});
|
|
11
11
|
if (!this.tables[tableName]) return this;
|
|
12
12
|
this.tables[tableName].columns[columnName].type = newType;
|
|
13
13
|
return this;
|
|
@@ -16,9 +16,9 @@ async function setColumnDefault(tableName, columnName, value) {
|
|
|
16
16
|
if (this.dialect === Dialect.SQLITE) {
|
|
17
17
|
throw new Error("SQLite does not support ALTER COLUMN DEFAULT directly.");
|
|
18
18
|
}
|
|
19
|
-
await this.client.exec(
|
|
20
|
-
`ALTER TABLE ${tableName} ALTER COLUMN ${columnName} SET DEFAULT ${value}`
|
|
21
|
-
);
|
|
19
|
+
await this.client.exec({
|
|
20
|
+
sql: `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} SET DEFAULT ${value}`
|
|
21
|
+
});
|
|
22
22
|
if (!this.tables[tableName]) return this;
|
|
23
23
|
if (
|
|
24
24
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -33,9 +33,9 @@ async function dropColumnDefault(tableName, columnName) {
|
|
|
33
33
|
if (this.dialect === Dialect.SQLITE) {
|
|
34
34
|
throw new Error("SQLite does not support DROP DEFAULT directly.");
|
|
35
35
|
}
|
|
36
|
-
await this.client.exec(
|
|
37
|
-
`ALTER TABLE ${tableName} ALTER COLUMN ${columnName} DROP DEFAULT`
|
|
38
|
-
);
|
|
36
|
+
await this.client.exec({
|
|
37
|
+
sql: `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} DROP DEFAULT`
|
|
38
|
+
});
|
|
39
39
|
if (!this.tables[tableName]) return this;
|
|
40
40
|
if (
|
|
41
41
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -52,9 +52,9 @@ async function setColumnNotNull(tableName, columnName) {
|
|
|
52
52
|
"SQLite does not support SET NOT NULL (requires table rebuild)"
|
|
53
53
|
);
|
|
54
54
|
}
|
|
55
|
-
await this.client.exec(
|
|
56
|
-
`ALTER TABLE ${tableName} ALTER COLUMN ${columnName} SET NOT NULL`
|
|
57
|
-
);
|
|
55
|
+
await this.client.exec({
|
|
56
|
+
sql: `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} SET NOT NULL`
|
|
57
|
+
});
|
|
58
58
|
if (!this.tables[tableName]) return this;
|
|
59
59
|
if (
|
|
60
60
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -71,9 +71,9 @@ async function dropColumnNotNull(tableName, columnName) {
|
|
|
71
71
|
"SQLite does not support DROP NOT NULL (requires table rebuild)"
|
|
72
72
|
);
|
|
73
73
|
}
|
|
74
|
-
await this.client.exec(
|
|
75
|
-
`ALTER TABLE ${tableName} ALTER COLUMN ${columnName} DROP NOT NULL`
|
|
76
|
-
);
|
|
74
|
+
await this.client.exec({
|
|
75
|
+
sql: `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} DROP NOT NULL`
|
|
76
|
+
});
|
|
77
77
|
if (!this.tables[tableName]) return this;
|
|
78
78
|
if (
|
|
79
79
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { D as Database } from '../index-
|
|
1
|
+
import { D as Database } from '../index-BXOAxB_h.js';
|
|
2
2
|
import { Column } from '../column/index.js';
|
|
3
|
-
import { T as Table, D as DatabaseDefinition } from '../index-
|
|
3
|
+
import { T as Table, D as DatabaseDefinition } from '../index-BdpoD4zk.js';
|
|
4
4
|
import { Dialect } from '../table/constants.js';
|
|
5
|
+
import 'bun';
|
|
5
6
|
import '../query/constants.js';
|
|
6
7
|
import '../column/constants.js';
|
|
7
8
|
import '../column/types.js';
|
|
@@ -2,9 +2,9 @@ import { Dialect } from '../table/constants.js';
|
|
|
2
2
|
|
|
3
3
|
// src/database/column.ts
|
|
4
4
|
async function addColumn(tableName, columnName, column) {
|
|
5
|
-
await this.client.exec(
|
|
6
|
-
`ALTER TABLE ${tableName} ADD COLUMN ${columnName} ${column.toString()};`
|
|
7
|
-
);
|
|
5
|
+
await this.client.exec({
|
|
6
|
+
sql: `ALTER TABLE ${tableName} ADD COLUMN ${columnName} ${column.toString()};`
|
|
7
|
+
});
|
|
8
8
|
if (!this.tables[tableName]) return this;
|
|
9
9
|
this.tables[tableName].columns[columnName] = column;
|
|
10
10
|
return this;
|
|
@@ -13,9 +13,9 @@ async function renameColumn(tableName, oldName, newName) {
|
|
|
13
13
|
if (this.dialect === Dialect.SQLITE) {
|
|
14
14
|
throw new Error("SQLite does not support RENAME COLUMN natively.");
|
|
15
15
|
}
|
|
16
|
-
await this.client.exec(
|
|
17
|
-
`ALTER TABLE ${tableName} RENAME COLUMN ${oldName} TO ${newName};`
|
|
18
|
-
);
|
|
16
|
+
await this.client.exec({
|
|
17
|
+
sql: `ALTER TABLE ${tableName} RENAME COLUMN ${oldName} TO ${newName};`
|
|
18
|
+
});
|
|
19
19
|
if (!this.tables[tableName]) return this;
|
|
20
20
|
this.tables[tableName].columns[newName] = this.tables[tableName].columns[oldName];
|
|
21
21
|
delete this.tables[tableName].columns[oldName];
|
|
@@ -25,7 +25,9 @@ async function dropColumn(tableName, columnName) {
|
|
|
25
25
|
if (this.dialect === Dialect.SQLITE) {
|
|
26
26
|
throw new Error("SQLite does not support DROP COLUMN natively.");
|
|
27
27
|
}
|
|
28
|
-
await this.client.exec(
|
|
28
|
+
await this.client.exec({
|
|
29
|
+
sql: `ALTER TABLE ${tableName} DROP COLUMN ${columnName};`
|
|
30
|
+
});
|
|
29
31
|
if (!this.tables[tableName]) return this;
|
|
30
32
|
delete this.tables[tableName].columns[columnName];
|
|
31
33
|
return this;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export { C as ColumnAlterationContract, T as TableAlterationContract } from '../index-
|
|
1
|
+
export { C as ColumnAlterationContract, T as TableAlterationContract } from '../index-BXOAxB_h.js';
|
|
2
2
|
import '../column/index.js';
|
|
3
3
|
import '../column/constants.js';
|
|
4
|
-
import '../index-
|
|
4
|
+
import '../index-BdpoD4zk.js';
|
|
5
5
|
import '../table/constants.js';
|
|
6
|
+
import 'bun';
|
|
6
7
|
import '../query/constants.js';
|
|
7
8
|
import '../column/types.js';
|
|
8
9
|
import '../types.js';
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import 'bun';
|
|
1
2
|
import '../column/index.js';
|
|
2
|
-
import '../index-
|
|
3
|
+
import '../index-BdpoD4zk.js';
|
|
3
4
|
import '../query/constants.js';
|
|
4
5
|
import '../table/constants.js';
|
|
5
|
-
export { D as Database } from '../index-
|
|
6
|
+
export { D as Database } from '../index-BXOAxB_h.js';
|
|
6
7
|
import '../column/constants.js';
|
|
7
8
|
import '../column/types.js';
|
|
8
9
|
import '../types.js';
|
|
@@ -3,7 +3,7 @@ import { Dialect } from '../table/constants.js';
|
|
|
3
3
|
import { alterColumnType, setColumnDefault, dropColumnDefault, dropColumnNotNull } from './alter.js';
|
|
4
4
|
import { addColumn, renameColumn, dropColumn } from './column.js';
|
|
5
5
|
import { createTable, renameTable, dropTable } from './table.js';
|
|
6
|
-
import { DatabasePsql, DatabaseSqlite } from './wrapper.js';
|
|
6
|
+
import { DatabaseMysql, DatabasePsql, DatabaseSqlite } from './wrapper.js';
|
|
7
7
|
|
|
8
8
|
// src/database/index.ts
|
|
9
9
|
var Database = class _Database {
|
|
@@ -31,10 +31,11 @@ var Database = class _Database {
|
|
|
31
31
|
dialect: options.dialect,
|
|
32
32
|
config: options.config
|
|
33
33
|
};
|
|
34
|
-
this.client =
|
|
34
|
+
this.client = this.createClient(options);
|
|
35
35
|
if (options.tables) {
|
|
36
36
|
for (const tableName in options.tables) {
|
|
37
37
|
options.tables[tableName].client = this.client;
|
|
38
|
+
options.tables[tableName].setDialect(this.dialect);
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
this.createTable = createTable.bind(this);
|
|
@@ -59,6 +60,18 @@ var Database = class _Database {
|
|
|
59
60
|
this
|
|
60
61
|
);
|
|
61
62
|
}
|
|
63
|
+
createClient(options) {
|
|
64
|
+
switch (options.dialect) {
|
|
65
|
+
case Dialect.SQLITE:
|
|
66
|
+
return new DatabaseSqlite(options.config);
|
|
67
|
+
case Dialect.POSTGRES:
|
|
68
|
+
return new DatabasePsql(options.config);
|
|
69
|
+
case Dialect.MYSQL:
|
|
70
|
+
return new DatabaseMysql(options.config);
|
|
71
|
+
default:
|
|
72
|
+
throw new Error(`Dialect ${options.dialect} is not supported`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
62
75
|
table(tableName) {
|
|
63
76
|
if (!this.tables[tableName]) {
|
|
64
77
|
throw new Error(`Table ${tableName} does not exist`);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { D as Database } from '../index-
|
|
1
|
+
import { D as Database } from '../index-BXOAxB_h.js';
|
|
2
2
|
import { Column } from '../column/index.js';
|
|
3
|
-
import { T as Table, D as DatabaseDefinition, a as TimestampOptions, M as MergeTimestampParanoid } from '../index-
|
|
3
|
+
import { T as Table, D as DatabaseDefinition, a as TimestampOptions, M as MergeTimestampParanoid } from '../index-BdpoD4zk.js';
|
|
4
4
|
import { Dialect } from '../table/constants.js';
|
|
5
|
+
import 'bun';
|
|
5
6
|
import '../query/constants.js';
|
|
6
7
|
import '../column/constants.js';
|
|
7
8
|
import '../column/types.js';
|
|
@@ -16,21 +16,29 @@ async function createTable(tableName, columns, options) {
|
|
|
16
16
|
while (this.client.status === "connecting") {
|
|
17
17
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
18
18
|
}
|
|
19
|
-
await table.create(
|
|
19
|
+
await table.create({
|
|
20
|
+
db: this.client
|
|
21
|
+
});
|
|
20
22
|
return this;
|
|
21
23
|
}
|
|
22
24
|
async function renameTable(oldName, newName) {
|
|
23
|
-
await this.client.exec(
|
|
25
|
+
await this.client.exec({
|
|
26
|
+
sql: `ALTER TABLE ${oldName} RENAME TO ${newName};`
|
|
27
|
+
});
|
|
24
28
|
this.tables[newName] = this.tables[oldName];
|
|
25
29
|
delete this.tables[oldName];
|
|
26
30
|
return this;
|
|
27
31
|
}
|
|
28
32
|
async function dropTable(tableName) {
|
|
29
33
|
if (!this.tables[tableName]) {
|
|
30
|
-
await this.client.exec(
|
|
34
|
+
await this.client.exec({
|
|
35
|
+
sql: `DROP TABLE IF EXISTS ${tableName};`
|
|
36
|
+
});
|
|
31
37
|
return this;
|
|
32
38
|
}
|
|
33
|
-
await this.tables[tableName].drop(
|
|
39
|
+
await this.tables[tableName].drop({
|
|
40
|
+
db: this.client
|
|
41
|
+
});
|
|
34
42
|
delete this.tables[tableName];
|
|
35
43
|
return this;
|
|
36
44
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import 'bun';
|
|
1
2
|
import '../column/index.js';
|
|
2
|
-
export { D as DatabaseDefinition, b as DatabaseDialect,
|
|
3
|
+
export { D as DatabaseDefinition, b as DatabaseDialect, c as DatabaseExecOptions, i as DatabaseOptions, s as MysqlConfig, P as PostgresConfig, r as SqlConfig, S as SqlConfigMapping, d as SqliteConfig } from '../index-BdpoD4zk.js';
|
|
3
4
|
import '../table/constants.js';
|
|
4
5
|
import '../column/constants.js';
|
|
5
6
|
import '../column/types.js';
|