@hedystia/db 2.0.6 → 2.0.8

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.
Files changed (67) hide show
  1. package/dist/cache/index.mjs +12 -0
  2. package/dist/cache/index.mjs.map +1 -0
  3. package/dist/cache/manager.mjs +156 -153
  4. package/dist/cache/manager.mjs.map +1 -1
  5. package/dist/cache/memory-store.mjs +113 -111
  6. package/dist/cache/memory-store.mjs.map +1 -1
  7. package/dist/cli/commands/migrate.cjs +78 -0
  8. package/dist/cli/commands/migrate.cjs.map +1 -0
  9. package/dist/cli/commands/migrate.mjs +83 -0
  10. package/dist/cli/commands/migrate.mjs.map +1 -0
  11. package/dist/cli/commands/migration.cjs +3 -2
  12. package/dist/cli/commands/migration.cjs.map +1 -1
  13. package/dist/cli/commands/migration.mjs +4 -3
  14. package/dist/cli/commands/migration.mjs.map +1 -1
  15. package/dist/cli.cjs +44 -5
  16. package/dist/cli.cjs.map +1 -1
  17. package/dist/cli.mjs +45 -5
  18. package/dist/cli.mjs.map +1 -1
  19. package/dist/core/database.cjs +75 -29
  20. package/dist/core/database.cjs.map +1 -1
  21. package/dist/core/database.d.cts +11 -0
  22. package/dist/core/database.d.mts +11 -0
  23. package/dist/core/database.mjs +91 -34
  24. package/dist/core/database.mjs.map +1 -1
  25. package/dist/core/repository.mjs +414 -410
  26. package/dist/core/repository.mjs.map +1 -1
  27. package/dist/drivers/driver.mjs +9 -7
  28. package/dist/drivers/driver.mjs.map +1 -1
  29. package/dist/drivers/file.mjs +315 -312
  30. package/dist/drivers/file.mjs.map +1 -1
  31. package/dist/drivers/index.mjs +15 -6
  32. package/dist/drivers/index.mjs.map +1 -1
  33. package/dist/drivers/mysql.mjs +261 -256
  34. package/dist/drivers/mysql.mjs.map +1 -1
  35. package/dist/drivers/sql-compiler.mjs +4 -1
  36. package/dist/drivers/sql-compiler.mjs.map +1 -1
  37. package/dist/drivers/sqlite.cjs +12 -1
  38. package/dist/drivers/sqlite.cjs.map +1 -1
  39. package/dist/drivers/sqlite.mjs +258 -242
  40. package/dist/drivers/sqlite.mjs.map +1 -1
  41. package/dist/errors.mjs +48 -64
  42. package/dist/errors.mjs.map +1 -1
  43. package/dist/index.mjs +21 -9
  44. package/dist/index.mjs.map +1 -1
  45. package/dist/migrations/templates.cjs +4 -3
  46. package/dist/migrations/templates.cjs.map +1 -1
  47. package/dist/migrations/templates.d.cts +3 -2
  48. package/dist/migrations/templates.d.mts +3 -2
  49. package/dist/migrations/templates.mjs +4 -3
  50. package/dist/migrations/templates.mjs.map +1 -1
  51. package/dist/schema/column.mjs +155 -157
  52. package/dist/schema/column.mjs.map +1 -1
  53. package/dist/schema/columns/index.mjs +103 -171
  54. package/dist/schema/columns/index.mjs.map +1 -1
  55. package/dist/schema/index.mjs +15 -0
  56. package/dist/schema/index.mjs.map +1 -0
  57. package/dist/schema/registry.mjs +122 -119
  58. package/dist/schema/registry.mjs.map +1 -1
  59. package/dist/schema/table.mjs +4 -1
  60. package/dist/schema/table.mjs.map +1 -1
  61. package/dist/sync/synchronizer.mjs +2 -1
  62. package/dist/sync/synchronizer.mjs.map +1 -1
  63. package/dist/utils/naming.cjs +9 -0
  64. package/dist/utils/naming.cjs.map +1 -1
  65. package/dist/utils/naming.mjs +9 -1
  66. package/dist/utils/naming.mjs.map +1 -1
  67. 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
- * Base error for all database-related errors
4
- */
5
- var DatabaseError = class extends Error {
6
- constructor(message) {
7
- super(message);
8
- this.name = "DatabaseError";
9
- }
10
- };
11
- /**
12
- * Error thrown when schema definition is invalid
13
- */
14
- var SchemaError = class extends DatabaseError {
15
- constructor(message) {
16
- super(message);
17
- this.name = "SchemaError";
18
- }
19
- };
20
- /**
21
- * Error thrown when a database driver encounters an error
22
- */
23
- var DriverError = class extends DatabaseError {
24
- constructor(message) {
25
- super(message);
26
- this.name = "DriverError";
27
- }
28
- };
29
- /**
30
- * Error thrown when a query is invalid
31
- */
32
- var QueryError = class extends DatabaseError {
33
- constructor(message) {
34
- super(message);
35
- this.name = "QueryError";
36
- }
37
- };
38
- /**
39
- * Error thrown when schema synchronization fails
40
- */
41
- var SyncError = class extends DatabaseError {
42
- constructor(message) {
43
- super(message);
44
- this.name = "SyncError";
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
- export { CacheError, DatabaseError, DriverError, MigrationError, QueryError, SchemaError, SyncError };
49
+ init_errors();
50
+ export { CacheError, DatabaseError, DriverError, MigrationError, QueryError, SchemaError, SyncError, init_errors };
67
51
 
68
52
  //# sourceMappingURL=errors.mjs.map
@@ -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":";;;;AAGA,IAAa,gBAAb,cAAmC,MAAM;CACvC,YAAY,SAAiB;AAC3B,QAAM,QAAQ;AACd,OAAK,OAAO;;;;;;AAOhB,IAAa,cAAb,cAAiC,cAAc;CAC7C,YAAY,SAAiB;AAC3B,QAAM,QAAQ;AACd,OAAK,OAAO;;;;;;AAOhB,IAAa,cAAb,cAAiC,cAAc;CAC7C,YAAY,SAAiB;AAC3B,QAAM,QAAQ;AACd,OAAK,OAAO;;;;;;AAOhB,IAAa,aAAb,cAAgC,cAAc;CAC5C,YAAY,SAAiB;AAC3B,QAAM,QAAQ;AACd,OAAK,OAAO;;;;;;AAOhB,IAAa,YAAb,cAA+B,cAAc;CAC3C,YAAY,SAAiB;AAC3B,QAAM,QAAQ;AACd,OAAK,OAAO;;;;;;AAOhB,IAAa,iBAAb,cAAoC,cAAc;CAChD,YAAY,SAAiB;AAC3B,QAAM,QAAQ;AACd,OAAK,OAAO;;;;;;AAOhB,IAAa,aAAb,cAAgC,cAAc;CAC5C,YAAY,SAAiB;AAC3B,QAAM,QAAQ;AACd,OAAK,OAAO"}
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 { 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, array, 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";
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 };
@@ -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":";;;;;;;;;;;;;;iBAaoD;gBACuC;AAsE3F,IAAA,cAAe"}
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"}
@@ -1,13 +1,14 @@
1
1
  //#region src/migrations/templates.ts
2
2
  /**
3
3
  * Generate a migration file template
4
- * @param {string} name - Migration name
4
+ * @param {string} id - Migration id (e.g. "20260320095958_sessions")
5
+ * @param {string} varName - Variable name for the export (camelCase)
5
6
  * @returns {string} Migration file content
6
7
  */
7
- function generateMigrationTemplate(name) {
8
+ function generateMigrationTemplate(id, varName) {
8
9
  return `import { migration } from "@hedystia/db";
9
10
 
10
- export default migration("${name}", {
11
+ export const ${varName} = migration("${id}", {
11
12
  async up({ schema, sql }) {
12
13
  // Add your migration logic here
13
14
  },
@@ -1 +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"}
1
+ {"version":3,"file":"templates.cjs","names":[],"sources":["../../src/migrations/templates.ts"],"sourcesContent":["/**\n * Generate a migration file template\n * @param {string} id - Migration id (e.g. \"20260320095958_sessions\")\n * @param {string} varName - Variable name for the export (camelCase)\n * @returns {string} Migration file content\n */\nexport function generateMigrationTemplate(id: string, varName: string): string {\n return `import { migration } from \"@hedystia/db\";\n\nexport const ${varName} = migration(\"${id}\", {\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":";;;;;;;AAMA,SAAgB,0BAA0B,IAAY,SAAyB;AAC7E,QAAO;;eAEM,QAAQ,gBAAgB,GAAG;;;;;;;;;;;;;;;AAgB1C,SAAgB,uBAAuB,MAAsB;AAC3D,QAAO;;eAEM,KAAK,YAAY,KAAK"}
@@ -1,10 +1,11 @@
1
1
  //#region src/migrations/templates.d.ts
2
2
  /**
3
3
  * Generate a migration file template
4
- * @param {string} name - Migration name
4
+ * @param {string} id - Migration id (e.g. "20260320095958_sessions")
5
+ * @param {string} varName - Variable name for the export (camelCase)
5
6
  * @returns {string} Migration file content
6
7
  */
7
- declare function generateMigrationTemplate(name: string): string;
8
+ declare function generateMigrationTemplate(id: string, varName: string): string;
8
9
  /**
9
10
  * Generate a schema file template
10
11
  * @param {string} name - Table name
@@ -1,10 +1,11 @@
1
1
  //#region src/migrations/templates.d.ts
2
2
  /**
3
3
  * Generate a migration file template
4
- * @param {string} name - Migration name
4
+ * @param {string} id - Migration id (e.g. "20260320095958_sessions")
5
+ * @param {string} varName - Variable name for the export (camelCase)
5
6
  * @returns {string} Migration file content
6
7
  */
7
- declare function generateMigrationTemplate(name: string): string;
8
+ declare function generateMigrationTemplate(id: string, varName: string): string;
8
9
  /**
9
10
  * Generate a schema file template
10
11
  * @param {string} name - Table name
@@ -2,13 +2,14 @@ import { __esmMin } from "../_virtual/_rolldown/runtime.mjs";
2
2
  //#region src/migrations/templates.ts
3
3
  /**
4
4
  * Generate a migration file template
5
- * @param {string} name - Migration name
5
+ * @param {string} id - Migration id (e.g. "20260320095958_sessions")
6
+ * @param {string} varName - Variable name for the export (camelCase)
6
7
  * @returns {string} Migration file content
7
8
  */
8
- function generateMigrationTemplate(name) {
9
+ function generateMigrationTemplate(id, varName) {
9
10
  return `import { migration } from "@hedystia/db";
10
11
 
11
- export default migration("${name}", {
12
+ export const ${varName} = migration("${id}", {
12
13
  async up({ schema, sql }) {
13
14
  // Add your migration logic here
14
15
  },
@@ -1 +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"}
1
+ {"version":3,"file":"templates.mjs","names":[],"sources":["../../src/migrations/templates.ts"],"sourcesContent":["/**\n * Generate a migration file template\n * @param {string} id - Migration id (e.g. \"20260320095958_sessions\")\n * @param {string} varName - Variable name for the export (camelCase)\n * @returns {string} Migration file content\n */\nexport function generateMigrationTemplate(id: string, varName: string): string {\n return `import { migration } from \"@hedystia/db\";\n\nexport const ${varName} = migration(\"${id}\", {\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":";;;;;;;;AAMA,SAAgB,0BAA0B,IAAY,SAAyB;AAC7E,QAAO;;eAEM,QAAQ,gBAAgB,GAAG;;;;;;;;;;;;;;;AAgB1C,SAAgB,uBAAuB,MAAsB;AAC3D,QAAO;;eAEM,KAAK,YAAY,KAAK"}
@@ -1,161 +1,159 @@
1
+ import { __esmMin } from "../_virtual/_rolldown/runtime.mjs";
1
2
  //#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>) | ColumnBuilder<any>} ref - A column reference or a function returning one
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 = typeof ref === "function" ? ref() : 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
- };
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
- export { ColumnBuilder };
156
+ init_column();
157
+ export { ColumnBuilder, init_column };
160
158
 
161
159
  //# sourceMappingURL=column.mjs.map