@hedystia/db 2.0.6 → 2.0.7
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/cache/index.mjs +12 -0
- package/dist/cache/index.mjs.map +1 -0
- package/dist/cache/manager.mjs +156 -153
- package/dist/cache/manager.mjs.map +1 -1
- package/dist/cache/memory-store.mjs +113 -111
- package/dist/cache/memory-store.mjs.map +1 -1
- package/dist/cli/commands/migrate.cjs +78 -0
- package/dist/cli/commands/migrate.cjs.map +1 -0
- package/dist/cli/commands/migrate.mjs +83 -0
- package/dist/cli/commands/migrate.mjs.map +1 -0
- package/dist/cli.cjs +36 -0
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +37 -0
- package/dist/cli.mjs.map +1 -1
- package/dist/core/database.cjs +72 -29
- package/dist/core/database.cjs.map +1 -1
- package/dist/core/database.d.cts +11 -0
- package/dist/core/database.d.mts +11 -0
- package/dist/core/database.mjs +88 -34
- package/dist/core/database.mjs.map +1 -1
- package/dist/core/repository.mjs +414 -410
- package/dist/core/repository.mjs.map +1 -1
- package/dist/drivers/driver.mjs +9 -7
- package/dist/drivers/driver.mjs.map +1 -1
- package/dist/drivers/file.mjs +315 -312
- package/dist/drivers/file.mjs.map +1 -1
- package/dist/drivers/index.mjs +15 -6
- package/dist/drivers/index.mjs.map +1 -1
- package/dist/drivers/mysql.mjs +261 -256
- package/dist/drivers/mysql.mjs.map +1 -1
- package/dist/drivers/sql-compiler.mjs +4 -1
- package/dist/drivers/sql-compiler.mjs.map +1 -1
- package/dist/drivers/sqlite.cjs +12 -1
- package/dist/drivers/sqlite.cjs.map +1 -1
- package/dist/drivers/sqlite.mjs +258 -242
- package/dist/drivers/sqlite.mjs.map +1 -1
- package/dist/errors.mjs +48 -64
- package/dist/errors.mjs.map +1 -1
- package/dist/index.mjs +21 -9
- package/dist/index.mjs.map +1 -1
- package/dist/schema/column.mjs +155 -157
- package/dist/schema/column.mjs.map +1 -1
- package/dist/schema/columns/index.mjs +103 -171
- package/dist/schema/columns/index.mjs.map +1 -1
- package/dist/schema/index.mjs +15 -0
- package/dist/schema/index.mjs.map +1 -0
- package/dist/schema/registry.mjs +122 -119
- package/dist/schema/registry.mjs.map +1 -1
- package/dist/schema/table.mjs +4 -1
- package/dist/schema/table.mjs.map +1 -1
- package/dist/sync/synchronizer.mjs +2 -1
- package/dist/sync/synchronizer.mjs.map +1 -1
- package/package.json +1 -1
package/dist/errors.mjs
CHANGED
|
@@ -1,68 +1,52 @@
|
|
|
1
|
+
import { __esmMin } from "./_virtual/_rolldown/runtime.mjs";
|
|
1
2
|
//#region src/errors.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Error thrown when migration execution fails
|
|
49
|
-
*/
|
|
50
|
-
var MigrationError = class extends DatabaseError {
|
|
51
|
-
constructor(message) {
|
|
52
|
-
super(message);
|
|
53
|
-
this.name = "MigrationError";
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* Error thrown when cache operation fails
|
|
58
|
-
*/
|
|
59
|
-
var CacheError = class extends DatabaseError {
|
|
60
|
-
constructor(message) {
|
|
61
|
-
super(message);
|
|
62
|
-
this.name = "CacheError";
|
|
63
|
-
}
|
|
64
|
-
};
|
|
3
|
+
var DatabaseError, SchemaError, DriverError, QueryError, SyncError, MigrationError, CacheError;
|
|
4
|
+
var init_errors = __esmMin((() => {
|
|
5
|
+
DatabaseError = class extends Error {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "DatabaseError";
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
SchemaError = class extends DatabaseError {
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = "SchemaError";
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
DriverError = class extends DatabaseError {
|
|
18
|
+
constructor(message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "DriverError";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
QueryError = class extends DatabaseError {
|
|
24
|
+
constructor(message) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.name = "QueryError";
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
SyncError = class extends DatabaseError {
|
|
30
|
+
constructor(message) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.name = "SyncError";
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
MigrationError = class extends DatabaseError {
|
|
36
|
+
constructor(message) {
|
|
37
|
+
super(message);
|
|
38
|
+
this.name = "MigrationError";
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
CacheError = class extends DatabaseError {
|
|
42
|
+
constructor(message) {
|
|
43
|
+
super(message);
|
|
44
|
+
this.name = "CacheError";
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}));
|
|
65
48
|
//#endregion
|
|
66
|
-
|
|
49
|
+
init_errors();
|
|
50
|
+
export { CacheError, DatabaseError, DriverError, MigrationError, QueryError, SchemaError, SyncError, init_errors };
|
|
67
51
|
|
|
68
52
|
//# sourceMappingURL=errors.mjs.map
|
package/dist/errors.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Base error for all database-related errors\n */\nexport class DatabaseError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"DatabaseError\";\n }\n}\n\n/**\n * Error thrown when schema definition is invalid\n */\nexport class SchemaError extends DatabaseError {\n constructor(message: string) {\n super(message);\n this.name = \"SchemaError\";\n }\n}\n\n/**\n * Error thrown when a database driver encounters an error\n */\nexport class DriverError extends DatabaseError {\n constructor(message: string) {\n super(message);\n this.name = \"DriverError\";\n }\n}\n\n/**\n * Error thrown when a query is invalid\n */\nexport class QueryError extends DatabaseError {\n constructor(message: string) {\n super(message);\n this.name = \"QueryError\";\n }\n}\n\n/**\n * Error thrown when schema synchronization fails\n */\nexport class SyncError extends DatabaseError {\n constructor(message: string) {\n super(message);\n this.name = \"SyncError\";\n }\n}\n\n/**\n * Error thrown when migration execution fails\n */\nexport class MigrationError extends DatabaseError {\n constructor(message: string) {\n super(message);\n this.name = \"MigrationError\";\n }\n}\n\n/**\n * Error thrown when cache operation fails\n */\nexport class CacheError extends DatabaseError {\n constructor(message: string) {\n super(message);\n this.name = \"CacheError\";\n }\n}\n"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"errors.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Base error for all database-related errors\n */\nexport class DatabaseError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"DatabaseError\";\n }\n}\n\n/**\n * Error thrown when schema definition is invalid\n */\nexport class SchemaError extends DatabaseError {\n constructor(message: string) {\n super(message);\n this.name = \"SchemaError\";\n }\n}\n\n/**\n * Error thrown when a database driver encounters an error\n */\nexport class DriverError extends DatabaseError {\n constructor(message: string) {\n super(message);\n this.name = \"DriverError\";\n }\n}\n\n/**\n * Error thrown when a query is invalid\n */\nexport class QueryError extends DatabaseError {\n constructor(message: string) {\n super(message);\n this.name = \"QueryError\";\n }\n}\n\n/**\n * Error thrown when schema synchronization fails\n */\nexport class SyncError extends DatabaseError {\n constructor(message: string) {\n super(message);\n this.name = \"SyncError\";\n }\n}\n\n/**\n * Error thrown when migration execution fails\n */\nexport class MigrationError extends DatabaseError {\n constructor(message: string) {\n super(message);\n this.name = \"MigrationError\";\n }\n}\n\n/**\n * Error thrown when cache operation fails\n */\nexport class CacheError extends DatabaseError {\n constructor(message: string) {\n super(message);\n this.name = \"CacheError\";\n }\n}\n"],"mappings":";;;;AAGa,iBAAb,cAAmC,MAAM;EACvC,YAAY,SAAiB;AAC3B,SAAM,QAAQ;AACd,QAAK,OAAO;;;AAOH,eAAb,cAAiC,cAAc;EAC7C,YAAY,SAAiB;AAC3B,SAAM,QAAQ;AACd,QAAK,OAAO;;;AAOH,eAAb,cAAiC,cAAc;EAC7C,YAAY,SAAiB;AAC3B,SAAM,QAAQ;AACd,QAAK,OAAO;;;AAOH,cAAb,cAAgC,cAAc;EAC5C,YAAY,SAAiB;AAC3B,SAAM,QAAQ;AACd,QAAK,OAAO;;;AAOH,aAAb,cAA+B,cAAc;EAC3C,YAAY,SAAiB;AAC3B,SAAM,QAAQ;AACd,QAAK,OAAO;;;AAOH,kBAAb,cAAoC,cAAc;EAChD,YAAY,SAAiB;AAC3B,SAAM,QAAQ;AACd,QAAK,OAAO;;;AAOH,cAAb,cAAgC,cAAc;EAC5C,YAAY,SAAiB;AAC3B,SAAM,QAAQ;AACd,QAAK,OAAO"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
import { CacheManager } from "./cache/manager.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
2
|
+
import { init_cache } from "./cache/index.mjs";
|
|
3
|
+
import { CacheError, DatabaseError, DriverError, MigrationError, QueryError, SchemaError, SyncError, init_errors } from "./errors.mjs";
|
|
4
|
+
import { compileColumnDef, compileCreateTable, compileDelete, compileInsert, compileSelect, compileUpdate, compileWhere, init_sql_compiler } from "./drivers/sql-compiler.mjs";
|
|
5
|
+
import { createDriver, init_drivers } from "./drivers/index.mjs";
|
|
6
|
+
import { ColumnBuilder, init_column } from "./schema/column.mjs";
|
|
7
|
+
import { NamedColumnStarter, array, bigint, blob, boolean, char, columns_exports, d, datetime, decimal, float, init_columns, integer, json, name, text, timestamp, varchar } from "./schema/columns/index.mjs";
|
|
8
|
+
import { SchemaRegistry, init_registry } from "./schema/registry.mjs";
|
|
9
|
+
import { init_table, table } from "./schema/table.mjs";
|
|
10
|
+
import { TableRepository, init_repository } from "./core/repository.mjs";
|
|
11
|
+
import { database, init_database } from "./core/database.mjs";
|
|
11
12
|
import { init_definition, migration } from "./migrations/definition.mjs";
|
|
12
13
|
import { generateMigrationTemplate, generateSchemaTemplate, init_templates } from "./migrations/templates.mjs";
|
|
13
14
|
import { Synchronizer } from "./sync/synchronizer.mjs";
|
|
14
15
|
//#region src/index.ts
|
|
16
|
+
init_cache();
|
|
17
|
+
init_database();
|
|
18
|
+
init_repository();
|
|
19
|
+
init_drivers();
|
|
20
|
+
init_sql_compiler();
|
|
15
21
|
init_definition();
|
|
16
22
|
init_templates();
|
|
23
|
+
init_column();
|
|
24
|
+
init_columns();
|
|
25
|
+
init_registry();
|
|
26
|
+
init_table();
|
|
27
|
+
init_errors();
|
|
28
|
+
init_columns();
|
|
17
29
|
var src_default = database;
|
|
18
30
|
//#endregion
|
|
19
31
|
export { CacheError, CacheManager, ColumnBuilder, DatabaseError, DriverError, MigrationError, NamedColumnStarter, QueryError, SchemaError, SchemaRegistry, SyncError, Synchronizer, TableRepository, array, bigint, blob, boolean, char, columns_exports as columns, compileColumnDef, compileCreateTable, compileDelete, compileInsert, compileSelect, compileUpdate, compileWhere, createDriver, d, database, datetime, decimal, src_default as default, float, generateMigrationTemplate, generateSchemaTemplate, integer, json, migration, name, table, text, timestamp, varchar };
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { CacheManager } from \"./cache\";\nimport { database } from \"./core/database\";\nimport { TableRepository } from \"./core/repository\";\nimport { createDriver } from \"./drivers\";\nimport {\n compileColumnDef,\n compileCreateTable,\n compileDelete,\n compileInsert,\n compileSelect,\n compileUpdate,\n compileWhere,\n} from \"./drivers/sql-compiler\";\nimport { migration } from \"./migrations/definition\";\nimport { generateMigrationTemplate, generateSchemaTemplate } from \"./migrations/templates\";\nimport { ColumnBuilder } from \"./schema/column\";\nimport * as columns from \"./schema/columns\";\nimport { SchemaRegistry } from \"./schema/registry\";\nimport { table } from \"./schema/table\";\nimport { Synchronizer } from \"./sync/synchronizer\";\n\nexport {\n CacheError,\n DatabaseError,\n DriverError,\n MigrationError,\n QueryError,\n SchemaError,\n SyncError,\n} from \"./errors\";\nexport * from \"./schema/columns\";\nexport type {\n CacheConfig,\n ColumnDataType,\n ColumnMetadata,\n ConnectionConfig,\n DatabaseConfig,\n DatabaseDriver,\n DatabaseType,\n DeferredRefMeta,\n DeleteOptions,\n FileConnectionConfig,\n InferInsert,\n InferRow,\n InferUpdate,\n MigrationContext,\n MigrationDefinition,\n MySQLConnectionConfig,\n QueryOptions,\n ReferenceAction,\n RelationQueryMap,\n RelationsFor,\n Repository,\n ResolveResult,\n SQLiteConnectionConfig,\n TableCacheConfig,\n TableDefinition,\n TableMetadata,\n UpdateOptions,\n WhereClause,\n WhereCondition,\n} from \"./types\";\nexport {\n CacheManager,\n ColumnBuilder,\n columns,\n compileColumnDef,\n compileCreateTable,\n compileDelete,\n compileInsert,\n compileSelect,\n compileUpdate,\n compileWhere,\n createDriver,\n database,\n generateMigrationTemplate,\n generateSchemaTemplate,\n migration,\n SchemaRegistry,\n Synchronizer,\n TableRepository,\n table,\n};\n\nexport default database;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { CacheManager } from \"./cache\";\nimport { database } from \"./core/database\";\nimport { TableRepository } from \"./core/repository\";\nimport { createDriver } from \"./drivers\";\nimport {\n compileColumnDef,\n compileCreateTable,\n compileDelete,\n compileInsert,\n compileSelect,\n compileUpdate,\n compileWhere,\n} from \"./drivers/sql-compiler\";\nimport { migration } from \"./migrations/definition\";\nimport { generateMigrationTemplate, generateSchemaTemplate } from \"./migrations/templates\";\nimport { ColumnBuilder } from \"./schema/column\";\nimport * as columns from \"./schema/columns\";\nimport { SchemaRegistry } from \"./schema/registry\";\nimport { table } from \"./schema/table\";\nimport { Synchronizer } from \"./sync/synchronizer\";\n\nexport {\n CacheError,\n DatabaseError,\n DriverError,\n MigrationError,\n QueryError,\n SchemaError,\n SyncError,\n} from \"./errors\";\nexport * from \"./schema/columns\";\nexport type {\n CacheConfig,\n ColumnDataType,\n ColumnMetadata,\n ConnectionConfig,\n DatabaseConfig,\n DatabaseDriver,\n DatabaseType,\n DeferredRefMeta,\n DeleteOptions,\n FileConnectionConfig,\n InferInsert,\n InferRow,\n InferUpdate,\n MigrationContext,\n MigrationDefinition,\n MySQLConnectionConfig,\n QueryOptions,\n ReferenceAction,\n RelationQueryMap,\n RelationsFor,\n Repository,\n ResolveResult,\n SQLiteConnectionConfig,\n TableCacheConfig,\n TableDefinition,\n TableMetadata,\n UpdateOptions,\n WhereClause,\n WhereCondition,\n} from \"./types\";\nexport {\n CacheManager,\n ColumnBuilder,\n columns,\n compileColumnDef,\n compileCreateTable,\n compileDelete,\n compileInsert,\n compileSelect,\n compileUpdate,\n compileWhere,\n createDriver,\n database,\n generateMigrationTemplate,\n generateSchemaTemplate,\n migration,\n SchemaRegistry,\n Synchronizer,\n TableRepository,\n table,\n};\n\nexport default database;\n"],"mappings":";;;;;;;;;;;;;;;YAAuC;eACI;iBACS;cACX;mBAST;iBACoB;gBACuC;aAC3C;cACJ;eACO;YACZ;aAWrB;;AAuDlB,IAAA,cAAe"}
|
package/dist/schema/column.mjs
CHANGED
|
@@ -1,161 +1,159 @@
|
|
|
1
|
+
import { __esmMin } from "../_virtual/_rolldown/runtime.mjs";
|
|
1
2
|
//#region src/schema/column.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
__getDeferredRef() {
|
|
155
|
-
return this._references ?? null;
|
|
156
|
-
}
|
|
157
|
-
};
|
|
3
|
+
var ColumnBuilder;
|
|
4
|
+
var init_column = __esmMin((() => {
|
|
5
|
+
ColumnBuilder = class {
|
|
6
|
+
_type;
|
|
7
|
+
_primaryKey = false;
|
|
8
|
+
_autoIncrement = false;
|
|
9
|
+
_notNull = false;
|
|
10
|
+
_unique = false;
|
|
11
|
+
_defaultValue = void 0;
|
|
12
|
+
_length;
|
|
13
|
+
_precision;
|
|
14
|
+
_scale;
|
|
15
|
+
_columnAlias;
|
|
16
|
+
_references;
|
|
17
|
+
constructor(type, length, precision, scale) {
|
|
18
|
+
this._type = type;
|
|
19
|
+
this._length = length;
|
|
20
|
+
this._precision = precision;
|
|
21
|
+
this._scale = scale;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Set a custom database column name different from the property key
|
|
25
|
+
* @param {string} alias - The column name to use in the database
|
|
26
|
+
* @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
|
|
27
|
+
* @example
|
|
28
|
+
* // In code: guildId, In database: guild_id
|
|
29
|
+
* guildId: varchar(255).name("guild_id")
|
|
30
|
+
*/
|
|
31
|
+
name(alias) {
|
|
32
|
+
this._columnAlias = alias;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Override the TypeScript type for this column with a custom type literal
|
|
37
|
+
* @template U - The custom type to use
|
|
38
|
+
* @returns {ColumnBuilder<U, TN, CN, Ref>} The column builder with the new type
|
|
39
|
+
* @example
|
|
40
|
+
* // Limits autocomplete to specific values
|
|
41
|
+
* locale: varchar(25).type<"en_US" | "es_ES">()
|
|
42
|
+
*/
|
|
43
|
+
type() {
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Mark this column as a primary key
|
|
48
|
+
* @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
|
|
49
|
+
*/
|
|
50
|
+
primaryKey() {
|
|
51
|
+
this._primaryKey = true;
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Mark this column as auto-incrementing
|
|
56
|
+
* @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
|
|
57
|
+
*/
|
|
58
|
+
autoIncrement() {
|
|
59
|
+
this._autoIncrement = true;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Mark this column as NOT NULL
|
|
64
|
+
* @returns {ColumnBuilder<NonNullable<T>, TN, CN, Ref>} The column builder for chaining
|
|
65
|
+
*/
|
|
66
|
+
notNull() {
|
|
67
|
+
this._notNull = true;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Mark this column as nullable
|
|
72
|
+
* @returns {ColumnBuilder<T | null, TN, CN, Ref>} The column builder for chaining
|
|
73
|
+
*/
|
|
74
|
+
nullable() {
|
|
75
|
+
this._notNull = false;
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Mark this column as nullable (alias for {@link nullable})
|
|
80
|
+
* @returns {ColumnBuilder<T | null, TN, CN, Ref>} The column builder for chaining
|
|
81
|
+
*/
|
|
82
|
+
null() {
|
|
83
|
+
return this.nullable();
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Set a default value for this column
|
|
87
|
+
* @param {T} value - The default value
|
|
88
|
+
* @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
|
|
89
|
+
*/
|
|
90
|
+
default(value) {
|
|
91
|
+
this._defaultValue = value;
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Mark this column as having a unique constraint
|
|
96
|
+
* @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
|
|
97
|
+
*/
|
|
98
|
+
unique() {
|
|
99
|
+
this._unique = true;
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Add a foreign key reference to another table's column
|
|
104
|
+
* @param {(() => ColumnBuilder<any>) | ColumnBuilder<any>} ref - A column reference or a function returning one
|
|
105
|
+
* @param {object} [options] - Reference options
|
|
106
|
+
* @param {ReferenceAction} [options.onDelete] - Action on delete
|
|
107
|
+
* @param {ReferenceAction} [options.onUpdate] - Action on update
|
|
108
|
+
* @param {string} [options.relationName] - Name for the relation
|
|
109
|
+
* @returns {ColumnBuilder<T>} The column builder for chaining
|
|
110
|
+
*/
|
|
111
|
+
references(ref, options) {
|
|
112
|
+
this._references = {
|
|
113
|
+
resolve: () => {
|
|
114
|
+
const col = typeof ref === "function" ? ref() : ref;
|
|
115
|
+
return {
|
|
116
|
+
table: col.__tableName ?? "",
|
|
117
|
+
column: col.__columnName ?? ""
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
onDelete: options?.onDelete,
|
|
121
|
+
onUpdate: options?.onUpdate,
|
|
122
|
+
relationName: options?.relationName
|
|
123
|
+
};
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Build the column metadata from the builder configuration
|
|
128
|
+
* @param {string} name - The column name
|
|
129
|
+
* @returns {ColumnMetadata} The built column metadata
|
|
130
|
+
*/
|
|
131
|
+
__build(name) {
|
|
132
|
+
return {
|
|
133
|
+
name: this._columnAlias ?? name,
|
|
134
|
+
type: this._type,
|
|
135
|
+
primaryKey: this._primaryKey,
|
|
136
|
+
autoIncrement: this._autoIncrement,
|
|
137
|
+
notNull: this._notNull || this._primaryKey,
|
|
138
|
+
unique: this._unique || this._primaryKey,
|
|
139
|
+
defaultValue: this._defaultValue,
|
|
140
|
+
length: this._length,
|
|
141
|
+
precision: this._precision,
|
|
142
|
+
scale: this._scale,
|
|
143
|
+
columnAlias: this._columnAlias
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Get deferred reference data if this column has a foreign key reference
|
|
148
|
+
* @returns {object | null} The deferred reference data or null
|
|
149
|
+
*/
|
|
150
|
+
__getDeferredRef() {
|
|
151
|
+
return this._references ?? null;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}));
|
|
158
155
|
//#endregion
|
|
159
|
-
|
|
156
|
+
init_column();
|
|
157
|
+
export { ColumnBuilder, init_column };
|
|
160
158
|
|
|
161
159
|
//# sourceMappingURL=column.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column.mjs","names":[],"sources":["../../src/schema/column.ts"],"sourcesContent":["import type { ColumnDataType, ColumnMetadata, DeferredRefMeta, ReferenceAction } from \"../types\";\n\n/**\n * Base column builder with chainable methods for defining column properties\n * @template T - The TypeScript type this column resolves to\n * @template TN - The table name this column belongs to (set by table())\n * @template CN - The column name (set by table())\n * @template Ref - The deferred reference metadata (set by references())\n */\nexport class ColumnBuilder<\n T = unknown,\n TN extends string = string,\n CN extends string = string,\n Ref extends DeferredRefMeta = never,\n> {\n declare readonly __type: T;\n declare readonly __tableName: TN;\n declare readonly __columnName: CN;\n declare readonly __ref: Ref;\n private _type: ColumnDataType;\n private _primaryKey = false;\n private _autoIncrement = false;\n private _notNull = false;\n private _unique = false;\n private _defaultValue: unknown = undefined;\n private _length?: number;\n private _precision?: number;\n private _scale?: number;\n private _columnAlias?: string;\n private _references?: {\n resolve: () => { table: string; column: string };\n onDelete?: ReferenceAction;\n onUpdate?: ReferenceAction;\n relationName?: string;\n };\n\n constructor(type: ColumnDataType, length?: number, precision?: number, scale?: number) {\n this._type = type;\n this._length = length;\n this._precision = precision;\n this._scale = scale;\n }\n\n /**\n * Set a custom database column name different from the property key\n * @param {string} alias - The column name to use in the database\n * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining\n * @example\n * // In code: guildId, In database: guild_id\n * guildId: varchar(255).name(\"guild_id\")\n */\n name(alias: string): ColumnBuilder<T, TN, CN, Ref> {\n this._columnAlias = alias;\n return this;\n }\n\n /**\n * Override the TypeScript type for this column with a custom type literal\n * @template U - The custom type to use\n * @returns {ColumnBuilder<U, TN, CN, Ref>} The column builder with the new type\n * @example\n * // Limits autocomplete to specific values\n * locale: varchar(25).type<\"en_US\" | \"es_ES\">()\n */\n type<U>(): ColumnBuilder<U, TN, CN, Ref> {\n return this as unknown as ColumnBuilder<U, TN, CN, Ref>;\n }\n\n /**\n * Mark this column as a primary key\n * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining\n */\n primaryKey(): ColumnBuilder<T, TN, CN, Ref> {\n this._primaryKey = true;\n return this;\n }\n\n /**\n * Mark this column as auto-incrementing\n * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining\n */\n autoIncrement(): ColumnBuilder<T, TN, CN, Ref> {\n this._autoIncrement = true;\n return this;\n }\n\n /**\n * Mark this column as NOT NULL\n * @returns {ColumnBuilder<NonNullable<T>, TN, CN, Ref>} The column builder for chaining\n */\n notNull(): ColumnBuilder<NonNullable<T>, TN, CN, Ref> {\n this._notNull = true;\n return this as unknown as ColumnBuilder<NonNullable<T>, TN, CN, Ref>;\n }\n\n /**\n * Mark this column as nullable\n * @returns {ColumnBuilder<T | null, TN, CN, Ref>} The column builder for chaining\n */\n nullable(): ColumnBuilder<T | null, TN, CN, Ref> {\n this._notNull = false;\n return this as unknown as ColumnBuilder<T | null, TN, CN, Ref>;\n }\n\n /**\n * Mark this column as nullable (alias for {@link nullable})\n * @returns {ColumnBuilder<T | null, TN, CN, Ref>} The column builder for chaining\n */\n null(): ColumnBuilder<T | null, TN, CN, Ref> {\n return this.nullable();\n }\n\n /**\n * Set a default value for this column\n * @param {T} value - The default value\n * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining\n */\n default(value: T): ColumnBuilder<T, TN, CN, Ref> {\n this._defaultValue = value;\n return this;\n }\n\n /**\n * Mark this column as having a unique constraint\n * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining\n */\n unique(): ColumnBuilder<T, TN, CN, Ref> {\n this._unique = true;\n return this;\n }\n\n /**\n * Add a foreign key reference to another table's column\n * @param {(() => ColumnBuilder<any>) | ColumnBuilder<any>} ref - A column reference or a function returning one\n * @param {object} [options] - Reference options\n * @param {ReferenceAction} [options.onDelete] - Action on delete\n * @param {ReferenceAction} [options.onUpdate] - Action on update\n * @param {string} [options.relationName] - Name for the relation\n * @returns {ColumnBuilder<T>} The column builder for chaining\n */\n references<\n R extends ColumnBuilder<any, string, string, any>,\n O extends {\n onDelete?: ReferenceAction;\n onUpdate?: ReferenceAction;\n relationName?: string;\n } = never,\n >(\n ref: (() => R) | R,\n options?: O,\n ): ColumnBuilder<\n T,\n TN,\n CN,\n DeferredRefMeta<\n CN,\n R[\"__tableName\"],\n R[\"__columnName\"],\n O extends { relationName: infer N extends string } ? N : undefined\n >\n > {\n this._references = {\n resolve: () => {\n const col = typeof ref === \"function\" ? ref() : ref;\n return {\n table: (col as any).__tableName ?? \"\",\n column: (col as any).__columnName ?? \"\",\n };\n },\n onDelete: options?.onDelete,\n onUpdate: options?.onUpdate,\n relationName: options?.relationName,\n };\n return this as any;\n }\n\n /**\n * Build the column metadata from the builder configuration\n * @param {string} name - The column name\n * @returns {ColumnMetadata} The built column metadata\n */\n __build(name: string): ColumnMetadata {\n return {\n name: this._columnAlias ?? name,\n type: this._type,\n primaryKey: this._primaryKey,\n autoIncrement: this._autoIncrement,\n notNull: this._notNull || this._primaryKey,\n unique: this._unique || this._primaryKey,\n defaultValue: this._defaultValue,\n length: this._length,\n precision: this._precision,\n scale: this._scale,\n columnAlias: this._columnAlias,\n };\n }\n\n /**\n * Get deferred reference data if this column has a foreign key reference\n * @returns {object | null} The deferred reference data or null\n */\n __getDeferredRef(): {\n resolve: () => { table: string; column: string };\n onDelete?: ReferenceAction;\n onUpdate?: ReferenceAction;\n relationName?: string;\n } | null {\n return this._references ?? null;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"column.mjs","names":[],"sources":["../../src/schema/column.ts"],"sourcesContent":["import type { ColumnDataType, ColumnMetadata, DeferredRefMeta, ReferenceAction } from \"../types\";\n\n/**\n * Base column builder with chainable methods for defining column properties\n * @template T - The TypeScript type this column resolves to\n * @template TN - The table name this column belongs to (set by table())\n * @template CN - The column name (set by table())\n * @template Ref - The deferred reference metadata (set by references())\n */\nexport class ColumnBuilder<\n T = unknown,\n TN extends string = string,\n CN extends string = string,\n Ref extends DeferredRefMeta = never,\n> {\n declare readonly __type: T;\n declare readonly __tableName: TN;\n declare readonly __columnName: CN;\n declare readonly __ref: Ref;\n private _type: ColumnDataType;\n private _primaryKey = false;\n private _autoIncrement = false;\n private _notNull = false;\n private _unique = false;\n private _defaultValue: unknown = undefined;\n private _length?: number;\n private _precision?: number;\n private _scale?: number;\n private _columnAlias?: string;\n private _references?: {\n resolve: () => { table: string; column: string };\n onDelete?: ReferenceAction;\n onUpdate?: ReferenceAction;\n relationName?: string;\n };\n\n constructor(type: ColumnDataType, length?: number, precision?: number, scale?: number) {\n this._type = type;\n this._length = length;\n this._precision = precision;\n this._scale = scale;\n }\n\n /**\n * Set a custom database column name different from the property key\n * @param {string} alias - The column name to use in the database\n * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining\n * @example\n * // In code: guildId, In database: guild_id\n * guildId: varchar(255).name(\"guild_id\")\n */\n name(alias: string): ColumnBuilder<T, TN, CN, Ref> {\n this._columnAlias = alias;\n return this;\n }\n\n /**\n * Override the TypeScript type for this column with a custom type literal\n * @template U - The custom type to use\n * @returns {ColumnBuilder<U, TN, CN, Ref>} The column builder with the new type\n * @example\n * // Limits autocomplete to specific values\n * locale: varchar(25).type<\"en_US\" | \"es_ES\">()\n */\n type<U>(): ColumnBuilder<U, TN, CN, Ref> {\n return this as unknown as ColumnBuilder<U, TN, CN, Ref>;\n }\n\n /**\n * Mark this column as a primary key\n * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining\n */\n primaryKey(): ColumnBuilder<T, TN, CN, Ref> {\n this._primaryKey = true;\n return this;\n }\n\n /**\n * Mark this column as auto-incrementing\n * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining\n */\n autoIncrement(): ColumnBuilder<T, TN, CN, Ref> {\n this._autoIncrement = true;\n return this;\n }\n\n /**\n * Mark this column as NOT NULL\n * @returns {ColumnBuilder<NonNullable<T>, TN, CN, Ref>} The column builder for chaining\n */\n notNull(): ColumnBuilder<NonNullable<T>, TN, CN, Ref> {\n this._notNull = true;\n return this as unknown as ColumnBuilder<NonNullable<T>, TN, CN, Ref>;\n }\n\n /**\n * Mark this column as nullable\n * @returns {ColumnBuilder<T | null, TN, CN, Ref>} The column builder for chaining\n */\n nullable(): ColumnBuilder<T | null, TN, CN, Ref> {\n this._notNull = false;\n return this as unknown as ColumnBuilder<T | null, TN, CN, Ref>;\n }\n\n /**\n * Mark this column as nullable (alias for {@link nullable})\n * @returns {ColumnBuilder<T | null, TN, CN, Ref>} The column builder for chaining\n */\n null(): ColumnBuilder<T | null, TN, CN, Ref> {\n return this.nullable();\n }\n\n /**\n * Set a default value for this column\n * @param {T} value - The default value\n * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining\n */\n default(value: T): ColumnBuilder<T, TN, CN, Ref> {\n this._defaultValue = value;\n return this;\n }\n\n /**\n * Mark this column as having a unique constraint\n * @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining\n */\n unique(): ColumnBuilder<T, TN, CN, Ref> {\n this._unique = true;\n return this;\n }\n\n /**\n * Add a foreign key reference to another table's column\n * @param {(() => ColumnBuilder<any>) | ColumnBuilder<any>} ref - A column reference or a function returning one\n * @param {object} [options] - Reference options\n * @param {ReferenceAction} [options.onDelete] - Action on delete\n * @param {ReferenceAction} [options.onUpdate] - Action on update\n * @param {string} [options.relationName] - Name for the relation\n * @returns {ColumnBuilder<T>} The column builder for chaining\n */\n references<\n R extends ColumnBuilder<any, string, string, any>,\n O extends {\n onDelete?: ReferenceAction;\n onUpdate?: ReferenceAction;\n relationName?: string;\n } = never,\n >(\n ref: (() => R) | R,\n options?: O,\n ): ColumnBuilder<\n T,\n TN,\n CN,\n DeferredRefMeta<\n CN,\n R[\"__tableName\"],\n R[\"__columnName\"],\n O extends { relationName: infer N extends string } ? N : undefined\n >\n > {\n this._references = {\n resolve: () => {\n const col = typeof ref === \"function\" ? ref() : ref;\n return {\n table: (col as any).__tableName ?? \"\",\n column: (col as any).__columnName ?? \"\",\n };\n },\n onDelete: options?.onDelete,\n onUpdate: options?.onUpdate,\n relationName: options?.relationName,\n };\n return this as any;\n }\n\n /**\n * Build the column metadata from the builder configuration\n * @param {string} name - The column name\n * @returns {ColumnMetadata} The built column metadata\n */\n __build(name: string): ColumnMetadata {\n return {\n name: this._columnAlias ?? name,\n type: this._type,\n primaryKey: this._primaryKey,\n autoIncrement: this._autoIncrement,\n notNull: this._notNull || this._primaryKey,\n unique: this._unique || this._primaryKey,\n defaultValue: this._defaultValue,\n length: this._length,\n precision: this._precision,\n scale: this._scale,\n columnAlias: this._columnAlias,\n };\n }\n\n /**\n * Get deferred reference data if this column has a foreign key reference\n * @returns {object | null} The deferred reference data or null\n */\n __getDeferredRef(): {\n resolve: () => { table: string; column: string };\n onDelete?: ReferenceAction;\n onUpdate?: ReferenceAction;\n relationName?: string;\n } | null {\n return this._references ?? null;\n }\n}\n"],"mappings":";;;;AASa,iBAAb,MAKE;EAKA;EACA,cAAsB;EACtB,iBAAyB;EACzB,WAAmB;EACnB,UAAkB;EAClB,gBAAiC,KAAA;EACjC;EACA;EACA;EACA;EACA;EAOA,YAAY,MAAsB,QAAiB,WAAoB,OAAgB;AACrF,QAAK,QAAQ;AACb,QAAK,UAAU;AACf,QAAK,aAAa;AAClB,QAAK,SAAS;;;;;;;;;;EAWhB,KAAK,OAA8C;AACjD,QAAK,eAAe;AACpB,UAAO;;;;;;;;;;EAWT,OAAyC;AACvC,UAAO;;;;;;EAOT,aAA4C;AAC1C,QAAK,cAAc;AACnB,UAAO;;;;;;EAOT,gBAA+C;AAC7C,QAAK,iBAAiB;AACtB,UAAO;;;;;;EAOT,UAAsD;AACpD,QAAK,WAAW;AAChB,UAAO;;;;;;EAOT,WAAiD;AAC/C,QAAK,WAAW;AAChB,UAAO;;;;;;EAOT,OAA6C;AAC3C,UAAO,KAAK,UAAU;;;;;;;EAQxB,QAAQ,OAAyC;AAC/C,QAAK,gBAAgB;AACrB,UAAO;;;;;;EAOT,SAAwC;AACtC,QAAK,UAAU;AACf,UAAO;;;;;;;;;;;EAYT,WAQE,KACA,SAWA;AACA,QAAK,cAAc;IACjB,eAAe;KACb,MAAM,MAAM,OAAO,QAAQ,aAAa,KAAK,GAAG;AAChD,YAAO;MACL,OAAQ,IAAY,eAAe;MACnC,QAAS,IAAY,gBAAgB;MACtC;;IAEH,UAAU,SAAS;IACnB,UAAU,SAAS;IACnB,cAAc,SAAS;IACxB;AACD,UAAO;;;;;;;EAQT,QAAQ,MAA8B;AACpC,UAAO;IACL,MAAM,KAAK,gBAAgB;IAC3B,MAAM,KAAK;IACX,YAAY,KAAK;IACjB,eAAe,KAAK;IACpB,SAAS,KAAK,YAAY,KAAK;IAC/B,QAAQ,KAAK,WAAW,KAAK;IAC7B,cAAc,KAAK;IACnB,QAAQ,KAAK;IACb,WAAW,KAAK;IAChB,OAAO,KAAK;IACZ,aAAa,KAAK;IACnB;;;;;;EAOH,mBAKS;AACP,UAAO,KAAK,eAAe"}
|