@axiosleo/orm-mysql 0.14.2 → 0.14.4
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/bin/orm-mysql.js +1 -1
- package/index.d.ts +27 -0
- package/package.json +1 -1
- package/src/builder.js +20 -0
- package/src/migration.js +25 -0
package/bin/orm-mysql.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -688,9 +688,36 @@ export declare class MigrationInterface {
|
|
|
688
688
|
*/
|
|
689
689
|
dropForeignKey(tableName: string, foreign_key: string): void;
|
|
690
690
|
|
|
691
|
+
/**
|
|
692
|
+
* insert data into table
|
|
693
|
+
* @param table
|
|
694
|
+
* @param data
|
|
695
|
+
*/
|
|
691
696
|
insertData(table: string, data: any[]): void;
|
|
692
697
|
|
|
698
|
+
/**
|
|
699
|
+
* execute raw sql
|
|
700
|
+
* @param sql
|
|
701
|
+
* @param values
|
|
702
|
+
*/
|
|
693
703
|
raw(sql: string, values: any[]): void;
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* rename table
|
|
707
|
+
* @param oldTableName
|
|
708
|
+
* @param newTableName
|
|
709
|
+
*/
|
|
710
|
+
renameTable(oldTableName: string, newTableName: string): void;
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* change column
|
|
714
|
+
* @param tableName
|
|
715
|
+
* @param columnName
|
|
716
|
+
* @param options
|
|
717
|
+
*/
|
|
718
|
+
changeColumn(tableName: string, columnName: string, options: {
|
|
719
|
+
type: FieldType,
|
|
720
|
+
} & CreateColumnOptions): void;
|
|
694
721
|
}
|
|
695
722
|
|
|
696
723
|
export type MigrateAction = 'up' | 'down' | 'UP' | 'DOWN';
|
package/package.json
CHANGED
package/src/builder.js
CHANGED
|
@@ -523,6 +523,26 @@ class ManageSQLBuilder extends Builder {
|
|
|
523
523
|
}
|
|
524
524
|
}
|
|
525
525
|
|
|
526
|
+
changeColumn(options) {
|
|
527
|
+
_validate(options, {
|
|
528
|
+
tableName: 'required|string',
|
|
529
|
+
columnName: 'required|string',
|
|
530
|
+
});
|
|
531
|
+
const columnOptions = {
|
|
532
|
+
...options.options,
|
|
533
|
+
name: options.columnName,
|
|
534
|
+
};
|
|
535
|
+
return _render('ALTER TABLE `${tableName}` MODIFY COLUMN ' + this.renderSingleColumn(columnOptions), { tableName: options.tableName });
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
renameTable(options) {
|
|
539
|
+
_validate(options, {
|
|
540
|
+
oldName: 'required|string',
|
|
541
|
+
newName: 'required|string',
|
|
542
|
+
});
|
|
543
|
+
return _render('RENAME TABLE `${oldName}` TO `${newName}`', options);
|
|
544
|
+
}
|
|
545
|
+
|
|
526
546
|
/**
|
|
527
547
|
* @param {import('./migration').ManageBuilderOptions} options
|
|
528
548
|
*/
|
package/src/migration.js
CHANGED
|
@@ -325,6 +325,31 @@ function _initMigration(file, queries = {}) {
|
|
|
325
325
|
}, ...baseAttr
|
|
326
326
|
});
|
|
327
327
|
|
|
328
|
+
Object.defineProperty(migration, 'renameTable', {
|
|
329
|
+
value: function (oldTableName, newTableName) {
|
|
330
|
+
const builder = new ManageSQLBuilder({
|
|
331
|
+
operator: 'rename',
|
|
332
|
+
target: 'table',
|
|
333
|
+
oldName: oldTableName,
|
|
334
|
+
newName: newTableName
|
|
335
|
+
});
|
|
336
|
+
queries[file].push({ sql: builder.sql, values: builder.values });
|
|
337
|
+
}, ...baseAttr
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
Object.defineProperty(migration, 'changeColumn', {
|
|
341
|
+
value: function (tableName, columnName, options) {
|
|
342
|
+
const builder = new ManageSQLBuilder({
|
|
343
|
+
operator: 'change',
|
|
344
|
+
target: 'column',
|
|
345
|
+
tableName,
|
|
346
|
+
columnName,
|
|
347
|
+
options
|
|
348
|
+
});
|
|
349
|
+
queries[file].push({ sql: builder.sql, values: builder.values });
|
|
350
|
+
}, ...baseAttr
|
|
351
|
+
});
|
|
352
|
+
|
|
328
353
|
return migration;
|
|
329
354
|
}
|
|
330
355
|
|