sqlmorpheus 0.1.0 → 0.1.1

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/index.d.mts CHANGED
@@ -102,9 +102,9 @@ declare function DbTable<T extends BackendTable>(tableName: string, primaryKey?:
102
102
 
103
103
  declare function ForeignKey<TOther extends BackendTable>(toTable: Class<TOther>, toColumn: keyof TOther, onDelete?: ForeignKeyActions, onUpdate?: ForeignKeyActions): (_: undefined, context: any) => void;
104
104
 
105
- declare async function prepareMigration(db: DatabaseAccess, dbInstructions: DatabaseInstructions, overwriteExisting?: boolean): Promise<void>;
106
- declare async function runPreparedMigrations(db: DatabaseAccess, dbInstructions: DatabaseInstructions);
107
- declare async function prepareAndRunMigration(db: DatabaseAccess, dbInstructions: DatabaseInstructions, overwriteExisting?: boolean): Promise<void>;
108
- declare async function rollback(db: DatabaseAccess, dbInstructions: DatabaseInstructions, toVersion: number);
105
+ declare function prepareMigration(db: DatabaseAccess, instructions: DatabaseInstructions, overwriteExisting?: boolean): Promise<void>;
106
+ declare function runPreparedMigrations(db: DatabaseAccess, instructions: DatabaseInstructions): Promise<void>;
107
+ declare function prepareAndRunMigration(db: DatabaseAccess, instructions: DatabaseInstructions, overwriteExisting?: boolean): Promise<void>;
108
+ declare function rollback(db: DatabaseAccess, instructions: DatabaseInstructions, toVersion: number): Promise<void>;
109
109
 
110
110
  export { DbTable, ForeignKey, prepareAndRunMigration, prepareMigration, rollback, runPreparedMigrations };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { DatabaseAccess } from "./lib/typings/DatabaseAccess";
2
2
  import DatabaseInstructions from "./lib/typings/DatabaseInstructions";
3
+ import DbTable from "./lib/tableInfo/decorators/DbTable";
4
+ import ForeignKey from "./lib/tableInfo/decorators/ForeignKey";
3
5
  export declare function prepareMigration(db: DatabaseAccess, instructions: DatabaseInstructions, overwriteExisting?: boolean): Promise<void>;
4
6
  export declare function runPreparedMigrations(db: DatabaseAccess, instructions: DatabaseInstructions): Promise<void>;
5
7
  export declare function prepareAndRunMigration(db: DatabaseAccess, instructions: DatabaseInstructions, overwriteExisting?: boolean): Promise<void>;
6
8
  export declare function rollback(db: DatabaseAccess, instructions: DatabaseInstructions, toVersion: number): Promise<void>;
9
+ export { DbTable, ForeignKey };
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ForeignKey = exports.DbTable = void 0;
6
7
  exports.prepareMigration = prepareMigration;
7
8
  exports.runPreparedMigrations = runPreparedMigrations;
8
9
  exports.prepareAndRunMigration = prepareAndRunMigration;
@@ -10,6 +11,10 @@ exports.rollback = rollback;
10
11
  const MigrationManager_1 = require("./lib/MigrationManager");
11
12
  const MigrationHistoryManager_1 = __importDefault(require("./lib/MigrationHistoryManager"));
12
13
  const Logger_1 = require("./lib/Logger");
14
+ const DbTable_1 = __importDefault(require("./lib/tableInfo/decorators/DbTable"));
15
+ exports.DbTable = DbTable_1.default;
16
+ const ForeignKey_1 = __importDefault(require("./lib/tableInfo/decorators/ForeignKey"));
17
+ exports.ForeignKey = ForeignKey_1.default;
13
18
  async function prepareMigration(db, instructions, overwriteExisting) {
14
19
  Logger_1.Logger.setMode(instructions.loggerMode);
15
20
  const mm = new MigrationManager_1.MigrationManager(db, instructions);
package/dist/index.mjs CHANGED
@@ -836,6 +836,38 @@ ${foreignKeyOnQuery}`;
836
836
  }
837
837
  };
838
838
 
839
+ // src/lib/tableInfo/decorators/DbTable.ts
840
+ function DbTable(tableName, primaryKey) {
841
+ return (table, context) => {
842
+ Object.defineProperty(table, "name", { value: tableName, writable: false });
843
+ const tableInfo = getTableInfoFromMetadata(context.metadata);
844
+ tableInfo.primaryKey = primaryKey?.toString();
845
+ if (tableInfo.foreignKeys) {
846
+ for (const foreignKey of tableInfo.foreignKeys) {
847
+ foreignKey.fromTable = tableName;
848
+ }
849
+ }
850
+ };
851
+ }
852
+
853
+ // src/lib/tableInfo/decorators/ForeignKey.ts
854
+ import "polyfill-symbol-metadata";
855
+ function ForeignKey(toTable, toColumn, onDelete, onUpdate) {
856
+ return (_, context) => {
857
+ const metadata = getTableInfoFromMetadata(context.metadata);
858
+ if (!metadata.foreignKeys)
859
+ metadata.foreignKeys = [];
860
+ metadata.foreignKeys.push({
861
+ fromTable: "",
862
+ fromColumn: context.name,
863
+ toTable: toTable.name,
864
+ toColumn: toColumn.toString(),
865
+ onDelete,
866
+ onUpdate
867
+ });
868
+ };
869
+ }
870
+
839
871
  // src/index.ts
840
872
  async function prepareMigration(db, instructions, overwriteExisting) {
841
873
  Logger.setMode(instructions.loggerMode);
@@ -877,6 +909,8 @@ async function rollback(db, instructions, toVersion) {
877
909
  migrationHistoryManager.setLastHistoryVersion(toVersion);
878
910
  }
879
911
  export {
912
+ DbTable,
913
+ ForeignKey,
880
914
  prepareAndRunMigration,
881
915
  prepareMigration,
882
916
  rollback,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sqlmorpheus",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "author": "JodliDev",
5
5
  "keywords": [],
6
6
  "license": "MIT",