@hedystia/db 2.0.0 → 2.0.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/dist/_virtual/_rolldown/runtime.cjs +13 -0
- package/dist/_virtual/_rolldown/runtime.mjs +17 -0
- package/dist/cache/manager.cjs +137 -0
- package/dist/cache/manager.cjs.map +1 -0
- package/dist/cache/manager.d.cts +72 -0
- package/dist/cache/manager.d.mts +72 -0
- package/dist/cache/manager.mjs +140 -0
- package/dist/cache/manager.mjs.map +1 -0
- package/dist/cache/memory-store.cjs +122 -0
- package/dist/cache/memory-store.cjs.map +1 -0
- package/dist/cache/memory-store.mjs +122 -0
- package/dist/cache/memory-store.mjs.map +1 -0
- package/dist/cli/commands/migration.cjs +22 -0
- package/dist/cli/commands/migration.cjs.map +1 -0
- package/dist/cli/commands/migration.mjs +32 -0
- package/dist/cli/commands/migration.mjs.map +1 -0
- package/dist/cli/commands/schema.cjs +21 -0
- package/dist/cli/commands/schema.cjs.map +1 -0
- package/dist/cli/commands/schema.mjs +30 -0
- package/dist/cli/commands/schema.mjs.map +1 -0
- package/dist/cli.cjs +50 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +57 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/constants.cjs +16 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.mjs +16 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/core/database.cjs +158 -0
- package/dist/core/database.cjs.map +1 -0
- package/dist/core/database.d.cts +74 -0
- package/dist/core/database.d.mts +74 -0
- package/dist/core/database.mjs +159 -0
- package/dist/core/database.mjs.map +1 -0
- package/dist/core/repository.cjs +416 -0
- package/dist/core/repository.cjs.map +1 -0
- package/dist/core/repository.d.cts +110 -0
- package/dist/core/repository.d.mts +110 -0
- package/dist/core/repository.mjs +416 -0
- package/dist/core/repository.mjs.map +1 -0
- package/dist/drivers/driver.cjs +11 -0
- package/dist/drivers/driver.cjs.map +1 -0
- package/dist/drivers/driver.mjs +11 -0
- package/dist/drivers/driver.mjs.map +1 -0
- package/dist/drivers/file.cjs +336 -0
- package/dist/drivers/file.cjs.map +1 -0
- package/dist/drivers/file.mjs +337 -0
- package/dist/drivers/file.mjs.map +1 -0
- package/dist/drivers/index.cjs +28 -0
- package/dist/drivers/index.cjs.map +1 -0
- package/dist/drivers/index.d.cts +14 -0
- package/dist/drivers/index.d.mts +14 -0
- package/dist/drivers/index.mjs +28 -0
- package/dist/drivers/index.mjs.map +1 -0
- package/dist/drivers/mysql.cjs +272 -0
- package/dist/drivers/mysql.cjs.map +1 -0
- package/dist/drivers/mysql.mjs +272 -0
- package/dist/drivers/mysql.mjs.map +1 -0
- package/dist/drivers/sql-compiler.cjs +284 -0
- package/dist/drivers/sql-compiler.cjs.map +1 -0
- package/dist/drivers/sql-compiler.d.cts +66 -0
- package/dist/drivers/sql-compiler.d.mts +66 -0
- package/dist/drivers/sql-compiler.mjs +276 -0
- package/dist/drivers/sql-compiler.mjs.map +1 -0
- package/dist/drivers/sqlite.cjs +262 -0
- package/dist/drivers/sqlite.cjs.map +1 -0
- package/dist/drivers/sqlite.mjs +262 -0
- package/dist/drivers/sqlite.mjs.map +1 -0
- package/dist/errors.cjs +74 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +46 -0
- package/dist/errors.d.mts +46 -0
- package/dist/errors.mjs +68 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.cjs +69 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.mts +15 -0
- package/dist/index.mjs +21 -0
- package/dist/index.mjs.map +1 -0
- package/dist/migrations/definition.cjs +20 -0
- package/dist/migrations/definition.cjs.map +1 -0
- package/dist/migrations/definition.d.cts +18 -0
- package/dist/migrations/definition.d.mts +18 -0
- package/dist/migrations/definition.mjs +23 -0
- package/dist/migrations/definition.mjs.map +1 -0
- package/dist/migrations/index.mjs +12 -0
- package/dist/migrations/index.mjs.map +1 -0
- package/dist/migrations/templates.cjs +39 -0
- package/dist/migrations/templates.cjs.map +1 -0
- package/dist/migrations/templates.d.cts +16 -0
- package/dist/migrations/templates.d.mts +16 -0
- package/dist/migrations/templates.mjs +41 -0
- package/dist/migrations/templates.mjs.map +1 -0
- package/dist/schema/column.cjs +161 -0
- package/dist/schema/column.cjs.map +1 -0
- package/dist/schema/column.d.cts +120 -0
- package/dist/schema/column.d.mts +120 -0
- package/dist/schema/column.mjs +161 -0
- package/dist/schema/column.mjs.map +1 -0
- package/dist/schema/columns/index.cjs +202 -0
- package/dist/schema/columns/index.cjs.map +1 -0
- package/dist/schema/columns/index.d.cts +141 -0
- package/dist/schema/columns/index.d.mts +141 -0
- package/dist/schema/columns/index.mjs +182 -0
- package/dist/schema/columns/index.mjs.map +1 -0
- package/dist/schema/registry.cjs +125 -0
- package/dist/schema/registry.cjs.map +1 -0
- package/dist/schema/registry.d.cts +66 -0
- package/dist/schema/registry.d.mts +66 -0
- package/dist/schema/registry.mjs +125 -0
- package/dist/schema/registry.mjs.map +1 -0
- package/dist/schema/table.cjs +39 -0
- package/dist/schema/table.cjs.map +1 -0
- package/dist/schema/table.d.cts +17 -0
- package/dist/schema/table.d.mts +17 -0
- package/dist/schema/table.mjs +39 -0
- package/dist/schema/table.mjs.map +1 -0
- package/dist/sync/synchronizer.cjs +43 -0
- package/dist/sync/synchronizer.cjs.map +1 -0
- package/dist/sync/synchronizer.d.cts +22 -0
- package/dist/sync/synchronizer.d.mts +22 -0
- package/dist/sync/synchronizer.mjs +43 -0
- package/dist/sync/synchronizer.mjs.map +1 -0
- package/dist/types.d.cts +229 -0
- package/dist/types.d.mts +229 -0
- package/dist/utils/fs.cjs +24 -0
- package/dist/utils/fs.cjs.map +1 -0
- package/dist/utils/fs.mjs +26 -0
- package/dist/utils/fs.mjs.map +1 -0
- package/dist/utils/index.mjs +14 -0
- package/dist/utils/index.mjs.map +1 -0
- package/dist/utils/naming.cjs +13 -0
- package/dist/utils/naming.cjs.map +1 -0
- package/dist/utils/naming.mjs +16 -0
- package/dist/utils/naming.mjs.map +1 -0
- package/dist/utils/stable-stringify.cjs +19 -0
- package/dist/utils/stable-stringify.cjs.map +1 -0
- package/dist/utils/stable-stringify.mjs +22 -0
- package/dist/utils/stable-stringify.mjs.map +1 -0
- package/package.json +64 -27
- package/readme.md +87 -105
- package/index.d.ts +0 -65
- package/index.js +0 -1
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CacheManager } from "./cache/manager.mjs";
|
|
2
|
+
import { CacheError, DatabaseError, DriverError, MigrationError, QueryError, SchemaError, SyncError } from "./errors.mjs";
|
|
3
|
+
import { compileColumnDef, compileCreateTable, compileDelete, compileInsert, compileSelect, compileUpdate, compileWhere } from "./drivers/sql-compiler.mjs";
|
|
4
|
+
import { createDriver } from "./drivers/index.mjs";
|
|
5
|
+
import { ColumnBuilder } from "./schema/column.mjs";
|
|
6
|
+
import { NamedColumnStarter, bigint, blob, boolean, char, columns_exports, d, datetime, decimal, float, integer, json, name, text, timestamp, varchar } from "./schema/columns/index.mjs";
|
|
7
|
+
import { SchemaRegistry } from "./schema/registry.mjs";
|
|
8
|
+
import { table } from "./schema/table.mjs";
|
|
9
|
+
import { TableRepository } from "./core/repository.mjs";
|
|
10
|
+
import { database } from "./core/database.mjs";
|
|
11
|
+
import { init_definition, migration } from "./migrations/definition.mjs";
|
|
12
|
+
import { generateMigrationTemplate, generateSchemaTemplate, init_templates } from "./migrations/templates.mjs";
|
|
13
|
+
import { Synchronizer } from "./sync/synchronizer.mjs";
|
|
14
|
+
//#region src/index.ts
|
|
15
|
+
init_definition();
|
|
16
|
+
init_templates();
|
|
17
|
+
var src_default = database;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { CacheError, CacheManager, ColumnBuilder, DatabaseError, DriverError, MigrationError, NamedColumnStarter, QueryError, SchemaError, SchemaRegistry, SyncError, Synchronizer, TableRepository, 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 };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +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 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":";;;;;;;;;;;;;;iBAaoD;gBACuC;AAqE3F,IAAA,cAAe"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/migrations/definition.ts
|
|
2
|
+
/**
|
|
3
|
+
* Define a database migration
|
|
4
|
+
* @param {string} name - Migration name (should match the file name)
|
|
5
|
+
* @param {object} actions - Migration actions
|
|
6
|
+
* @param {(ctx: MigrationContext) => Promise<void>} actions.up - Function to run when applying the migration
|
|
7
|
+
* @param {(ctx: MigrationContext) => Promise<void>} actions.down - Function to run when reverting the migration
|
|
8
|
+
* @returns {MigrationDefinition} The migration definition
|
|
9
|
+
*/
|
|
10
|
+
function migration(name, actions) {
|
|
11
|
+
return {
|
|
12
|
+
name,
|
|
13
|
+
up: actions.up,
|
|
14
|
+
down: actions.down
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
exports.migration = migration;
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=definition.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definition.cjs","names":[],"sources":["../../src/migrations/definition.ts"],"sourcesContent":["import type { MigrationContext, MigrationDefinition } from \"../types\";\n\n/**\n * Define a database migration\n * @param {string} name - Migration name (should match the file name)\n * @param {object} actions - Migration actions\n * @param {(ctx: MigrationContext) => Promise<void>} actions.up - Function to run when applying the migration\n * @param {(ctx: MigrationContext) => Promise<void>} actions.down - Function to run when reverting the migration\n * @returns {MigrationDefinition} The migration definition\n */\nexport function migration(\n name: string,\n actions: {\n up: (ctx: MigrationContext) => Promise<void>;\n down: (ctx: MigrationContext) => Promise<void>;\n },\n): MigrationDefinition {\n return {\n name,\n up: actions.up,\n down: actions.down,\n };\n}\n"],"mappings":";;;;;;;;;AAUA,SAAgB,UACd,MACA,SAIqB;AACrB,QAAO;EACL;EACA,IAAI,QAAQ;EACZ,MAAM,QAAQ;EACf"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MigrationContext, MigrationDefinition } from "../types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/migrations/definition.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Define a database migration
|
|
6
|
+
* @param {string} name - Migration name (should match the file name)
|
|
7
|
+
* @param {object} actions - Migration actions
|
|
8
|
+
* @param {(ctx: MigrationContext) => Promise<void>} actions.up - Function to run when applying the migration
|
|
9
|
+
* @param {(ctx: MigrationContext) => Promise<void>} actions.down - Function to run when reverting the migration
|
|
10
|
+
* @returns {MigrationDefinition} The migration definition
|
|
11
|
+
*/
|
|
12
|
+
declare function migration(name: string, actions: {
|
|
13
|
+
up: (ctx: MigrationContext) => Promise<void>;
|
|
14
|
+
down: (ctx: MigrationContext) => Promise<void>;
|
|
15
|
+
}): MigrationDefinition;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { migration };
|
|
18
|
+
//# sourceMappingURL=definition.d.cts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MigrationContext, MigrationDefinition } from "../types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/migrations/definition.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Define a database migration
|
|
6
|
+
* @param {string} name - Migration name (should match the file name)
|
|
7
|
+
* @param {object} actions - Migration actions
|
|
8
|
+
* @param {(ctx: MigrationContext) => Promise<void>} actions.up - Function to run when applying the migration
|
|
9
|
+
* @param {(ctx: MigrationContext) => Promise<void>} actions.down - Function to run when reverting the migration
|
|
10
|
+
* @returns {MigrationDefinition} The migration definition
|
|
11
|
+
*/
|
|
12
|
+
declare function migration(name: string, actions: {
|
|
13
|
+
up: (ctx: MigrationContext) => Promise<void>;
|
|
14
|
+
down: (ctx: MigrationContext) => Promise<void>;
|
|
15
|
+
}): MigrationDefinition;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { migration };
|
|
18
|
+
//# sourceMappingURL=definition.d.mts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { __esmMin } from "../_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
//#region src/migrations/definition.ts
|
|
3
|
+
/**
|
|
4
|
+
* Define a database migration
|
|
5
|
+
* @param {string} name - Migration name (should match the file name)
|
|
6
|
+
* @param {object} actions - Migration actions
|
|
7
|
+
* @param {(ctx: MigrationContext) => Promise<void>} actions.up - Function to run when applying the migration
|
|
8
|
+
* @param {(ctx: MigrationContext) => Promise<void>} actions.down - Function to run when reverting the migration
|
|
9
|
+
* @returns {MigrationDefinition} The migration definition
|
|
10
|
+
*/
|
|
11
|
+
function migration(name, actions) {
|
|
12
|
+
return {
|
|
13
|
+
name,
|
|
14
|
+
up: actions.up,
|
|
15
|
+
down: actions.down
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
var init_definition = __esmMin((() => {}));
|
|
19
|
+
//#endregion
|
|
20
|
+
init_definition();
|
|
21
|
+
export { init_definition, migration };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=definition.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definition.mjs","names":[],"sources":["../../src/migrations/definition.ts"],"sourcesContent":["import type { MigrationContext, MigrationDefinition } from \"../types\";\n\n/**\n * Define a database migration\n * @param {string} name - Migration name (should match the file name)\n * @param {object} actions - Migration actions\n * @param {(ctx: MigrationContext) => Promise<void>} actions.up - Function to run when applying the migration\n * @param {(ctx: MigrationContext) => Promise<void>} actions.down - Function to run when reverting the migration\n * @returns {MigrationDefinition} The migration definition\n */\nexport function migration(\n name: string,\n actions: {\n up: (ctx: MigrationContext) => Promise<void>;\n down: (ctx: MigrationContext) => Promise<void>;\n },\n): MigrationDefinition {\n return {\n name,\n up: actions.up,\n down: actions.down,\n };\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,UACd,MACA,SAIqB;AACrB,QAAO;EACL;EACA,IAAI,QAAQ;EACZ,MAAM,QAAQ;EACf"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { __esmMin } from "../_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
import "./definition.mjs";
|
|
3
|
+
import { init_templates } from "./templates.mjs";
|
|
4
|
+
//#region src/migrations/index.ts
|
|
5
|
+
var init_migrations = __esmMin((() => {
|
|
6
|
+
init_templates();
|
|
7
|
+
}));
|
|
8
|
+
//#endregion
|
|
9
|
+
init_migrations();
|
|
10
|
+
export { init_migrations };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/migrations/index.ts"],"sourcesContent":["export { migration } from \"./definition\";\nexport { generateMigrationTemplate, generateSchemaTemplate } from \"./templates\";\n"],"mappings":";;;;;iBACgF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/migrations/templates.ts
|
|
2
|
+
/**
|
|
3
|
+
* Generate a migration file template
|
|
4
|
+
* @param {string} name - Migration name
|
|
5
|
+
* @returns {string} Migration file content
|
|
6
|
+
*/
|
|
7
|
+
function generateMigrationTemplate(name) {
|
|
8
|
+
return `import { migration } from "@hedystia/db";
|
|
9
|
+
|
|
10
|
+
export default migration("${name}", {
|
|
11
|
+
async up({ schema, sql }) {
|
|
12
|
+
// Add your migration logic here
|
|
13
|
+
},
|
|
14
|
+
async down({ schema, sql }) {
|
|
15
|
+
// Add your rollback logic here
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Generate a schema file template
|
|
22
|
+
* @param {string} name - Table name
|
|
23
|
+
* @returns {string} Schema file content
|
|
24
|
+
*/
|
|
25
|
+
function generateSchemaTemplate(name) {
|
|
26
|
+
return `import { table, integer, datetime } from "@hedystia/db";
|
|
27
|
+
|
|
28
|
+
export const ${name} = table("${name}", {
|
|
29
|
+
id: integer().primaryKey().autoIncrement(),
|
|
30
|
+
createdAt: datetime().default(new Date()),
|
|
31
|
+
updatedAt: datetime().default(new Date()),
|
|
32
|
+
});
|
|
33
|
+
`;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
exports.generateMigrationTemplate = generateMigrationTemplate;
|
|
37
|
+
exports.generateSchemaTemplate = generateSchemaTemplate;
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=templates.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.cjs","names":[],"sources":["../../src/migrations/templates.ts"],"sourcesContent":["/**\n * Generate a migration file template\n * @param {string} name - Migration name\n * @returns {string} Migration file content\n */\nexport function generateMigrationTemplate(name: string): string {\n return `import { migration } from \"@hedystia/db\";\n\nexport default migration(\"${name}\", {\n async up({ schema, sql }) {\n // Add your migration logic here\n },\n async down({ schema, sql }) {\n // Add your rollback logic here\n },\n});\n`;\n}\n\n/**\n * Generate a schema file template\n * @param {string} name - Table name\n * @returns {string} Schema file content\n */\nexport function generateSchemaTemplate(name: string): string {\n return `import { table, integer, datetime } from \"@hedystia/db\";\n\nexport const ${name} = table(\"${name}\", {\n id: integer().primaryKey().autoIncrement(),\n createdAt: datetime().default(new Date()),\n updatedAt: datetime().default(new Date()),\n});\n`;\n}\n"],"mappings":";;;;;;AAKA,SAAgB,0BAA0B,MAAsB;AAC9D,QAAO;;4BAEmB,KAAK;;;;;;;;;;;;;;;AAgBjC,SAAgB,uBAAuB,MAAsB;AAC3D,QAAO;;eAEM,KAAK,YAAY,KAAK"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/migrations/templates.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Generate a migration file template
|
|
4
|
+
* @param {string} name - Migration name
|
|
5
|
+
* @returns {string} Migration file content
|
|
6
|
+
*/
|
|
7
|
+
declare function generateMigrationTemplate(name: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Generate a schema file template
|
|
10
|
+
* @param {string} name - Table name
|
|
11
|
+
* @returns {string} Schema file content
|
|
12
|
+
*/
|
|
13
|
+
declare function generateSchemaTemplate(name: string): string;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { generateMigrationTemplate, generateSchemaTemplate };
|
|
16
|
+
//# sourceMappingURL=templates.d.cts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/migrations/templates.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Generate a migration file template
|
|
4
|
+
* @param {string} name - Migration name
|
|
5
|
+
* @returns {string} Migration file content
|
|
6
|
+
*/
|
|
7
|
+
declare function generateMigrationTemplate(name: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Generate a schema file template
|
|
10
|
+
* @param {string} name - Table name
|
|
11
|
+
* @returns {string} Schema file content
|
|
12
|
+
*/
|
|
13
|
+
declare function generateSchemaTemplate(name: string): string;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { generateMigrationTemplate, generateSchemaTemplate };
|
|
16
|
+
//# sourceMappingURL=templates.d.mts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { __esmMin } from "../_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
//#region src/migrations/templates.ts
|
|
3
|
+
/**
|
|
4
|
+
* Generate a migration file template
|
|
5
|
+
* @param {string} name - Migration name
|
|
6
|
+
* @returns {string} Migration file content
|
|
7
|
+
*/
|
|
8
|
+
function generateMigrationTemplate(name) {
|
|
9
|
+
return `import { migration } from "@hedystia/db";
|
|
10
|
+
|
|
11
|
+
export default migration("${name}", {
|
|
12
|
+
async up({ schema, sql }) {
|
|
13
|
+
// Add your migration logic here
|
|
14
|
+
},
|
|
15
|
+
async down({ schema, sql }) {
|
|
16
|
+
// Add your rollback logic here
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Generate a schema file template
|
|
23
|
+
* @param {string} name - Table name
|
|
24
|
+
* @returns {string} Schema file content
|
|
25
|
+
*/
|
|
26
|
+
function generateSchemaTemplate(name) {
|
|
27
|
+
return `import { table, integer, datetime } from "@hedystia/db";
|
|
28
|
+
|
|
29
|
+
export const ${name} = table("${name}", {
|
|
30
|
+
id: integer().primaryKey().autoIncrement(),
|
|
31
|
+
createdAt: datetime().default(new Date()),
|
|
32
|
+
updatedAt: datetime().default(new Date()),
|
|
33
|
+
});
|
|
34
|
+
`;
|
|
35
|
+
}
|
|
36
|
+
var init_templates = __esmMin((() => {}));
|
|
37
|
+
//#endregion
|
|
38
|
+
init_templates();
|
|
39
|
+
export { generateMigrationTemplate, generateSchemaTemplate, init_templates };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=templates.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.mjs","names":[],"sources":["../../src/migrations/templates.ts"],"sourcesContent":["/**\n * Generate a migration file template\n * @param {string} name - Migration name\n * @returns {string} Migration file content\n */\nexport function generateMigrationTemplate(name: string): string {\n return `import { migration } from \"@hedystia/db\";\n\nexport default migration(\"${name}\", {\n async up({ schema, sql }) {\n // Add your migration logic here\n },\n async down({ schema, sql }) {\n // Add your rollback logic here\n },\n});\n`;\n}\n\n/**\n * Generate a schema file template\n * @param {string} name - Table name\n * @returns {string} Schema file content\n */\nexport function generateSchemaTemplate(name: string): string {\n return `import { table, integer, datetime } from \"@hedystia/db\";\n\nexport const ${name} = table(\"${name}\", {\n id: integer().primaryKey().autoIncrement(),\n createdAt: datetime().default(new Date()),\n updatedAt: datetime().default(new Date()),\n});\n`;\n}\n"],"mappings":";;;;;;;AAKA,SAAgB,0BAA0B,MAAsB;AAC9D,QAAO;;4BAEmB,KAAK;;;;;;;;;;;;;;;AAgBjC,SAAgB,uBAAuB,MAAsB;AAC3D,QAAO;;eAEM,KAAK,YAAY,KAAK"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
//#region src/schema/column.ts
|
|
2
|
+
/**
|
|
3
|
+
* Base column builder with chainable methods for defining column properties
|
|
4
|
+
* @template T - The TypeScript type this column resolves to
|
|
5
|
+
* @template TN - The table name this column belongs to (set by table())
|
|
6
|
+
* @template CN - The column name (set by table())
|
|
7
|
+
* @template Ref - The deferred reference metadata (set by references())
|
|
8
|
+
*/
|
|
9
|
+
var ColumnBuilder = class {
|
|
10
|
+
_type;
|
|
11
|
+
_primaryKey = false;
|
|
12
|
+
_autoIncrement = false;
|
|
13
|
+
_notNull = false;
|
|
14
|
+
_unique = false;
|
|
15
|
+
_defaultValue = void 0;
|
|
16
|
+
_length;
|
|
17
|
+
_precision;
|
|
18
|
+
_scale;
|
|
19
|
+
_columnAlias;
|
|
20
|
+
_references;
|
|
21
|
+
constructor(type, length, precision, scale) {
|
|
22
|
+
this._type = type;
|
|
23
|
+
this._length = length;
|
|
24
|
+
this._precision = precision;
|
|
25
|
+
this._scale = scale;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Set a custom database column name different from the property key
|
|
29
|
+
* @param {string} alias - The column name to use in the database
|
|
30
|
+
* @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
|
|
31
|
+
* @example
|
|
32
|
+
* // In code: guildId, In database: guild_id
|
|
33
|
+
* guildId: varchar(255).name("guild_id")
|
|
34
|
+
*/
|
|
35
|
+
name(alias) {
|
|
36
|
+
this._columnAlias = alias;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Override the TypeScript type for this column with a custom type literal
|
|
41
|
+
* @template U - The custom type to use
|
|
42
|
+
* @returns {ColumnBuilder<U, TN, CN, Ref>} The column builder with the new type
|
|
43
|
+
* @example
|
|
44
|
+
* // Limits autocomplete to specific values
|
|
45
|
+
* locale: varchar(25).type<"en_US" | "es_ES">()
|
|
46
|
+
*/
|
|
47
|
+
type() {
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Mark this column as a primary key
|
|
52
|
+
* @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
|
|
53
|
+
*/
|
|
54
|
+
primaryKey() {
|
|
55
|
+
this._primaryKey = true;
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Mark this column as auto-incrementing
|
|
60
|
+
* @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
|
|
61
|
+
*/
|
|
62
|
+
autoIncrement() {
|
|
63
|
+
this._autoIncrement = true;
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Mark this column as NOT NULL
|
|
68
|
+
* @returns {ColumnBuilder<NonNullable<T>, TN, CN, Ref>} The column builder for chaining
|
|
69
|
+
*/
|
|
70
|
+
notNull() {
|
|
71
|
+
this._notNull = true;
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Mark this column as nullable
|
|
76
|
+
* @returns {ColumnBuilder<T | null, TN, CN, Ref>} The column builder for chaining
|
|
77
|
+
*/
|
|
78
|
+
nullable() {
|
|
79
|
+
this._notNull = false;
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Mark this column as nullable (alias for {@link nullable})
|
|
84
|
+
* @returns {ColumnBuilder<T | null, TN, CN, Ref>} The column builder for chaining
|
|
85
|
+
*/
|
|
86
|
+
null() {
|
|
87
|
+
return this.nullable();
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Set a default value for this column
|
|
91
|
+
* @param {T} value - The default value
|
|
92
|
+
* @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
|
|
93
|
+
*/
|
|
94
|
+
default(value) {
|
|
95
|
+
this._defaultValue = value;
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Mark this column as having a unique constraint
|
|
100
|
+
* @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
|
|
101
|
+
*/
|
|
102
|
+
unique() {
|
|
103
|
+
this._unique = true;
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Add a foreign key reference to another table's column
|
|
108
|
+
* @param {() => ColumnBuilder<any>} ref - A function returning the referenced column
|
|
109
|
+
* @param {object} [options] - Reference options
|
|
110
|
+
* @param {ReferenceAction} [options.onDelete] - Action on delete
|
|
111
|
+
* @param {ReferenceAction} [options.onUpdate] - Action on update
|
|
112
|
+
* @param {string} [options.relationName] - Name for the relation
|
|
113
|
+
* @returns {ColumnBuilder<T>} The column builder for chaining
|
|
114
|
+
*/
|
|
115
|
+
references(ref, options) {
|
|
116
|
+
this._references = {
|
|
117
|
+
resolve: () => {
|
|
118
|
+
const col = ref();
|
|
119
|
+
return {
|
|
120
|
+
table: col.__tableName ?? "",
|
|
121
|
+
column: col.__columnName ?? ""
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
onDelete: options?.onDelete,
|
|
125
|
+
onUpdate: options?.onUpdate,
|
|
126
|
+
relationName: options?.relationName
|
|
127
|
+
};
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Build the column metadata from the builder configuration
|
|
132
|
+
* @param {string} name - The column name
|
|
133
|
+
* @returns {ColumnMetadata} The built column metadata
|
|
134
|
+
*/
|
|
135
|
+
__build(name) {
|
|
136
|
+
return {
|
|
137
|
+
name: this._columnAlias ?? name,
|
|
138
|
+
type: this._type,
|
|
139
|
+
primaryKey: this._primaryKey,
|
|
140
|
+
autoIncrement: this._autoIncrement,
|
|
141
|
+
notNull: this._notNull || this._primaryKey,
|
|
142
|
+
unique: this._unique || this._primaryKey,
|
|
143
|
+
defaultValue: this._defaultValue,
|
|
144
|
+
length: this._length,
|
|
145
|
+
precision: this._precision,
|
|
146
|
+
scale: this._scale,
|
|
147
|
+
columnAlias: this._columnAlias
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get deferred reference data if this column has a foreign key reference
|
|
152
|
+
* @returns {object | null} The deferred reference data or null
|
|
153
|
+
*/
|
|
154
|
+
__getDeferredRef() {
|
|
155
|
+
return this._references ?? null;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
//#endregion
|
|
159
|
+
exports.ColumnBuilder = ColumnBuilder;
|
|
160
|
+
|
|
161
|
+
//# sourceMappingURL=column.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column.cjs","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>} ref - A function returning the referenced column\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,\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 = 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,IAAa,gBAAb,MAKE;CAKA;CACA,cAAsB;CACtB,iBAAyB;CACzB,WAAmB;CACnB,UAAkB;CAClB,gBAAiC,KAAA;CACjC;CACA;CACA;CACA;CACA;CAOA,YAAY,MAAsB,QAAiB,WAAoB,OAAgB;AACrF,OAAK,QAAQ;AACb,OAAK,UAAU;AACf,OAAK,aAAa;AAClB,OAAK,SAAS;;;;;;;;;;CAWhB,KAAK,OAA8C;AACjD,OAAK,eAAe;AACpB,SAAO;;;;;;;;;;CAWT,OAAyC;AACvC,SAAO;;;;;;CAOT,aAA4C;AAC1C,OAAK,cAAc;AACnB,SAAO;;;;;;CAOT,gBAA+C;AAC7C,OAAK,iBAAiB;AACtB,SAAO;;;;;;CAOT,UAAsD;AACpD,OAAK,WAAW;AAChB,SAAO;;;;;;CAOT,WAAiD;AAC/C,OAAK,WAAW;AAChB,SAAO;;;;;;CAOT,OAA6C;AAC3C,SAAO,KAAK,UAAU;;;;;;;CAQxB,QAAQ,OAAyC;AAC/C,OAAK,gBAAgB;AACrB,SAAO;;;;;;CAOT,SAAwC;AACtC,OAAK,UAAU;AACf,SAAO;;;;;;;;;;;CAYT,WAQE,KACA,SAWA;AACA,OAAK,cAAc;GACjB,eAAe;IACb,MAAM,MAAM,KAAK;AACjB,WAAO;KACL,OAAQ,IAAY,eAAe;KACnC,QAAS,IAAY,gBAAgB;KACtC;;GAEH,UAAU,SAAS;GACnB,UAAU,SAAS;GACnB,cAAc,SAAS;GACxB;AACD,SAAO;;;;;;;CAQT,QAAQ,MAA8B;AACpC,SAAO;GACL,MAAM,KAAK,gBAAgB;GAC3B,MAAM,KAAK;GACX,YAAY,KAAK;GACjB,eAAe,KAAK;GACpB,SAAS,KAAK,YAAY,KAAK;GAC/B,QAAQ,KAAK,WAAW,KAAK;GAC7B,cAAc,KAAK;GACnB,QAAQ,KAAK;GACb,WAAW,KAAK;GAChB,OAAO,KAAK;GACZ,aAAa,KAAK;GACnB;;;;;;CAOH,mBAKS;AACP,SAAO,KAAK,eAAe"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { ColumnDataType, ColumnMetadata, DeferredRefMeta, ReferenceAction } from "../types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/schema/column.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Base column builder with chainable methods for defining column properties
|
|
6
|
+
* @template T - The TypeScript type this column resolves to
|
|
7
|
+
* @template TN - The table name this column belongs to (set by table())
|
|
8
|
+
* @template CN - The column name (set by table())
|
|
9
|
+
* @template Ref - The deferred reference metadata (set by references())
|
|
10
|
+
*/
|
|
11
|
+
declare class ColumnBuilder<T = unknown, TN extends string = string, CN extends string = string, Ref extends DeferredRefMeta = never> {
|
|
12
|
+
readonly __type: T;
|
|
13
|
+
readonly __tableName: TN;
|
|
14
|
+
readonly __columnName: CN;
|
|
15
|
+
readonly __ref: Ref;
|
|
16
|
+
private _type;
|
|
17
|
+
private _primaryKey;
|
|
18
|
+
private _autoIncrement;
|
|
19
|
+
private _notNull;
|
|
20
|
+
private _unique;
|
|
21
|
+
private _defaultValue;
|
|
22
|
+
private _length?;
|
|
23
|
+
private _precision?;
|
|
24
|
+
private _scale?;
|
|
25
|
+
private _columnAlias?;
|
|
26
|
+
private _references?;
|
|
27
|
+
constructor(type: ColumnDataType, length?: number, precision?: number, scale?: number);
|
|
28
|
+
/**
|
|
29
|
+
* Set a custom database column name different from the property key
|
|
30
|
+
* @param {string} alias - The column name to use in the database
|
|
31
|
+
* @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
|
|
32
|
+
* @example
|
|
33
|
+
* // In code: guildId, In database: guild_id
|
|
34
|
+
* guildId: varchar(255).name("guild_id")
|
|
35
|
+
*/
|
|
36
|
+
name(alias: string): ColumnBuilder<T, TN, CN, Ref>;
|
|
37
|
+
/**
|
|
38
|
+
* Override the TypeScript type for this column with a custom type literal
|
|
39
|
+
* @template U - The custom type to use
|
|
40
|
+
* @returns {ColumnBuilder<U, TN, CN, Ref>} The column builder with the new type
|
|
41
|
+
* @example
|
|
42
|
+
* // Limits autocomplete to specific values
|
|
43
|
+
* locale: varchar(25).type<"en_US" | "es_ES">()
|
|
44
|
+
*/
|
|
45
|
+
type<U>(): ColumnBuilder<U, TN, CN, Ref>;
|
|
46
|
+
/**
|
|
47
|
+
* Mark this column as a primary key
|
|
48
|
+
* @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
|
|
49
|
+
*/
|
|
50
|
+
primaryKey(): ColumnBuilder<T, TN, CN, Ref>;
|
|
51
|
+
/**
|
|
52
|
+
* Mark this column as auto-incrementing
|
|
53
|
+
* @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
|
|
54
|
+
*/
|
|
55
|
+
autoIncrement(): ColumnBuilder<T, TN, CN, Ref>;
|
|
56
|
+
/**
|
|
57
|
+
* Mark this column as NOT NULL
|
|
58
|
+
* @returns {ColumnBuilder<NonNullable<T>, TN, CN, Ref>} The column builder for chaining
|
|
59
|
+
*/
|
|
60
|
+
notNull(): ColumnBuilder<NonNullable<T>, TN, CN, Ref>;
|
|
61
|
+
/**
|
|
62
|
+
* Mark this column as nullable
|
|
63
|
+
* @returns {ColumnBuilder<T | null, TN, CN, Ref>} The column builder for chaining
|
|
64
|
+
*/
|
|
65
|
+
nullable(): ColumnBuilder<T | null, TN, CN, Ref>;
|
|
66
|
+
/**
|
|
67
|
+
* Mark this column as nullable (alias for {@link nullable})
|
|
68
|
+
* @returns {ColumnBuilder<T | null, TN, CN, Ref>} The column builder for chaining
|
|
69
|
+
*/
|
|
70
|
+
null(): ColumnBuilder<T | null, TN, CN, Ref>;
|
|
71
|
+
/**
|
|
72
|
+
* Set a default value for this column
|
|
73
|
+
* @param {T} value - The default value
|
|
74
|
+
* @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
|
|
75
|
+
*/
|
|
76
|
+
default(value: T): ColumnBuilder<T, TN, CN, Ref>;
|
|
77
|
+
/**
|
|
78
|
+
* Mark this column as having a unique constraint
|
|
79
|
+
* @returns {ColumnBuilder<T, TN, CN, Ref>} The column builder for chaining
|
|
80
|
+
*/
|
|
81
|
+
unique(): ColumnBuilder<T, TN, CN, Ref>;
|
|
82
|
+
/**
|
|
83
|
+
* Add a foreign key reference to another table's column
|
|
84
|
+
* @param {() => ColumnBuilder<any>} ref - A function returning the referenced column
|
|
85
|
+
* @param {object} [options] - Reference options
|
|
86
|
+
* @param {ReferenceAction} [options.onDelete] - Action on delete
|
|
87
|
+
* @param {ReferenceAction} [options.onUpdate] - Action on update
|
|
88
|
+
* @param {string} [options.relationName] - Name for the relation
|
|
89
|
+
* @returns {ColumnBuilder<T>} The column builder for chaining
|
|
90
|
+
*/
|
|
91
|
+
references<R extends ColumnBuilder<any, string, string, any>, O extends {
|
|
92
|
+
onDelete?: ReferenceAction;
|
|
93
|
+
onUpdate?: ReferenceAction;
|
|
94
|
+
relationName?: string;
|
|
95
|
+
} = never>(ref: () => R, options?: O): ColumnBuilder<T, TN, CN, DeferredRefMeta<CN, R["__tableName"], R["__columnName"], O extends {
|
|
96
|
+
relationName: infer N extends string;
|
|
97
|
+
} ? N : undefined>>;
|
|
98
|
+
/**
|
|
99
|
+
* Build the column metadata from the builder configuration
|
|
100
|
+
* @param {string} name - The column name
|
|
101
|
+
* @returns {ColumnMetadata} The built column metadata
|
|
102
|
+
*/
|
|
103
|
+
__build(name: string): ColumnMetadata;
|
|
104
|
+
/**
|
|
105
|
+
* Get deferred reference data if this column has a foreign key reference
|
|
106
|
+
* @returns {object | null} The deferred reference data or null
|
|
107
|
+
*/
|
|
108
|
+
__getDeferredRef(): {
|
|
109
|
+
resolve: () => {
|
|
110
|
+
table: string;
|
|
111
|
+
column: string;
|
|
112
|
+
};
|
|
113
|
+
onDelete?: ReferenceAction;
|
|
114
|
+
onUpdate?: ReferenceAction;
|
|
115
|
+
relationName?: string;
|
|
116
|
+
} | null;
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
export { ColumnBuilder };
|
|
120
|
+
//# sourceMappingURL=column.d.cts.map
|