fib-orm 1.4.2 → 2.0.0
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/License +1 -1
- package/README.md +53 -0
- package/lib/cli/commands/ddlFrom.d.ts +2 -0
- package/lib/cli/commands/ddlFrom.js +74 -0
- package/lib/cli/commands/dumpModel.d.ts +2 -0
- package/lib/cli/commands/dumpModel.js +106 -0
- package/lib/cli/commands/escape.d.ts +2 -0
- package/lib/cli/commands/escape.js +68 -0
- package/lib/cli/commands/spinner.d.ts +2 -0
- package/lib/cli/commands/spinner.js +36 -0
- package/lib/cli/commands/upgrade.d.ts +2 -0
- package/lib/cli/commands/upgrade.js +65 -0
- package/lib/cli/helpers/ddl.d.ts +17 -0
- package/lib/cli/helpers/ddl.js +55 -0
- package/lib/cli/helpers/package.d.ts +26 -0
- package/lib/cli/helpers/package.js +56 -0
- package/lib/cli/index.d.ts +2 -0
- package/lib/cli/index.js +18 -0
- package/lib/codepoints-map.json +762 -0
- package/lib/db-driver/Typo.d.ts +112 -0
- package/lib/db-driver/Typo.js +1 -0
- package/lib/db-driver/built-ins/base.class.d.ts +96 -0
- package/lib/db-driver/built-ins/base.class.js +186 -0
- package/lib/db-driver/built-ins/driver-dm.d.ts +18 -0
- package/lib/db-driver/built-ins/driver-dm.js +53 -0
- package/lib/db-driver/built-ins/driver-mongodb.d.ts +24 -0
- package/lib/db-driver/built-ins/driver-mongodb.js +46 -0
- package/lib/db-driver/built-ins/driver-mysql.d.ts +18 -0
- package/lib/db-driver/built-ins/driver-mysql.js +37 -0
- package/lib/db-driver/built-ins/driver-postgresql.d.ts +22 -0
- package/lib/db-driver/built-ins/driver-postgresql.js +76 -0
- package/lib/db-driver/built-ins/driver-redis.d.ts +12 -0
- package/lib/db-driver/built-ins/driver-redis.js +35 -0
- package/lib/db-driver/built-ins/driver-sqlite.d.ts +17 -0
- package/lib/db-driver/built-ins/driver-sqlite.js +34 -0
- package/lib/db-driver/index.d.ts +3 -0
- package/lib/db-driver/index.js +4 -0
- package/lib/db-driver/utils.d.ts +14 -0
- package/lib/db-driver/utils.js +187 -0
- package/lib/knex/deps/tarn/dist/PendingOperation.d.ts +12 -0
- package/lib/knex/deps/tarn/dist/PendingOperation.js +48 -0
- package/lib/knex/deps/tarn/dist/Pool.d.ts +97 -0
- package/lib/knex/deps/tarn/dist/Pool.js +516 -0
- package/lib/knex/deps/tarn/dist/PromiseInspection.d.ts +16 -0
- package/lib/knex/deps/tarn/dist/PromiseInspection.js +21 -0
- package/lib/knex/deps/tarn/dist/Resource.d.ts +9 -0
- package/lib/knex/deps/tarn/dist/Resource.js +19 -0
- package/lib/knex/deps/tarn/dist/TimeoutError.d.ts +2 -0
- package/lib/knex/deps/tarn/dist/TimeoutError.js +5 -0
- package/lib/knex/deps/tarn/dist/tarn.d.ts +3 -0
- package/lib/knex/deps/tarn/dist/tarn.js +10 -0
- package/lib/knex/deps/tarn/dist/utils.d.ts +14 -0
- package/lib/knex/deps/tarn/dist/utils.js +60 -0
- package/lib/knex/knex.d.ts +2 -0
- package/lib/knex/knex.js +3 -0
- package/lib/knex/sandbox.d.ts +4 -0
- package/lib/knex/sandbox.js +22 -0
- package/lib/orm/Adapters.d.ts +3 -0
- package/lib/orm/Adapters.js +44 -0
- package/lib/orm/AggregateFunctions.d.ts +3 -0
- package/lib/orm/AggregateFunctions.js +176 -0
- package/lib/orm/Associations/Extend.d.ts +22 -0
- package/lib/orm/Associations/Extend.js +274 -0
- package/lib/orm/Associations/Many.d.ts +17 -0
- package/lib/orm/Associations/Many.js +569 -0
- package/lib/orm/Associations/One.d.ts +16 -0
- package/lib/orm/Associations/One.js +310 -0
- package/lib/orm/Associations/_utils.d.ts +15 -0
- package/lib/orm/Associations/_utils.js +52 -0
- package/lib/orm/ChainFind.d.ts +3 -0
- package/lib/orm/ChainFind.js +327 -0
- package/lib/orm/ChainInstance.d.ts +6 -0
- package/lib/orm/ChainInstance.js +73 -0
- package/lib/orm/Debug.d.ts +2 -0
- package/lib/orm/Debug.js +17 -0
- package/lib/orm/Drivers/DB/base.d.ts +3 -0
- package/lib/orm/Drivers/DB/base.js +3 -0
- package/lib/orm/Drivers/DB/dm.d.ts +11 -0
- package/lib/orm/Drivers/DB/dm.js +23 -0
- package/lib/orm/Drivers/DB/mysql.d.ts +11 -0
- package/lib/orm/Drivers/DB/mysql.js +23 -0
- package/lib/orm/Drivers/DB/postgres.d.ts +11 -0
- package/lib/orm/Drivers/DB/postgres.js +22 -0
- package/lib/orm/Drivers/DB/sqlite3.d.ts +16 -0
- package/lib/orm/Drivers/DB/sqlite3.js +39 -0
- package/lib/orm/Drivers/DML/_ddl-sql.d.ts +3 -0
- package/lib/orm/Drivers/DML/_ddl-sql.js +51 -0
- package/lib/orm/Drivers/DML/_dml-helpers.d.ts +19 -0
- package/lib/orm/Drivers/DML/_dml-helpers.js +51 -0
- package/lib/orm/Drivers/DML/_shared.d.ts +9 -0
- package/lib/orm/Drivers/DML/_shared.js +38 -0
- package/lib/orm/Drivers/DML/_utils.d.ts +8 -0
- package/lib/orm/Drivers/DML/_utils.js +67 -0
- package/lib/orm/Drivers/DML/constants.d.ts +3 -0
- package/lib/orm/Drivers/DML/constants.js +2 -0
- package/lib/orm/Drivers/DML/dm.d.ts +2 -0
- package/lib/orm/Drivers/DML/dm.js +293 -0
- package/lib/orm/Drivers/DML/index.d.ts +4 -0
- package/lib/orm/Drivers/DML/index.js +6 -0
- package/lib/orm/Drivers/DML/mysql.d.ts +2 -0
- package/lib/orm/Drivers/DML/mysql.js +251 -0
- package/lib/orm/Drivers/DML/postgres.d.ts +3 -0
- package/lib/orm/Drivers/DML/postgres.js +276 -0
- package/lib/orm/Drivers/DML/sqlite.d.ts +2 -0
- package/lib/orm/Drivers/DML/sqlite.js +266 -0
- package/lib/orm/Error.d.ts +11 -0
- package/lib/orm/Error.js +40 -0
- package/lib/orm/Helpers.d.ts +35 -0
- package/lib/orm/Helpers.js +233 -0
- package/lib/orm/Hook.d.ts +13 -0
- package/lib/orm/Hook.js +99 -0
- package/lib/orm/Instance.d.ts +2 -0
- package/lib/orm/Instance.js +697 -0
- package/lib/orm/LazyLoad.d.ts +4 -0
- package/lib/orm/LazyLoad.js +76 -0
- package/lib/orm/Model.d.ts +7 -0
- package/lib/orm/Model.js +971 -0
- package/lib/orm/ORM.d.ts +37 -0
- package/lib/orm/ORM.js +241 -0
- package/lib/orm/Patch/fib-cache.d.ts +40 -0
- package/lib/orm/Patch/fib-cache.js +2 -0
- package/lib/orm/Patch/plugin.d.ts +4 -0
- package/lib/orm/Patch/plugin.js +13 -0
- package/lib/orm/Property.d.ts +9 -0
- package/lib/orm/Property.js +71 -0
- package/lib/orm/Settings.d.ts +42 -0
- package/lib/orm/Settings.js +119 -0
- package/lib/orm/Singleton.d.ts +5 -0
- package/lib/orm/Singleton.js +72 -0
- package/lib/orm/Typo/Adapter.d.ts +5 -0
- package/lib/orm/Typo/Adapter.js +1 -0
- package/lib/orm/Typo/DMLDriver.d.ts +210 -0
- package/lib/orm/Typo/DMLDriver.js +1 -0
- package/lib/orm/Typo/Db.d.ts +38 -0
- package/lib/orm/Typo/Db.js +1 -0
- package/lib/orm/Typo/Error.d.ts +31 -0
- package/lib/orm/Typo/Error.js +1 -0
- package/lib/orm/Typo/ORM.d.ts +233 -0
- package/lib/orm/Typo/ORM.js +3 -0
- package/lib/orm/Typo/Validators.d.ts +32 -0
- package/lib/orm/Typo/Validators.js +2 -0
- package/lib/orm/Typo/_common.d.ts +38 -0
- package/lib/orm/Typo/_common.js +1 -0
- package/lib/orm/Typo/assoc.d.ts +221 -0
- package/lib/orm/Typo/assoc.js +1 -0
- package/lib/orm/Typo/hook.d.ts +42 -0
- package/lib/orm/Typo/hook.js +1 -0
- package/lib/orm/Typo/instance.d.ts +157 -0
- package/lib/orm/Typo/instance.js +1 -0
- package/lib/orm/Typo/model.d.ts +313 -0
- package/lib/orm/Typo/model.js +6 -0
- package/lib/orm/Typo/patch.d.ts +31 -0
- package/lib/orm/Typo/patch.js +1 -0
- package/lib/orm/Typo/property.d.ts +57 -0
- package/lib/orm/Typo/property.js +1 -0
- package/lib/orm/Typo/query.d.ts +216 -0
- package/lib/orm/Typo/query.js +1 -0
- package/lib/orm/Typo/settings.d.ts +35 -0
- package/lib/orm/Typo/settings.js +5 -0
- package/lib/orm/Typo/synchronous.d.ts +47 -0
- package/lib/orm/Typo/synchronous.js +1 -0
- package/lib/orm/Utilities.d.ts +179 -0
- package/lib/orm/Utilities.js +975 -0
- package/lib/orm/Validators.d.ts +34 -0
- package/lib/orm/Validators.js +100 -0
- package/lib/orm/Where/common.d.ts +1 -0
- package/lib/orm/Where/common.js +7 -0
- package/lib/orm/Where/filterDate.d.ts +11 -0
- package/lib/orm/Where/filterDate.js +58 -0
- package/lib/orm/index.d.ts +68 -0
- package/lib/orm/index.js +157 -0
- package/lib/orm-core/callback.d.ts +12 -0
- package/lib/orm-core/callback.js +1 -0
- package/lib/orm-core/dialect.d.ts +80 -0
- package/lib/orm-core/dialect.js +1 -0
- package/lib/orm-core/error.d.ts +16 -0
- package/lib/orm-core/error.js +29 -0
- package/lib/orm-core/index.d.ts +6 -0
- package/lib/orm-core/index.js +6 -0
- package/lib/orm-core/sync.d.ts +12 -0
- package/lib/orm-core/sync.js +1 -0
- package/lib/orm-core/utils.d.ts +1 -0
- package/lib/orm-core/utils.js +5 -0
- package/lib/orm-property/Property.d.ts +78 -0
- package/lib/orm-property/Property.js +1 -0
- package/lib/orm-property/Utils.d.ts +9 -0
- package/lib/orm-property/Utils.js +13 -0
- package/lib/orm-property/customTypes.d.ts +2 -0
- package/lib/orm-property/customTypes.js +13 -0
- package/lib/orm-property/index.d.ts +10 -0
- package/lib/orm-property/index.js +22 -0
- package/lib/orm-property/transformer.d.ts +5 -0
- package/lib/orm-property/transformer.js +10 -0
- package/lib/orm-property/transformers/dm.d.ts +29 -0
- package/lib/orm-property/transformers/dm.js +237 -0
- package/lib/orm-property/transformers/index.d.ts +4 -0
- package/lib/orm-property/transformers/index.js +5 -0
- package/lib/orm-property/transformers/mysql.d.ts +102 -0
- package/lib/orm-property/transformers/mysql.js +261 -0
- package/lib/orm-property/transformers/postgresql.d.ts +54 -0
- package/lib/orm-property/transformers/postgresql.js +189 -0
- package/lib/orm-property/transformers/sqlite.d.ts +19 -0
- package/lib/orm-property/transformers/sqlite.js +171 -0
- package/lib/sql-ddl-sync/Dialects/dm.d.ts +40 -0
- package/lib/sql-ddl-sync/Dialects/dm.js +296 -0
- package/lib/sql-ddl-sync/Dialects/index.d.ts +7 -0
- package/lib/sql-ddl-sync/Dialects/index.js +7 -0
- package/lib/sql-ddl-sync/Dialects/mysql.d.ts +39 -0
- package/lib/sql-ddl-sync/Dialects/mysql.js +240 -0
- package/lib/sql-ddl-sync/Dialects/postgresql.d.ts +40 -0
- package/lib/sql-ddl-sync/Dialects/postgresql.js +286 -0
- package/lib/sql-ddl-sync/Dialects/sqlite.d.ts +44 -0
- package/lib/sql-ddl-sync/Dialects/sqlite.js +256 -0
- package/lib/sql-ddl-sync/SQL.d.ts +12 -0
- package/lib/sql-ddl-sync/SQL.js +108 -0
- package/lib/sql-ddl-sync/Typo/Collection.d.ts +13 -0
- package/lib/sql-ddl-sync/Typo/Collection.js +1 -0
- package/lib/sql-ddl-sync/Typo/DbIndex.d.ts +13 -0
- package/lib/sql-ddl-sync/Typo/DbIndex.js +1 -0
- package/lib/sql-ddl-sync/Typo/Dialect.d.ts +81 -0
- package/lib/sql-ddl-sync/Typo/Dialect.js +1 -0
- package/lib/sql-ddl-sync/Typo/Driver.d.ts +53 -0
- package/lib/sql-ddl-sync/Typo/Driver.js +1 -0
- package/lib/sql-ddl-sync/Typo/Query.d.ts +7 -0
- package/lib/sql-ddl-sync/Typo/Query.js +1 -0
- package/lib/sql-ddl-sync/Typo/SQL.d.ts +31 -0
- package/lib/sql-ddl-sync/Typo/SQL.js +1 -0
- package/lib/sql-ddl-sync/Typo/_common.d.ts +29 -0
- package/lib/sql-ddl-sync/Typo/_common.js +1 -0
- package/lib/sql-ddl-sync/Utils.d.ts +40 -0
- package/lib/sql-ddl-sync/Utils.js +217 -0
- package/lib/sql-ddl-sync/index.d.ts +87 -0
- package/lib/sql-ddl-sync/index.js +371 -0
- package/lib/sql-query/Comparators.d.ts +3 -0
- package/lib/sql-query/Comparators.js +94 -0
- package/lib/sql-query/Create.d.ts +35 -0
- package/lib/sql-query/Create.js +77 -0
- package/lib/sql-query/Dialects/dm.d.ts +3 -0
- package/lib/sql-query/Dialects/dm.js +74 -0
- package/lib/sql-query/Dialects/index.d.ts +10 -0
- package/lib/sql-query/Dialects/index.js +12 -0
- package/lib/sql-query/Dialects/mssql.d.ts +3 -0
- package/lib/sql-query/Dialects/mssql.js +73 -0
- package/lib/sql-query/Dialects/mysql.d.ts +3 -0
- package/lib/sql-query/Dialects/mysql.js +100 -0
- package/lib/sql-query/Dialects/postgresql.d.ts +3 -0
- package/lib/sql-query/Dialects/postgresql.js +76 -0
- package/lib/sql-query/Dialects/sqlite.d.ts +3 -0
- package/lib/sql-query/Dialects/sqlite.js +61 -0
- package/lib/sql-query/Helpers.d.ts +38 -0
- package/lib/sql-query/Helpers.js +259 -0
- package/lib/sql-query/Insert.d.ts +12 -0
- package/lib/sql-query/Insert.js +33 -0
- package/lib/sql-query/Query.d.ts +29 -0
- package/lib/sql-query/Query.js +119 -0
- package/lib/sql-query/Remove.d.ts +16 -0
- package/lib/sql-query/Remove.js +93 -0
- package/lib/sql-query/Select.d.ts +62 -0
- package/lib/sql-query/Select.js +533 -0
- package/lib/sql-query/Set.d.ts +4 -0
- package/lib/sql-query/Set.js +16 -0
- package/lib/sql-query/Typo/Aggregation.d.ts +32 -0
- package/lib/sql-query/Typo/Aggregation.js +1 -0
- package/lib/sql-query/Typo/Comparators.d.ts +140 -0
- package/lib/sql-query/Typo/Comparators.js +1 -0
- package/lib/sql-query/Typo/Dialect.d.ts +39 -0
- package/lib/sql-query/Typo/Dialect.js +1 -0
- package/lib/sql-query/Typo/Field.d.ts +8 -0
- package/lib/sql-query/Typo/Field.js +1 -0
- package/lib/sql-query/Typo/Helper.d.ts +4 -0
- package/lib/sql-query/Typo/Helper.js +1 -0
- package/lib/sql-query/Typo/Query-ChainBuilder.d.ts +80 -0
- package/lib/sql-query/Typo/Query-ChainBuilder.js +1 -0
- package/lib/sql-query/Typo/Query.d.ts +34 -0
- package/lib/sql-query/Typo/Query.js +16 -0
- package/lib/sql-query/Typo/Sql.d.ts +143 -0
- package/lib/sql-query/Typo/Sql.js +1 -0
- package/lib/sql-query/Typo/SubQuery.d.ts +39 -0
- package/lib/sql-query/Typo/SubQuery.js +1 -0
- package/lib/sql-query/Typo/index.d.ts +9 -0
- package/lib/sql-query/Typo/index.js +1 -0
- package/lib/sql-query/Update.d.ts +15 -0
- package/lib/sql-query/Update.js +38 -0
- package/lib/sql-query/Where.d.ts +4 -0
- package/lib/sql-query/Where.js +280 -0
- package/package.json +72 -36
- package/.travis.yml +0 -14
- package/@types/index.d.ts +0 -254
- package/@types/orm_mirror/orm.d.ts +0 -275
- package/@types/orm_mirror/sql-query.d.ts +0 -79
- package/Readme.md +0 -843
- package/lib/index.js +0 -13
- package/lib/modules/mysql.js +0 -35
- package/lib/modules/sqlite3.js +0 -27
- package/lib/patch.js +0 -271
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/// <reference types="@fibjs/types" />
|
|
2
|
+
import { FxOrmSqlDDLSync__Dialect } from "../Typo/Dialect";
|
|
3
|
+
type IDialect = FxOrmSqlDDLSync__Dialect.Dialect<Class_DbConnection>;
|
|
4
|
+
export declare const convertIndexes: IDialect['convertIndexes'];
|
|
5
|
+
export declare const hasCollectionSync: IDialect['hasCollectionSync'];
|
|
6
|
+
export declare const hasCollection: IDialect['hasCollection'];
|
|
7
|
+
export declare const addPrimaryKeySync: IDialect['addPrimaryKeySync'];
|
|
8
|
+
export declare const addPrimaryKey: IDialect['addPrimaryKey'];
|
|
9
|
+
export declare const dropPrimaryKeySync: IDialect['dropPrimaryKeySync'];
|
|
10
|
+
export declare const dropPrimaryKey: IDialect['dropPrimaryKey'];
|
|
11
|
+
export declare const addForeignKeySync: IDialect['addForeignKeySync'];
|
|
12
|
+
export declare const addForeignKey: IDialect['addForeignKey'];
|
|
13
|
+
export declare const dropForeignKeySync: IDialect['dropForeignKeySync'];
|
|
14
|
+
export declare const dropForeignKey: IDialect['dropForeignKey'];
|
|
15
|
+
export declare const getCollectionColumnsSync: IDialect['getCollectionColumnsSync'];
|
|
16
|
+
export declare const getCollectionColumns: IDialect['getCollectionColumns'];
|
|
17
|
+
export declare const getCollectionPropertiesSync: IDialect['getCollectionPropertiesSync'];
|
|
18
|
+
export declare const getCollectionProperties: IDialect['getCollectionProperties'];
|
|
19
|
+
export declare const createCollectionSync: IDialect['createCollectionSync'];
|
|
20
|
+
export declare const createCollection: IDialect['createCollection'];
|
|
21
|
+
export declare const dropCollectionSync: IDialect['dropCollectionSync'];
|
|
22
|
+
export declare const dropCollection: IDialect['dropCollection'];
|
|
23
|
+
export declare const hasCollectionColumnsSync: IDialect['hasCollectionColumnsSync'];
|
|
24
|
+
export declare const hasCollectionColumns: IDialect['hasCollectionColumns'];
|
|
25
|
+
export declare const addCollectionColumnSync: IDialect['addCollectionColumnSync'];
|
|
26
|
+
export declare const addCollectionColumn: IDialect['addCollectionColumn'];
|
|
27
|
+
export declare const renameCollectionColumnSync: IDialect['renameCollectionColumnSync'];
|
|
28
|
+
export declare const renameCollectionColumn: IDialect['renameCollectionColumn'];
|
|
29
|
+
export declare const modifyCollectionColumnSync: IDialect['modifyCollectionColumnSync'];
|
|
30
|
+
export declare const modifyCollectionColumn: IDialect['modifyCollectionColumn'];
|
|
31
|
+
export declare const dropCollectionColumnSync: IDialect['dropCollectionColumnSync'];
|
|
32
|
+
export declare const dropCollectionColumn: IDialect['dropCollectionColumn'];
|
|
33
|
+
export declare const getCollectionIndexesSync: IDialect['getCollectionIndexesSync'];
|
|
34
|
+
export declare const getCollectionIndexes: IDialect['getCollectionIndexes'];
|
|
35
|
+
export declare const addIndexSync: IDialect['addIndexSync'];
|
|
36
|
+
export declare const addIndex: IDialect['addIndex'];
|
|
37
|
+
export declare const removeIndexSync: IDialect['removeIndexSync'];
|
|
38
|
+
export declare const removeIndex: IDialect['removeIndex'];
|
|
39
|
+
export declare const toRawType: IDialect['toRawType'];
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.toRawType = exports.removeIndex = exports.removeIndexSync = exports.addIndex = exports.addIndexSync = exports.getCollectionIndexes = exports.getCollectionIndexesSync = exports.dropCollectionColumn = exports.dropCollectionColumnSync = exports.modifyCollectionColumn = exports.modifyCollectionColumnSync = exports.renameCollectionColumn = exports.renameCollectionColumnSync = exports.addCollectionColumn = exports.addCollectionColumnSync = exports.hasCollectionColumns = exports.hasCollectionColumnsSync = exports.dropCollection = exports.dropCollectionSync = exports.createCollection = exports.createCollectionSync = exports.getCollectionProperties = exports.getCollectionPropertiesSync = exports.getCollectionColumns = exports.getCollectionColumnsSync = exports.dropForeignKey = exports.dropForeignKeySync = exports.addForeignKey = exports.addForeignKeySync = exports.dropPrimaryKey = exports.dropPrimaryKeySync = exports.addPrimaryKey = exports.addPrimaryKeySync = exports.hasCollection = exports.hasCollectionSync = exports.convertIndexes = void 0;
|
|
3
|
+
const FxORMCore = require("../../orm-core/index");
|
|
4
|
+
const index_1 = require("../../orm-property/index");
|
|
5
|
+
const SQL = require("../SQL");
|
|
6
|
+
const Utils_1 = require("../Utils");
|
|
7
|
+
const Transformer = (0, index_1.transformer)('dm');
|
|
8
|
+
const convertIndexes = function (collection, index_defs) {
|
|
9
|
+
const prefix = `${collection}_`;
|
|
10
|
+
return index_defs.map(indexDef => {
|
|
11
|
+
if (indexDef.name && indexDef.name.startsWith(prefix)) {
|
|
12
|
+
return indexDef;
|
|
13
|
+
}
|
|
14
|
+
return Object.assign(Object.assign({}, indexDef), { name: `${prefix}${indexDef.name}` });
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
exports.convertIndexes = convertIndexes;
|
|
18
|
+
function fetchPrimaryKeys(dbdriver, name) {
|
|
19
|
+
const rows = dbdriver.execute((0, Utils_1.getSqlQueryDialect)('dm').escape([
|
|
20
|
+
"SELECT col.COLUMN_NAME ",
|
|
21
|
+
"FROM ALL_CONSTRAINTS con ",
|
|
22
|
+
"JOIN ALL_CONS_COLUMNS col ",
|
|
23
|
+
"ON con.CONSTRAINT_NAME = col.CONSTRAINT_NAME AND con.OWNER = col.OWNER ",
|
|
24
|
+
"WHERE con.CONSTRAINT_TYPE = 'P' ",
|
|
25
|
+
"AND con.TABLE_NAME = UPPER(?) ",
|
|
26
|
+
"AND con.OWNER = USER"
|
|
27
|
+
].join(''), [name]));
|
|
28
|
+
const set = new Set();
|
|
29
|
+
rows.forEach((row) => {
|
|
30
|
+
const col = row.COLUMN_NAME || row.column_name;
|
|
31
|
+
if (col)
|
|
32
|
+
set.add(String(col));
|
|
33
|
+
});
|
|
34
|
+
return set;
|
|
35
|
+
}
|
|
36
|
+
const hasCollectionSync = function (dbdriver, name) {
|
|
37
|
+
const rows = dbdriver.execute((0, Utils_1.getSqlQueryDialect)('dm').escape("SELECT TABLE_NAME FROM ALL_TABLES WHERE TABLE_NAME = UPPER(?) AND OWNER = USER", [name]));
|
|
38
|
+
return rows.length > 0;
|
|
39
|
+
};
|
|
40
|
+
exports.hasCollectionSync = hasCollectionSync;
|
|
41
|
+
const hasCollection = function (dbdriver, name, cb) {
|
|
42
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.hasCollectionSync)(dbdriver, name));
|
|
43
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
44
|
+
};
|
|
45
|
+
exports.hasCollection = hasCollection;
|
|
46
|
+
const addPrimaryKeySync = function (dbdriver, tableName, columnName) {
|
|
47
|
+
return dbdriver.execute((0, Utils_1.getSqlQueryDialect)('dm').escape("ALTER TABLE ?? ADD CONSTRAINT ?? PRIMARY KEY(??)", [tableName, columnName + "_PK", columnName]));
|
|
48
|
+
};
|
|
49
|
+
exports.addPrimaryKeySync = addPrimaryKeySync;
|
|
50
|
+
const addPrimaryKey = function (dbdriver, tableName, columnName, cb) {
|
|
51
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.addPrimaryKeySync)(dbdriver, tableName, columnName));
|
|
52
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
53
|
+
};
|
|
54
|
+
exports.addPrimaryKey = addPrimaryKey;
|
|
55
|
+
const dropPrimaryKeySync = function (dbdriver, tableName, columnName) {
|
|
56
|
+
return dbdriver.execute((0, Utils_1.getSqlQueryDialect)('dm').escape("ALTER TABLE ?? DROP PRIMARY KEY", [tableName]));
|
|
57
|
+
};
|
|
58
|
+
exports.dropPrimaryKeySync = dropPrimaryKeySync;
|
|
59
|
+
const dropPrimaryKey = function (dbdriver, tableName, columnName, cb) {
|
|
60
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.dropPrimaryKeySync)(dbdriver, tableName, columnName));
|
|
61
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
62
|
+
};
|
|
63
|
+
exports.dropPrimaryKey = dropPrimaryKey;
|
|
64
|
+
const addForeignKeySync = function (dbdriver, tableName, options) {
|
|
65
|
+
return dbdriver.execute((0, Utils_1.getSqlQueryDialect)('dm').escape("ALTER TABLE ?? ADD CONSTRAINT ?? FOREIGN KEY(??) REFERENCES ??(??)", [tableName, options.name + "_fk", options.name, options.references.table, options.references.column]));
|
|
66
|
+
};
|
|
67
|
+
exports.addForeignKeySync = addForeignKeySync;
|
|
68
|
+
const addForeignKey = function (dbdriver, tableName, options, cb) {
|
|
69
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.addForeignKeySync)(dbdriver, tableName, options));
|
|
70
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
71
|
+
};
|
|
72
|
+
exports.addForeignKey = addForeignKey;
|
|
73
|
+
const dropForeignKeySync = function (dbdriver, tableName, columnName) {
|
|
74
|
+
return dbdriver.execute((0, Utils_1.getSqlQueryDialect)('dm').escape("ALTER TABLE ?? DROP CONSTRAINT ??", [tableName, columnName + "_fk"]));
|
|
75
|
+
};
|
|
76
|
+
exports.dropForeignKeySync = dropForeignKeySync;
|
|
77
|
+
const dropForeignKey = function (dbdriver, tableName, columnName, cb) {
|
|
78
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.dropForeignKeySync)(dbdriver, tableName, columnName));
|
|
79
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
80
|
+
};
|
|
81
|
+
exports.dropForeignKey = dropForeignKey;
|
|
82
|
+
const getCollectionColumnsSync = function (dbdriver, name) {
|
|
83
|
+
return dbdriver.execute((0, Utils_1.getSqlQueryDialect)('dm').escape("SELECT c.*, cc.COMMENTS FROM ALL_TAB_COLUMNS c LEFT JOIN ALL_COL_COMMENTS cc ON c.OWNER = cc.OWNER AND c.TABLE_NAME = cc.TABLE_NAME AND c.COLUMN_NAME = cc.COLUMN_NAME WHERE c.TABLE_NAME = UPPER(?) AND c.OWNER = USER ORDER BY c.COLUMN_ID", [name])).map((row) => Transformer.filterRawColumns(row));
|
|
84
|
+
};
|
|
85
|
+
exports.getCollectionColumnsSync = getCollectionColumnsSync;
|
|
86
|
+
const getCollectionColumns = function (dbdriver, name, cb) {
|
|
87
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.getCollectionColumnsSync)(dbdriver, name));
|
|
88
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
89
|
+
};
|
|
90
|
+
exports.getCollectionColumns = getCollectionColumns;
|
|
91
|
+
const getCollectionPropertiesSync = function (dbdriver, name) {
|
|
92
|
+
const cols = (0, exports.getCollectionColumnsSync)(dbdriver, name);
|
|
93
|
+
const pkSet = fetchPrimaryKeys(dbdriver, name);
|
|
94
|
+
const props = {};
|
|
95
|
+
for (let i = 0; i < cols.length; i++) {
|
|
96
|
+
const colInfo = cols[i];
|
|
97
|
+
const mapsToRaw = colInfo.COLUMN_NAME || colInfo.column_name;
|
|
98
|
+
const mapsTo = mapsToRaw !== undefined ? String(mapsToRaw) : '';
|
|
99
|
+
const prop = Transformer.rawToProperty(colInfo, {
|
|
100
|
+
collection: name,
|
|
101
|
+
}).property;
|
|
102
|
+
if (mapsTo && pkSet.has(String(mapsTo))) {
|
|
103
|
+
prop.primary = true;
|
|
104
|
+
prop.key = true;
|
|
105
|
+
}
|
|
106
|
+
if (mapsTo)
|
|
107
|
+
props[mapsTo] = prop;
|
|
108
|
+
}
|
|
109
|
+
return props;
|
|
110
|
+
};
|
|
111
|
+
exports.getCollectionPropertiesSync = getCollectionPropertiesSync;
|
|
112
|
+
const getCollectionProperties = function (dbdriver, name, cb) {
|
|
113
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.getCollectionPropertiesSync)(dbdriver, name));
|
|
114
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
115
|
+
};
|
|
116
|
+
exports.getCollectionProperties = getCollectionProperties;
|
|
117
|
+
const createCollectionSync = function (dbdriver, name, columns, keys, opts) {
|
|
118
|
+
return dbdriver.execute(SQL.CREATE_TABLE({
|
|
119
|
+
name: name,
|
|
120
|
+
columns: columns,
|
|
121
|
+
keys: keys,
|
|
122
|
+
comment: opts.comment
|
|
123
|
+
}, 'dm'));
|
|
124
|
+
};
|
|
125
|
+
exports.createCollectionSync = createCollectionSync;
|
|
126
|
+
const createCollection = function (dbdriver, name, columns, keys, opts, cb) {
|
|
127
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.createCollectionSync)(dbdriver, name, columns, keys, opts));
|
|
128
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
129
|
+
};
|
|
130
|
+
exports.createCollection = createCollection;
|
|
131
|
+
const dropCollectionSync = function (dbdriver, name) {
|
|
132
|
+
return dbdriver.execute(SQL.DROP_TABLE({ name: name }, 'dm'));
|
|
133
|
+
};
|
|
134
|
+
exports.dropCollectionSync = dropCollectionSync;
|
|
135
|
+
const dropCollection = function (dbdriver, name, cb) {
|
|
136
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.dropCollectionSync)(dbdriver, name));
|
|
137
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
138
|
+
};
|
|
139
|
+
exports.dropCollection = dropCollection;
|
|
140
|
+
const hasCollectionColumnsSync = function (dbdriver, name, column) {
|
|
141
|
+
const columns = (0, Utils_1.arraify)(column);
|
|
142
|
+
let res = null, has = false;
|
|
143
|
+
try {
|
|
144
|
+
has = columns.every(columnName => (res = dbdriver.execute(SQL.CHECK_TABLE_HAS_COLUMN({
|
|
145
|
+
name: name,
|
|
146
|
+
column: columnName,
|
|
147
|
+
}, 'dm'))) && !!(res && res.length));
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
has = false;
|
|
151
|
+
}
|
|
152
|
+
return has;
|
|
153
|
+
};
|
|
154
|
+
exports.hasCollectionColumnsSync = hasCollectionColumnsSync;
|
|
155
|
+
const hasCollectionColumns = function (dbdriver, name, column, cb) {
|
|
156
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.hasCollectionColumnsSync)(dbdriver, name, column));
|
|
157
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
158
|
+
};
|
|
159
|
+
exports.hasCollectionColumns = hasCollectionColumns;
|
|
160
|
+
const addCollectionColumnSync = function (dbdriver, name, column, after_column) {
|
|
161
|
+
return dbdriver.execute(SQL.ALTER_TABLE_ADD_COLUMN({
|
|
162
|
+
name: name,
|
|
163
|
+
column: column,
|
|
164
|
+
after: after_column,
|
|
165
|
+
first: !after_column
|
|
166
|
+
}, 'dm'));
|
|
167
|
+
};
|
|
168
|
+
exports.addCollectionColumnSync = addCollectionColumnSync;
|
|
169
|
+
const addCollectionColumn = function (dbdriver, name, column, after_column, cb) {
|
|
170
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.addCollectionColumnSync)(dbdriver, name, column, after_column));
|
|
171
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
172
|
+
};
|
|
173
|
+
exports.addCollectionColumn = addCollectionColumn;
|
|
174
|
+
const renameCollectionColumnSync = function (dbdriver, name, oldColName, newColName) {
|
|
175
|
+
return dbdriver.execute(SQL.ALTER_TABLE_RENAME_COLUMN({
|
|
176
|
+
name: name,
|
|
177
|
+
oldColName: oldColName,
|
|
178
|
+
newColName: newColName
|
|
179
|
+
}, 'dm'));
|
|
180
|
+
};
|
|
181
|
+
exports.renameCollectionColumnSync = renameCollectionColumnSync;
|
|
182
|
+
const renameCollectionColumn = function (dbdriver, name, oldColName, newColName, cb) {
|
|
183
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.renameCollectionColumnSync)(dbdriver, name, oldColName, newColName));
|
|
184
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
185
|
+
};
|
|
186
|
+
exports.renameCollectionColumn = renameCollectionColumn;
|
|
187
|
+
const modifyCollectionColumnSync = function (dbdriver, name, column) {
|
|
188
|
+
return dbdriver.execute(SQL.ALTER_TABLE_MODIFY_COLUMN({
|
|
189
|
+
name: name,
|
|
190
|
+
column: column
|
|
191
|
+
}, 'dm'));
|
|
192
|
+
};
|
|
193
|
+
exports.modifyCollectionColumnSync = modifyCollectionColumnSync;
|
|
194
|
+
const modifyCollectionColumn = function (dbdriver, name, column, cb) {
|
|
195
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.modifyCollectionColumnSync)(dbdriver, name, column));
|
|
196
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
197
|
+
};
|
|
198
|
+
exports.modifyCollectionColumn = modifyCollectionColumn;
|
|
199
|
+
const dropCollectionColumnSync = function (dbdriver, name, column) {
|
|
200
|
+
return dbdriver.execute(SQL.ALTER_TABLE_DROP_COLUMN({
|
|
201
|
+
name: name,
|
|
202
|
+
column: column
|
|
203
|
+
}, 'dm'));
|
|
204
|
+
};
|
|
205
|
+
exports.dropCollectionColumnSync = dropCollectionColumnSync;
|
|
206
|
+
const dropCollectionColumn = function (dbdriver, name, column, cb) {
|
|
207
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.dropCollectionColumnSync)(dbdriver, name, column));
|
|
208
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
209
|
+
};
|
|
210
|
+
exports.dropCollectionColumn = dropCollectionColumn;
|
|
211
|
+
const getCollectionIndexesSync = function (dbdriver, name) {
|
|
212
|
+
const indexRows = dbdriver.execute((0, Utils_1.getSqlQueryDialect)('dm').escape([
|
|
213
|
+
"SELECT i.INDEX_NAME, i.UNIQUENESS, c.COLUMN_NAME ",
|
|
214
|
+
"FROM ALL_INDEXES i ",
|
|
215
|
+
"JOIN ALL_IND_COLUMNS c ",
|
|
216
|
+
"ON i.INDEX_NAME = c.INDEX_NAME AND i.TABLE_NAME = c.TABLE_NAME AND i.OWNER = c.INDEX_OWNER ",
|
|
217
|
+
"WHERE i.TABLE_NAME = UPPER(?) AND i.OWNER = USER"
|
|
218
|
+
].join(''), [name]));
|
|
219
|
+
const pkRows = dbdriver.execute((0, Utils_1.getSqlQueryDialect)('dm').escape([
|
|
220
|
+
"SELECT CONSTRAINT_NAME ",
|
|
221
|
+
"FROM ALL_CONSTRAINTS ",
|
|
222
|
+
"WHERE CONSTRAINT_TYPE = 'P' ",
|
|
223
|
+
"AND TABLE_NAME = UPPER(?) ",
|
|
224
|
+
"AND OWNER = USER"
|
|
225
|
+
].join(''), [name]));
|
|
226
|
+
const pkIndexSet = new Set();
|
|
227
|
+
pkRows.forEach((row) => {
|
|
228
|
+
const cname = row.CONSTRAINT_NAME || row.constraint_name;
|
|
229
|
+
if (cname)
|
|
230
|
+
pkIndexSet.add(String(cname));
|
|
231
|
+
});
|
|
232
|
+
return convertIndexRows(indexRows, pkIndexSet);
|
|
233
|
+
};
|
|
234
|
+
exports.getCollectionIndexesSync = getCollectionIndexesSync;
|
|
235
|
+
const getCollectionIndexes = function (dbdriver, name, cb) {
|
|
236
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.getCollectionIndexesSync)(dbdriver, name));
|
|
237
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
238
|
+
};
|
|
239
|
+
exports.getCollectionIndexes = getCollectionIndexes;
|
|
240
|
+
const addIndexSync = function (dbdriver, indexName, unique, collection, columns) {
|
|
241
|
+
return dbdriver.execute(SQL.CREATE_INDEX({
|
|
242
|
+
name: indexName,
|
|
243
|
+
unique: unique,
|
|
244
|
+
collection: collection,
|
|
245
|
+
columns: columns
|
|
246
|
+
}, 'dm'));
|
|
247
|
+
};
|
|
248
|
+
exports.addIndexSync = addIndexSync;
|
|
249
|
+
const addIndex = function (dbdriver, indexName, unique, collection, columns, cb) {
|
|
250
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.addIndexSync)(dbdriver, indexName, unique, collection, columns));
|
|
251
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
252
|
+
};
|
|
253
|
+
exports.addIndex = addIndex;
|
|
254
|
+
const removeIndexSync = function (dbdriver, collection, name) {
|
|
255
|
+
return dbdriver.execute(SQL.DROP_INDEX({
|
|
256
|
+
name: name,
|
|
257
|
+
collection: collection
|
|
258
|
+
}, 'dm'));
|
|
259
|
+
};
|
|
260
|
+
exports.removeIndexSync = removeIndexSync;
|
|
261
|
+
const removeIndex = function (dbdriver, collection, name, cb) {
|
|
262
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.removeIndexSync)(dbdriver, collection, name));
|
|
263
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
264
|
+
};
|
|
265
|
+
exports.removeIndex = removeIndex;
|
|
266
|
+
const toRawType = function (property, ctx) {
|
|
267
|
+
var _a, _b;
|
|
268
|
+
return Transformer.toStorageType(property, {
|
|
269
|
+
collection: ctx.collection,
|
|
270
|
+
customTypes: (_a = ctx.driver) === null || _a === void 0 ? void 0 : _a.customTypes,
|
|
271
|
+
escapeVal: (0, Utils_1.getSqlQueryDialect)(((_b = ctx.driver) === null || _b === void 0 ? void 0 : _b.type) || 'dm').escapeVal
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
exports.toRawType = toRawType;
|
|
275
|
+
function convertIndexRows(rows, pkIndexSet) {
|
|
276
|
+
const indexes = {};
|
|
277
|
+
for (let i = 0; i < rows.length; i++) {
|
|
278
|
+
const index_name = rows[i].INDEX_NAME || rows[i].index_name;
|
|
279
|
+
const uniqueness = rows[i].UNIQUENESS || rows[i].uniqueness;
|
|
280
|
+
const column_name = rows[i].COLUMN_NAME || rows[i].column_name;
|
|
281
|
+
if (!index_name || pkIndexSet.has(String(index_name))) {
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (/^INDEX\d+$/i.test(String(index_name))) {
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
if (!indexes.hasOwnProperty(index_name)) {
|
|
288
|
+
indexes[index_name] = {
|
|
289
|
+
columns: [],
|
|
290
|
+
unique: String(uniqueness).toUpperCase() === 'UNIQUE'
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
indexes[index_name].columns.push(column_name);
|
|
294
|
+
}
|
|
295
|
+
return indexes;
|
|
296
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="@fibjs/types" />
|
|
2
|
+
import { FxOrmSqlDDLSync__Dialect } from '../Typo/Dialect';
|
|
3
|
+
export import mysql = require('./mysql');
|
|
4
|
+
export import sqlite = require('./sqlite');
|
|
5
|
+
export import postgresql = require('./postgresql');
|
|
6
|
+
export declare const mssql: FxOrmSqlDDLSync__Dialect.Dialect<Class_DbConnection>;
|
|
7
|
+
export import dm = require('./dm');
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.mssql = void 0;
|
|
3
|
+
exports.mysql = require("./mysql");
|
|
4
|
+
exports.sqlite = require("./sqlite");
|
|
5
|
+
exports.postgresql = require("./postgresql");
|
|
6
|
+
exports.mssql = null;
|
|
7
|
+
exports.dm = require("./dm");
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/// <reference types="@fibjs/types" />
|
|
2
|
+
import { FxOrmSqlDDLSync__Dialect } from "../Typo/Dialect";
|
|
3
|
+
type IDialect = FxOrmSqlDDLSync__Dialect.Dialect<Class_MySQL>;
|
|
4
|
+
export declare const hasCollectionSync: IDialect['hasCollectionSync'];
|
|
5
|
+
export declare const hasCollection: IDialect['hasCollection'];
|
|
6
|
+
export declare const addPrimaryKeySync: IDialect['addPrimaryKeySync'];
|
|
7
|
+
export declare const addPrimaryKey: IDialect['addPrimaryKey'];
|
|
8
|
+
export declare const dropPrimaryKeySync: IDialect['dropPrimaryKeySync'];
|
|
9
|
+
export declare const dropPrimaryKey: IDialect['dropPrimaryKey'];
|
|
10
|
+
export declare const addForeignKeySync: IDialect['addForeignKeySync'];
|
|
11
|
+
export declare const addForeignKey: IDialect['addForeignKey'];
|
|
12
|
+
export declare const dropForeignKeySync: IDialect['dropForeignKeySync'];
|
|
13
|
+
export declare const dropForeignKey: IDialect['dropForeignKey'];
|
|
14
|
+
export declare const getCollectionColumnsSync: IDialect['getCollectionColumnsSync'];
|
|
15
|
+
export declare const getCollectionColumns: IDialect['getCollectionColumns'];
|
|
16
|
+
export declare const getCollectionPropertiesSync: IDialect['getCollectionPropertiesSync'];
|
|
17
|
+
export declare const getCollectionProperties: IDialect['getCollectionProperties'];
|
|
18
|
+
export declare const createCollectionSync: IDialect['createCollectionSync'];
|
|
19
|
+
export declare const createCollection: IDialect['createCollection'];
|
|
20
|
+
export declare const dropCollectionSync: IDialect['dropCollectionSync'];
|
|
21
|
+
export declare const dropCollection: IDialect['dropCollection'];
|
|
22
|
+
export declare const hasCollectionColumnsSync: IDialect['hasCollectionColumnsSync'];
|
|
23
|
+
export declare const hasCollectionColumns: IDialect['hasCollectionColumns'];
|
|
24
|
+
export declare const addCollectionColumnSync: IDialect['addCollectionColumnSync'];
|
|
25
|
+
export declare const addCollectionColumn: IDialect['addCollectionColumn'];
|
|
26
|
+
export declare const renameCollectionColumnSync: IDialect['renameCollectionColumnSync'];
|
|
27
|
+
export declare const renameCollectionColumn: IDialect['renameCollectionColumn'];
|
|
28
|
+
export declare const modifyCollectionColumnSync: IDialect['modifyCollectionColumnSync'];
|
|
29
|
+
export declare const modifyCollectionColumn: IDialect['modifyCollectionColumn'];
|
|
30
|
+
export declare const dropCollectionColumnSync: IDialect['dropCollectionColumnSync'];
|
|
31
|
+
export declare const dropCollectionColumn: IDialect['dropCollectionColumn'];
|
|
32
|
+
export declare const getCollectionIndexesSync: IDialect['getCollectionIndexesSync'];
|
|
33
|
+
export declare const getCollectionIndexes: IDialect['getCollectionIndexes'];
|
|
34
|
+
export declare const addIndexSync: IDialect['addIndexSync'];
|
|
35
|
+
export declare const addIndex: IDialect['addIndex'];
|
|
36
|
+
export declare const removeIndexSync: IDialect['removeIndexSync'];
|
|
37
|
+
export declare const removeIndex: IDialect['removeIndex'];
|
|
38
|
+
export declare const toRawType: IDialect['toRawType'];
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.toRawType = exports.removeIndex = exports.removeIndexSync = exports.addIndex = exports.addIndexSync = exports.getCollectionIndexes = exports.getCollectionIndexesSync = exports.dropCollectionColumn = exports.dropCollectionColumnSync = exports.modifyCollectionColumn = exports.modifyCollectionColumnSync = exports.renameCollectionColumn = exports.renameCollectionColumnSync = exports.addCollectionColumn = exports.addCollectionColumnSync = exports.hasCollectionColumns = exports.hasCollectionColumnsSync = exports.dropCollection = exports.dropCollectionSync = exports.createCollection = exports.createCollectionSync = exports.getCollectionProperties = exports.getCollectionPropertiesSync = exports.getCollectionColumns = exports.getCollectionColumnsSync = exports.dropForeignKey = exports.dropForeignKeySync = exports.addForeignKey = exports.addForeignKeySync = exports.dropPrimaryKey = exports.dropPrimaryKeySync = exports.addPrimaryKey = exports.addPrimaryKeySync = exports.hasCollection = exports.hasCollectionSync = void 0;
|
|
3
|
+
const FxORMCore = require("../../orm-core/index");
|
|
4
|
+
const index_1 = require("../../orm-property/index");
|
|
5
|
+
const SQL = require("../SQL");
|
|
6
|
+
const Utils_1 = require("../Utils");
|
|
7
|
+
const Transformer = (0, index_1.transformer)('mysql');
|
|
8
|
+
const hasCollectionSync = function (dbdriver, name) {
|
|
9
|
+
const rows = dbdriver.execute((0, Utils_1.getSqlQueryDialect)('mysql').escape("SHOW TABLES LIKE ?", [name]));
|
|
10
|
+
return rows.length > 0;
|
|
11
|
+
};
|
|
12
|
+
exports.hasCollectionSync = hasCollectionSync;
|
|
13
|
+
const hasCollection = function (dbdriver, name, cb) {
|
|
14
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.hasCollectionSync)(dbdriver, name));
|
|
15
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
16
|
+
};
|
|
17
|
+
exports.hasCollection = hasCollection;
|
|
18
|
+
const addPrimaryKeySync = function (dbdriver, tableName, columnName) {
|
|
19
|
+
return dbdriver.execute((0, Utils_1.getSqlQueryDialect)('mysql').escape("ALTER TABLE ?? ADD CONSTRAINT ?? PRIMARY KEY(??);", [tableName, columnName + "PK", columnName]));
|
|
20
|
+
};
|
|
21
|
+
exports.addPrimaryKeySync = addPrimaryKeySync;
|
|
22
|
+
const addPrimaryKey = function (dbdriver, tableName, columnName, cb) {
|
|
23
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.addPrimaryKeySync)(dbdriver, tableName, columnName));
|
|
24
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
25
|
+
};
|
|
26
|
+
exports.addPrimaryKey = addPrimaryKey;
|
|
27
|
+
const dropPrimaryKeySync = function (dbdriver, tableName, columnName) {
|
|
28
|
+
return dbdriver.execute((0, Utils_1.getSqlQueryDialect)('mysql').escape("ALTER TABLE ?? DROP PRIMARY KEY;", [tableName]));
|
|
29
|
+
};
|
|
30
|
+
exports.dropPrimaryKeySync = dropPrimaryKeySync;
|
|
31
|
+
const dropPrimaryKey = function (dbdriver, tableName, columnName, cb) {
|
|
32
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.dropPrimaryKeySync)(dbdriver, tableName, columnName));
|
|
33
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
34
|
+
};
|
|
35
|
+
exports.dropPrimaryKey = dropPrimaryKey;
|
|
36
|
+
const addForeignKeySync = function (dbdriver, tableName, options) {
|
|
37
|
+
return dbdriver.execute((0, Utils_1.getSqlQueryDialect)('mysql').escape("ALTER TABLE ?? ADD CONSTRAINT ?? FOREIGN KEY(??) REFERENCES ??(??)", [tableName, options.name + "_fk", options.name, options.references.table, options.references.column]));
|
|
38
|
+
};
|
|
39
|
+
exports.addForeignKeySync = addForeignKeySync;
|
|
40
|
+
const addForeignKey = function (dbdriver, tableName, options, cb) {
|
|
41
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.addForeignKeySync)(dbdriver, tableName, options));
|
|
42
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
43
|
+
};
|
|
44
|
+
exports.addForeignKey = addForeignKey;
|
|
45
|
+
const dropForeignKeySync = function (dbdriver, tableName, columnName) {
|
|
46
|
+
return dbdriver.execute((0, Utils_1.getSqlQueryDialect)('mysql').escape(`ALTER TABLE ?? DROP FOREIGN KEY ??;`, [tableName, columnName + '_fk']));
|
|
47
|
+
};
|
|
48
|
+
exports.dropForeignKeySync = dropForeignKeySync;
|
|
49
|
+
const dropForeignKey = function (dbdriver, tableName, columnName, cb) {
|
|
50
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.dropForeignKeySync)(dbdriver, tableName, columnName));
|
|
51
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
52
|
+
};
|
|
53
|
+
exports.dropForeignKey = dropForeignKey;
|
|
54
|
+
const getCollectionColumnsSync = function (dbdriver, name) {
|
|
55
|
+
return dbdriver.execute((0, Utils_1.getSqlQueryDialect)('mysql').escape("SHOW FULL COLUMNS FROM ??", [name])).map(row => Transformer.filterRawColumns(row));
|
|
56
|
+
};
|
|
57
|
+
exports.getCollectionColumnsSync = getCollectionColumnsSync;
|
|
58
|
+
const getCollectionColumns = function (dbdriver, name, cb) {
|
|
59
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.getCollectionColumnsSync)(dbdriver, name));
|
|
60
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
61
|
+
};
|
|
62
|
+
exports.getCollectionColumns = getCollectionColumns;
|
|
63
|
+
const getCollectionPropertiesSync = function (dbdriver, name) {
|
|
64
|
+
const cols = (0, exports.getCollectionColumnsSync)(dbdriver, name);
|
|
65
|
+
const props = {};
|
|
66
|
+
for (let i = 0; i < cols.length; i++) {
|
|
67
|
+
const colInfo = cols[i];
|
|
68
|
+
props[colInfo.Field] = Transformer.rawToProperty(colInfo, {
|
|
69
|
+
collection: name,
|
|
70
|
+
}).property;
|
|
71
|
+
}
|
|
72
|
+
return props;
|
|
73
|
+
};
|
|
74
|
+
exports.getCollectionPropertiesSync = getCollectionPropertiesSync;
|
|
75
|
+
const getCollectionProperties = function (dbdriver, name, cb) {
|
|
76
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.getCollectionPropertiesSync)(dbdriver, name));
|
|
77
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
78
|
+
};
|
|
79
|
+
exports.getCollectionProperties = getCollectionProperties;
|
|
80
|
+
const createCollectionSync = function (dbdriver, name, columns, keys, opts) {
|
|
81
|
+
return dbdriver.execute(SQL.CREATE_TABLE({
|
|
82
|
+
name: name,
|
|
83
|
+
columns: columns,
|
|
84
|
+
keys: keys,
|
|
85
|
+
comment: opts.comment
|
|
86
|
+
}, 'mysql'));
|
|
87
|
+
};
|
|
88
|
+
exports.createCollectionSync = createCollectionSync;
|
|
89
|
+
const createCollection = function (dbdriver, name, columns, keys, opts, cb) {
|
|
90
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.createCollectionSync)(dbdriver, name, columns, keys, opts));
|
|
91
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
92
|
+
};
|
|
93
|
+
exports.createCollection = createCollection;
|
|
94
|
+
const dropCollectionSync = function (dbdriver, name) {
|
|
95
|
+
return dbdriver.execute(SQL.DROP_TABLE({ name: name }, 'mysql'));
|
|
96
|
+
};
|
|
97
|
+
exports.dropCollectionSync = dropCollectionSync;
|
|
98
|
+
const dropCollection = function (dbdriver, name, cb) {
|
|
99
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.dropCollectionSync)(dbdriver, name));
|
|
100
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
101
|
+
};
|
|
102
|
+
exports.dropCollection = dropCollection;
|
|
103
|
+
const hasCollectionColumnsSync = function (dbdriver, name, column) {
|
|
104
|
+
const columns = (0, Utils_1.arraify)(column);
|
|
105
|
+
let res = null, has = false;
|
|
106
|
+
try {
|
|
107
|
+
has = columns.every(column => (res = dbdriver.execute(SQL.CHECK_TABLE_HAS_COLUMN({
|
|
108
|
+
name: name,
|
|
109
|
+
column: column,
|
|
110
|
+
}, 'mysql'))) && !!(res && res.length));
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
has = false;
|
|
114
|
+
}
|
|
115
|
+
return has;
|
|
116
|
+
};
|
|
117
|
+
exports.hasCollectionColumnsSync = hasCollectionColumnsSync;
|
|
118
|
+
const hasCollectionColumns = function (dbdriver, name, column, cb) {
|
|
119
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.hasCollectionColumnsSync)(dbdriver, name, column));
|
|
120
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
121
|
+
};
|
|
122
|
+
exports.hasCollectionColumns = hasCollectionColumns;
|
|
123
|
+
const addCollectionColumnSync = function (dbdriver, name, column, after_column) {
|
|
124
|
+
return dbdriver.execute(SQL.ALTER_TABLE_ADD_COLUMN({
|
|
125
|
+
name: name,
|
|
126
|
+
column: column,
|
|
127
|
+
after: after_column,
|
|
128
|
+
first: !after_column
|
|
129
|
+
}, 'mysql'));
|
|
130
|
+
};
|
|
131
|
+
exports.addCollectionColumnSync = addCollectionColumnSync;
|
|
132
|
+
const addCollectionColumn = function (dbdriver, name, column, after_column, cb) {
|
|
133
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.addCollectionColumnSync)(dbdriver, name, column, after_column));
|
|
134
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
135
|
+
};
|
|
136
|
+
exports.addCollectionColumn = addCollectionColumn;
|
|
137
|
+
const renameCollectionColumnSync = function (dbdriver, name, oldColName, newColName) {
|
|
138
|
+
throw new Error("MySQL doesn't support simple column rename");
|
|
139
|
+
};
|
|
140
|
+
exports.renameCollectionColumnSync = renameCollectionColumnSync;
|
|
141
|
+
const renameCollectionColumn = function (dbdriver, name, oldColName, newColName, cb) {
|
|
142
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.renameCollectionColumnSync)(dbdriver, name, oldColName, newColName));
|
|
143
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
144
|
+
};
|
|
145
|
+
exports.renameCollectionColumn = renameCollectionColumn;
|
|
146
|
+
const modifyCollectionColumnSync = function (dbdriver, name, column) {
|
|
147
|
+
return dbdriver.execute(SQL.ALTER_TABLE_MODIFY_COLUMN({
|
|
148
|
+
name: name,
|
|
149
|
+
column: column
|
|
150
|
+
}, 'mysql'));
|
|
151
|
+
};
|
|
152
|
+
exports.modifyCollectionColumnSync = modifyCollectionColumnSync;
|
|
153
|
+
const modifyCollectionColumn = function (dbdriver, name, column, cb) {
|
|
154
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.modifyCollectionColumnSync)(dbdriver, name, column));
|
|
155
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
156
|
+
};
|
|
157
|
+
exports.modifyCollectionColumn = modifyCollectionColumn;
|
|
158
|
+
const dropCollectionColumnSync = function (dbdriver, name, column) {
|
|
159
|
+
return dbdriver.execute(SQL.ALTER_TABLE_DROP_COLUMN({
|
|
160
|
+
name: name,
|
|
161
|
+
column: column
|
|
162
|
+
}, 'mysql'));
|
|
163
|
+
};
|
|
164
|
+
exports.dropCollectionColumnSync = dropCollectionColumnSync;
|
|
165
|
+
const dropCollectionColumn = function (dbdriver, name, column, cb) {
|
|
166
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.dropCollectionColumnSync)(dbdriver, name, column));
|
|
167
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
168
|
+
};
|
|
169
|
+
exports.dropCollectionColumn = dropCollectionColumn;
|
|
170
|
+
const getCollectionIndexesSync = function (dbdriver, name) {
|
|
171
|
+
const rows = dbdriver.execute((0, Utils_1.getSqlQueryDialect)('mysql').escape([
|
|
172
|
+
"SELECT index_name, column_name, non_unique ",
|
|
173
|
+
"FROM information_schema.statistics ",
|
|
174
|
+
"WHERE table_schema = ? AND table_name = ?",
|
|
175
|
+
].join(''), [dbdriver.currentDb, name]));
|
|
176
|
+
return convertIndexRows(rows);
|
|
177
|
+
};
|
|
178
|
+
exports.getCollectionIndexesSync = getCollectionIndexesSync;
|
|
179
|
+
const getCollectionIndexes = function (dbdriver, name, cb) {
|
|
180
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.getCollectionIndexesSync)(dbdriver, name));
|
|
181
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
182
|
+
};
|
|
183
|
+
exports.getCollectionIndexes = getCollectionIndexes;
|
|
184
|
+
const addIndexSync = function (dbdriver, indexName, unique, collection, columns) {
|
|
185
|
+
return dbdriver.execute(SQL.CREATE_INDEX({
|
|
186
|
+
name: indexName,
|
|
187
|
+
unique: unique,
|
|
188
|
+
collection: collection,
|
|
189
|
+
columns: columns
|
|
190
|
+
}, 'mysql'));
|
|
191
|
+
};
|
|
192
|
+
exports.addIndexSync = addIndexSync;
|
|
193
|
+
const addIndex = function (dbdriver, indexName, unique, collection, columns, cb) {
|
|
194
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.addIndexSync)(dbdriver, indexName, unique, collection, columns));
|
|
195
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
196
|
+
};
|
|
197
|
+
exports.addIndex = addIndex;
|
|
198
|
+
const removeIndexSync = function (dbdriver, collection, name) {
|
|
199
|
+
return dbdriver.execute(SQL.DROP_INDEX({
|
|
200
|
+
name: name,
|
|
201
|
+
collection: collection
|
|
202
|
+
}, 'mysql'));
|
|
203
|
+
};
|
|
204
|
+
exports.removeIndexSync = removeIndexSync;
|
|
205
|
+
const removeIndex = function (dbdriver, collection, name, cb) {
|
|
206
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => (0, exports.removeIndexSync)(dbdriver, collection, name));
|
|
207
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
208
|
+
};
|
|
209
|
+
exports.removeIndex = removeIndex;
|
|
210
|
+
const toRawType = function (property, ctx) {
|
|
211
|
+
var _a, _b;
|
|
212
|
+
return Transformer.toStorageType(property, {
|
|
213
|
+
collection: ctx.collection,
|
|
214
|
+
customTypes: (_a = ctx.driver) === null || _a === void 0 ? void 0 : _a.customTypes,
|
|
215
|
+
escapeVal: (0, Utils_1.getSqlQueryDialect)(((_b = ctx.driver) === null || _b === void 0 ? void 0 : _b.type) || 'mysql').escapeVal
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
exports.toRawType = toRawType;
|
|
219
|
+
function convertIndexRows(rows) {
|
|
220
|
+
const indexes = {};
|
|
221
|
+
for (let i = 0; i < rows.length; i++) {
|
|
222
|
+
const index_name = getObjectPropertyCaseInsensitive(rows[i], "index_name");
|
|
223
|
+
const non_unique = getObjectPropertyCaseInsensitive(rows[i], "non_unique");
|
|
224
|
+
const column_name = getObjectPropertyCaseInsensitive(rows[i], "column_name");
|
|
225
|
+
if (index_name == 'PRIMARY') {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (!indexes.hasOwnProperty(index_name)) {
|
|
229
|
+
indexes[index_name] = {
|
|
230
|
+
columns: [],
|
|
231
|
+
unique: (non_unique == 0)
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
indexes[index_name].columns.push(column_name);
|
|
235
|
+
}
|
|
236
|
+
return indexes;
|
|
237
|
+
}
|
|
238
|
+
function getObjectPropertyCaseInsensitive(obj, key) {
|
|
239
|
+
return obj[Object.keys(obj).find((k) => k.toLowerCase() === key.toLowerCase())];
|
|
240
|
+
}
|