@axiosleo/orm-mysql 0.14.1 → 0.14.3
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 +17 -0
- package/package.json +1 -1
- package/src/builder.js +10 -2
- package/src/migration.js +12 -0
- package/docker-compose.yml +0 -18
- package/pnpm-workspace.yaml +0 -5
package/bin/orm-mysql.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -688,9 +688,26 @@ 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;
|
|
694
711
|
}
|
|
695
712
|
|
|
696
713
|
export type MigrateAction = 'up' | 'down' | 'UP' | 'DOWN';
|
package/package.json
CHANGED
package/src/builder.js
CHANGED
|
@@ -523,6 +523,14 @@ class ManageSQLBuilder extends Builder {
|
|
|
523
523
|
}
|
|
524
524
|
}
|
|
525
525
|
|
|
526
|
+
renameTable(options) {
|
|
527
|
+
_validate(options, {
|
|
528
|
+
oldName: 'required|string',
|
|
529
|
+
newName: 'required|string',
|
|
530
|
+
});
|
|
531
|
+
return _render('RENAME TABLE `${oldName}` TO `${newName}`', options);
|
|
532
|
+
}
|
|
533
|
+
|
|
526
534
|
/**
|
|
527
535
|
* @param {import('./migration').ManageBuilderOptions} options
|
|
528
536
|
*/
|
|
@@ -749,7 +757,7 @@ class ManageSQLBuilder extends Builder {
|
|
|
749
757
|
let str = `\`${options.name}\` ${type}`;
|
|
750
758
|
if (typeof options.length !== 'undefined') {
|
|
751
759
|
if (type === 'DECIMAL') {
|
|
752
|
-
str += `(${options.precision || 10}, ${options.length || 6})`;
|
|
760
|
+
str += `(${options.precision || 10}, ${options.scale || options.length || 6})`;
|
|
753
761
|
} else {
|
|
754
762
|
str += `(${options.length})`;
|
|
755
763
|
}
|
|
@@ -760,7 +768,7 @@ class ManageSQLBuilder extends Builder {
|
|
|
760
768
|
} else if (type === 'TINYINT') {
|
|
761
769
|
str += '(4)';
|
|
762
770
|
} else if (type === 'DECIMAL') {
|
|
763
|
-
str += `(${options.precision || 10}, ${options.length || 6})`;
|
|
771
|
+
str += `(${options.precision || 10}, ${options.scale || options.length || 6})`;
|
|
764
772
|
}
|
|
765
773
|
if (options.allowNull === false || options.primaryKey === true) {
|
|
766
774
|
str += ' NOT NULL';
|
package/src/migration.js
CHANGED
|
@@ -325,6 +325,18 @@ 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
|
+
|
|
328
340
|
return migration;
|
|
329
341
|
}
|
|
330
342
|
|
package/docker-compose.yml
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
version: '3'
|
|
2
|
-
# Settings and configurations that are common for all containers
|
|
3
|
-
services:
|
|
4
|
-
mysql:
|
|
5
|
-
image: 'mysql:8.0'
|
|
6
|
-
container_name: "orm-feature-tests-mysql"
|
|
7
|
-
command: mysqld --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
|
|
8
|
-
environment:
|
|
9
|
-
MYSQL_ROOT_PASSWORD: '3AQqZTfmww=Ftj'
|
|
10
|
-
MYSQL_DATABASE: 'feature_tests'
|
|
11
|
-
restart: 'always'
|
|
12
|
-
ports:
|
|
13
|
-
- "3306:3306"
|
|
14
|
-
healthcheck:
|
|
15
|
-
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-p3AQqZTfmww=Ftj"]
|
|
16
|
-
interval: 5s
|
|
17
|
-
timeout: 3s
|
|
18
|
-
retries: 10
|