fib-orm 1.4.2 → 2.1.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 +75 -0
- package/lib/cli/commands/dumpModel.d.ts +2 -0
- package/lib/cli/commands/dumpModel.js +107 -0
- package/lib/cli/commands/escape.d.ts +2 -0
- package/lib/cli/commands/escape.js +69 -0
- package/lib/cli/commands/spinner.d.ts +2 -0
- package/lib/cli/commands/spinner.js +37 -0
- package/lib/cli/commands/upgrade.d.ts +2 -0
- package/lib/cli/commands/upgrade.js +66 -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 +25 -0
- package/lib/cli/helpers/package.js +56 -0
- package/lib/cli/index.d.ts +2 -0
- package/lib/cli/index.js +19 -0
- package/lib/codepoints-map.json +762 -0
- package/lib/db-driver/Typo.d.ts +111 -0
- package/lib/db-driver/Typo.js +2 -0
- package/lib/db-driver/built-ins/base.class.d.ts +91 -0
- package/lib/db-driver/built-ins/base.class.js +187 -0
- package/lib/db-driver/built-ins/driver-dm.d.ts +17 -0
- package/lib/db-driver/built-ins/driver-dm.js +54 -0
- package/lib/db-driver/built-ins/driver-mongodb.d.ts +23 -0
- package/lib/db-driver/built-ins/driver-mongodb.js +47 -0
- package/lib/db-driver/built-ins/driver-mysql.d.ts +17 -0
- package/lib/db-driver/built-ins/driver-mysql.js +38 -0
- package/lib/db-driver/built-ins/driver-postgresql.d.ts +21 -0
- package/lib/db-driver/built-ins/driver-postgresql.js +77 -0
- package/lib/db-driver/built-ins/driver-redis.d.ts +11 -0
- package/lib/db-driver/built-ins/driver-redis.js +36 -0
- package/lib/db-driver/built-ins/driver-sqlite.d.ts +16 -0
- package/lib/db-driver/built-ins/driver-sqlite.js +35 -0
- package/lib/db-driver/index.d.ts +3 -0
- package/lib/db-driver/index.js +5 -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 +4 -0
- package/lib/knex/sandbox.d.ts +4 -0
- package/lib/knex/sandbox.js +23 -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 +177 -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 +16 -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 +14 -0
- package/lib/orm/Associations/_utils.js +53 -0
- package/lib/orm/ChainFind.d.ts +3 -0
- package/lib/orm/ChainFind.js +328 -0
- package/lib/orm/ChainInstance.d.ts +6 -0
- package/lib/orm/ChainInstance.js +74 -0
- package/lib/orm/Debug.d.ts +2 -0
- package/lib/orm/Debug.js +17 -0
- package/lib/orm/Drivers/DB/base.d.ts +2 -0
- package/lib/orm/Drivers/DB/base.js +4 -0
- package/lib/orm/Drivers/DB/dm.d.ts +9 -0
- package/lib/orm/Drivers/DB/dm.js +24 -0
- package/lib/orm/Drivers/DB/mysql.d.ts +9 -0
- package/lib/orm/Drivers/DB/mysql.js +24 -0
- package/lib/orm/Drivers/DB/postgres.d.ts +9 -0
- package/lib/orm/Drivers/DB/postgres.js +23 -0
- package/lib/orm/Drivers/DB/sqlite3.d.ts +14 -0
- package/lib/orm/Drivers/DB/sqlite3.js +40 -0
- package/lib/orm/Drivers/DML/_ddl-sql.d.ts +3 -0
- package/lib/orm/Drivers/DML/_ddl-sql.js +52 -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 +39 -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 +3 -0
- package/lib/orm/Drivers/DML/dm.d.ts +2 -0
- package/lib/orm/Drivers/DML/dm.js +294 -0
- package/lib/orm/Drivers/DML/index.d.ts +4 -0
- package/lib/orm/Drivers/DML/index.js +7 -0
- package/lib/orm/Drivers/DML/mysql.d.ts +2 -0
- package/lib/orm/Drivers/DML/mysql.js +252 -0
- package/lib/orm/Drivers/DML/postgres.d.ts +2 -0
- package/lib/orm/Drivers/DML/postgres.js +277 -0
- package/lib/orm/Drivers/DML/sqlite.d.ts +2 -0
- package/lib/orm/Drivers/DML/sqlite.js +267 -0
- package/lib/orm/Error.d.ts +11 -0
- package/lib/orm/Error.js +41 -0
- package/lib/orm/Helpers.d.ts +35 -0
- package/lib/orm/Helpers.js +234 -0
- package/lib/orm/Hook.d.ts +13 -0
- package/lib/orm/Hook.js +100 -0
- package/lib/orm/Instance.d.ts +2 -0
- package/lib/orm/Instance.js +698 -0
- package/lib/orm/LazyLoad.d.ts +4 -0
- package/lib/orm/LazyLoad.js +76 -0
- package/lib/orm/Model.d.ts +6 -0
- package/lib/orm/Model.js +974 -0
- package/lib/orm/ORM.d.ts +37 -0
- package/lib/orm/ORM.js +242 -0
- package/lib/orm/Patch/fib-cache.d.ts +39 -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 +14 -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 +120 -0
- package/lib/orm/Singleton.d.ts +5 -0
- package/lib/orm/Singleton.js +73 -0
- package/lib/orm/Typo/Adapter.d.ts +5 -0
- package/lib/orm/Typo/Adapter.js +2 -0
- package/lib/orm/Typo/DMLDriver.d.ts +209 -0
- package/lib/orm/Typo/DMLDriver.js +2 -0
- package/lib/orm/Typo/Db.d.ts +35 -0
- package/lib/orm/Typo/Db.js +2 -0
- package/lib/orm/Typo/Error.d.ts +29 -0
- package/lib/orm/Typo/Error.js +2 -0
- package/lib/orm/Typo/ORM.d.ts +231 -0
- package/lib/orm/Typo/ORM.js +4 -0
- package/lib/orm/Typo/Validators.d.ts +31 -0
- package/lib/orm/Typo/Validators.js +3 -0
- package/lib/orm/Typo/_common.d.ts +37 -0
- package/lib/orm/Typo/_common.js +2 -0
- package/lib/orm/Typo/assoc.d.ts +221 -0
- package/lib/orm/Typo/assoc.js +2 -0
- package/lib/orm/Typo/hook.d.ts +42 -0
- package/lib/orm/Typo/hook.js +2 -0
- package/lib/orm/Typo/instance.d.ts +156 -0
- package/lib/orm/Typo/instance.js +2 -0
- package/lib/orm/Typo/model.d.ts +311 -0
- package/lib/orm/Typo/model.js +7 -0
- package/lib/orm/Typo/patch.d.ts +31 -0
- package/lib/orm/Typo/patch.js +2 -0
- package/lib/orm/Typo/property.d.ts +57 -0
- package/lib/orm/Typo/property.js +2 -0
- package/lib/orm/Typo/query.d.ts +216 -0
- package/lib/orm/Typo/query.js +2 -0
- package/lib/orm/Typo/settings.d.ts +35 -0
- package/lib/orm/Typo/settings.js +6 -0
- package/lib/orm/Typo/synchronous.d.ts +47 -0
- package/lib/orm/Typo/synchronous.js +2 -0
- package/lib/orm/Utilities.d.ts +178 -0
- package/lib/orm/Utilities.js +975 -0
- package/lib/orm/Validators.d.ts +33 -0
- package/lib/orm/Validators.js +101 -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 +67 -0
- package/lib/orm/index.js +158 -0
- package/lib/orm-core/callback.d.ts +12 -0
- package/lib/orm-core/callback.js +2 -0
- package/lib/orm-core/dialect.d.ts +80 -0
- package/lib/orm-core/dialect.js +2 -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 +7 -0
- package/lib/orm-core/sync.d.ts +12 -0
- package/lib/orm-core/sync.js +2 -0
- package/lib/orm-core/utils.d.ts +1 -0
- package/lib/orm-core/utils.js +6 -0
- package/lib/orm-property/Property.d.ts +78 -0
- package/lib/orm-property/Property.js +2 -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 +23 -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 +238 -0
- package/lib/orm-property/transformers/index.d.ts +4 -0
- package/lib/orm-property/transformers/index.js +6 -0
- package/lib/orm-property/transformers/mysql.d.ts +101 -0
- package/lib/orm-property/transformers/mysql.js +262 -0
- package/lib/orm-property/transformers/postgresql.d.ts +54 -0
- package/lib/orm-property/transformers/postgresql.js +190 -0
- package/lib/orm-property/transformers/sqlite.d.ts +19 -0
- package/lib/orm-property/transformers/sqlite.js +172 -0
- package/lib/sql-ddl-sync/Dialects/dm.d.ts +39 -0
- package/lib/sql-ddl-sync/Dialects/dm.js +297 -0
- package/lib/sql-ddl-sync/Dialects/index.d.ts +6 -0
- package/lib/sql-ddl-sync/Dialects/index.js +8 -0
- package/lib/sql-ddl-sync/Dialects/mysql.d.ts +38 -0
- package/lib/sql-ddl-sync/Dialects/mysql.js +241 -0
- package/lib/sql-ddl-sync/Dialects/postgresql.d.ts +39 -0
- package/lib/sql-ddl-sync/Dialects/postgresql.js +287 -0
- package/lib/sql-ddl-sync/Dialects/sqlite.d.ts +43 -0
- package/lib/sql-ddl-sync/Dialects/sqlite.js +257 -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 +2 -0
- package/lib/sql-ddl-sync/Typo/DbIndex.d.ts +13 -0
- package/lib/sql-ddl-sync/Typo/DbIndex.js +2 -0
- package/lib/sql-ddl-sync/Typo/Dialect.d.ts +81 -0
- package/lib/sql-ddl-sync/Typo/Dialect.js +2 -0
- package/lib/sql-ddl-sync/Typo/Driver.d.ts +53 -0
- package/lib/sql-ddl-sync/Typo/Driver.js +2 -0
- package/lib/sql-ddl-sync/Typo/Query.d.ts +7 -0
- package/lib/sql-ddl-sync/Typo/Query.js +2 -0
- package/lib/sql-ddl-sync/Typo/SQL.d.ts +31 -0
- package/lib/sql-ddl-sync/Typo/SQL.js +2 -0
- package/lib/sql-ddl-sync/Typo/_common.d.ts +29 -0
- package/lib/sql-ddl-sync/Typo/_common.js +2 -0
- package/lib/sql-ddl-sync/Utils.d.ts +39 -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 +372 -0
- package/lib/sql-query/Comparators.d.ts +3 -0
- package/lib/sql-query/Comparators.js +95 -0
- package/lib/sql-query/Create.d.ts +35 -0
- package/lib/sql-query/Create.js +78 -0
- package/lib/sql-query/Dialects/dm.d.ts +3 -0
- package/lib/sql-query/Dialects/dm.js +75 -0
- package/lib/sql-query/Dialects/index.d.ts +10 -0
- package/lib/sql-query/Dialects/index.js +13 -0
- package/lib/sql-query/Dialects/mssql.d.ts +3 -0
- package/lib/sql-query/Dialects/mssql.js +74 -0
- package/lib/sql-query/Dialects/mysql.d.ts +3 -0
- package/lib/sql-query/Dialects/mysql.js +101 -0
- package/lib/sql-query/Dialects/postgresql.d.ts +3 -0
- package/lib/sql-query/Dialects/postgresql.js +77 -0
- package/lib/sql-query/Dialects/sqlite.d.ts +3 -0
- package/lib/sql-query/Dialects/sqlite.js +62 -0
- package/lib/sql-query/Helpers.d.ts +37 -0
- package/lib/sql-query/Helpers.js +260 -0
- package/lib/sql-query/Insert.d.ts +12 -0
- package/lib/sql-query/Insert.js +34 -0
- package/lib/sql-query/Query.d.ts +28 -0
- package/lib/sql-query/Query.js +120 -0
- package/lib/sql-query/Remove.d.ts +16 -0
- package/lib/sql-query/Remove.js +94 -0
- package/lib/sql-query/Select.d.ts +62 -0
- package/lib/sql-query/Select.js +534 -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 +2 -0
- package/lib/sql-query/Typo/Comparators.d.ts +140 -0
- package/lib/sql-query/Typo/Comparators.js +2 -0
- package/lib/sql-query/Typo/Dialect.d.ts +39 -0
- package/lib/sql-query/Typo/Dialect.js +2 -0
- package/lib/sql-query/Typo/Field.d.ts +8 -0
- package/lib/sql-query/Typo/Field.js +2 -0
- package/lib/sql-query/Typo/Helper.d.ts +4 -0
- package/lib/sql-query/Typo/Helper.js +2 -0
- package/lib/sql-query/Typo/Query-ChainBuilder.d.ts +80 -0
- package/lib/sql-query/Typo/Query-ChainBuilder.js +2 -0
- package/lib/sql-query/Typo/Query.d.ts +34 -0
- package/lib/sql-query/Typo/Query.js +17 -0
- package/lib/sql-query/Typo/Sql.d.ts +143 -0
- package/lib/sql-query/Typo/Sql.js +2 -0
- package/lib/sql-query/Typo/SubQuery.d.ts +39 -0
- package/lib/sql-query/Typo/SubQuery.js +2 -0
- package/lib/sql-query/Typo/index.d.ts +9 -0
- package/lib/sql-query/Typo/index.js +2 -0
- package/lib/sql-query/Update.d.ts +15 -0
- package/lib/sql-query/Update.js +39 -0
- package/lib/sql-query/Where.d.ts +4 -0
- package/lib/sql-query/Where.js +280 -0
- package/package.json +71 -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,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CREATE_TABLE = CREATE_TABLE;
|
|
4
|
+
exports.ALTER_TABLE_COMMENT = ALTER_TABLE_COMMENT;
|
|
5
|
+
exports.DROP_TABLE = DROP_TABLE;
|
|
6
|
+
exports.CHECK_TABLE_HAS_COLUMN = CHECK_TABLE_HAS_COLUMN;
|
|
7
|
+
exports.ALTER_TABLE_ADD_COLUMN = ALTER_TABLE_ADD_COLUMN;
|
|
8
|
+
exports.ALTER_TABLE_RENAME_COLUMN = ALTER_TABLE_RENAME_COLUMN;
|
|
9
|
+
exports.ALTER_TABLE_MODIFY_COLUMN = ALTER_TABLE_MODIFY_COLUMN;
|
|
10
|
+
exports.ALTER_TABLE_DROP_COLUMN = ALTER_TABLE_DROP_COLUMN;
|
|
11
|
+
exports.CREATE_INDEX = CREATE_INDEX;
|
|
12
|
+
exports.DROP_INDEX = DROP_INDEX;
|
|
13
|
+
const Utils_1 = require("./Utils");
|
|
14
|
+
function CREATE_TABLE(options, db_type) {
|
|
15
|
+
let sql = "CREATE TABLE " + (0, Utils_1.getSqlQueryDialect)(db_type).escapeId(options.name) + " (" + options.columns.join(", ");
|
|
16
|
+
if (options.keys && options.keys.length > 0) {
|
|
17
|
+
sql += ", PRIMARY KEY (" + options.keys.map(function (val) {
|
|
18
|
+
return (0, Utils_1.getSqlQueryDialect)(db_type).escapeId(val);
|
|
19
|
+
}).join(", ") + ")";
|
|
20
|
+
}
|
|
21
|
+
sql += ")";
|
|
22
|
+
if (options.comment && db_type === 'mysql') {
|
|
23
|
+
sql += ` COMMENT ${(0, Utils_1.getSqlQueryDialect)(db_type).escapeVal(options.comment)}`;
|
|
24
|
+
}
|
|
25
|
+
return sql;
|
|
26
|
+
}
|
|
27
|
+
;
|
|
28
|
+
function ALTER_TABLE_COMMENT(db_type, table, comment) {
|
|
29
|
+
switch (db_type) {
|
|
30
|
+
case 'mysql': {
|
|
31
|
+
return `ALTER TABLE ${(0, Utils_1.getSqlQueryDialect)(db_type).escapeId(table)} COMMENT ${(0, Utils_1.getSqlQueryDialect)(db_type).escapeVal(comment || '')}`;
|
|
32
|
+
}
|
|
33
|
+
case 'psql': {
|
|
34
|
+
return `COMMENT ON TABLE ${(0, Utils_1.getSqlQueryDialect)(db_type).escapeId(table)} IS ${comment ? (0, Utils_1.getSqlQueryDialect)(db_type).escapeVal(comment) : 'null'}`;
|
|
35
|
+
}
|
|
36
|
+
case 'dm': {
|
|
37
|
+
return `COMMENT ON TABLE ${(0, Utils_1.getSqlQueryDialect)(db_type).escapeId(table)} IS ${comment ? (0, Utils_1.getSqlQueryDialect)(db_type).escapeVal(comment) : 'null'}`;
|
|
38
|
+
}
|
|
39
|
+
case 'sqlite':
|
|
40
|
+
default: {
|
|
41
|
+
throw new Error(`[SQL] ALTER_TABLE_COMMENT: not supported db_type: ${db_type}!`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function DROP_TABLE(options, db_type) {
|
|
46
|
+
const sql = "DROP TABLE " + (0, Utils_1.getSqlQueryDialect)(db_type).escapeId(options.name);
|
|
47
|
+
return sql;
|
|
48
|
+
}
|
|
49
|
+
;
|
|
50
|
+
function CHECK_TABLE_HAS_COLUMN(options, db_type) {
|
|
51
|
+
const eid = (0, Utils_1.getSqlQueryDialect)(db_type).escapeId;
|
|
52
|
+
const evalue = (0, Utils_1.getSqlQueryDialect)(db_type).escapeVal;
|
|
53
|
+
const sql = [
|
|
54
|
+
db_type === 'mysql'
|
|
55
|
+
? `SHOW FULL COLUMNS FROM ${eid(options.name)} LIKE ${evalue(options.column)}`
|
|
56
|
+
: db_type === 'dm'
|
|
57
|
+
? `SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = UPPER(${evalue(options.name)}) AND COLUMN_NAME = UPPER(${evalue(options.column)}) AND OWNER = USER`
|
|
58
|
+
: `SHOW COLUMNS FROM ${eid(options.name)} LIKE ${evalue(options.column)}`
|
|
59
|
+
].filter(x => x).join('');
|
|
60
|
+
return sql;
|
|
61
|
+
}
|
|
62
|
+
;
|
|
63
|
+
function ALTER_TABLE_ADD_COLUMN(options, db_type) {
|
|
64
|
+
const sql = [
|
|
65
|
+
"ALTER TABLE " + (0, Utils_1.getSqlQueryDialect)(db_type).escapeId(options.name),
|
|
66
|
+
" ADD " + options.column,
|
|
67
|
+
db_type !== 'dm' && options.after && " AFTER " + (0, Utils_1.getSqlQueryDialect)(db_type).escapeId(options.after),
|
|
68
|
+
db_type !== 'dm' && options.first && " FIRST",
|
|
69
|
+
].filter(x => x).join('');
|
|
70
|
+
return sql;
|
|
71
|
+
}
|
|
72
|
+
;
|
|
73
|
+
function ALTER_TABLE_RENAME_COLUMN(opts, db_type) {
|
|
74
|
+
const eid = (0, Utils_1.getSqlQueryDialect)(db_type).escapeId;
|
|
75
|
+
const sql = "ALTER TABLE " + eid(opts.name) +
|
|
76
|
+
" RENAME COLUMN " + eid(opts.oldColName) + " TO " + eid(opts.newColName);
|
|
77
|
+
return sql;
|
|
78
|
+
}
|
|
79
|
+
function ALTER_TABLE_MODIFY_COLUMN(options, db_type) {
|
|
80
|
+
const sql = "ALTER TABLE " + (0, Utils_1.getSqlQueryDialect)(db_type).escapeId(options.name) +
|
|
81
|
+
" MODIFY " + options.column;
|
|
82
|
+
return sql;
|
|
83
|
+
}
|
|
84
|
+
;
|
|
85
|
+
function ALTER_TABLE_DROP_COLUMN(options, db_type) {
|
|
86
|
+
const sql = "ALTER TABLE " + (0, Utils_1.getSqlQueryDialect)(db_type).escapeId(options.name) +
|
|
87
|
+
(db_type === 'dm' ? " DROP COLUMN " : " DROP ") + (0, Utils_1.getSqlQueryDialect)(db_type).escapeId(options.column);
|
|
88
|
+
return sql;
|
|
89
|
+
}
|
|
90
|
+
;
|
|
91
|
+
function CREATE_INDEX(options, db_type) {
|
|
92
|
+
const sql = "CREATE" + (options.unique ? " UNIQUE" : "") + " INDEX " + (0, Utils_1.getSqlQueryDialect)(db_type).escapeId(options.name) +
|
|
93
|
+
" ON " + (0, Utils_1.getSqlQueryDialect)(db_type).escapeId(options.collection) +
|
|
94
|
+
" (" + options.columns.map(function (col) { return (0, Utils_1.getSqlQueryDialect)(db_type).escapeId(col); }) + ")";
|
|
95
|
+
return sql;
|
|
96
|
+
}
|
|
97
|
+
;
|
|
98
|
+
function DROP_INDEX(options, db_type) {
|
|
99
|
+
const sql = db_type === 'dm'
|
|
100
|
+
? "DROP INDEX " + (0, Utils_1.getSqlQueryDialect)(db_type).escapeId(options.name)
|
|
101
|
+
: "DROP INDEX " + (0, Utils_1.getSqlQueryDialect)(db_type).escapeId(options.name) +
|
|
102
|
+
" ON " + (0, Utils_1.getSqlQueryDialect)(db_type).escapeId(options.collection);
|
|
103
|
+
return sql;
|
|
104
|
+
}
|
|
105
|
+
;
|
|
106
|
+
// export function RENAME_TABLE (options, driver: FxOrmSqlDDLSync__Driver.Driver) {
|
|
107
|
+
// const sql = "ALTER TABLE " + options.oldCollectionName + " RENAME TO " + options.newCollectionName + " ;";
|
|
108
|
+
// }
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IProperty } from "../../orm-property/index";
|
|
2
|
+
import { FxOrmSqlDDLSync__DbIndex } from "./DbIndex";
|
|
3
|
+
export declare namespace FxOrmSqlDDLSync__Collection {
|
|
4
|
+
interface Collection {
|
|
5
|
+
name: string;
|
|
6
|
+
properties: Record<string, IProperty>;
|
|
7
|
+
/**
|
|
8
|
+
* @description collection level comment, pointless for some database such as sqlite
|
|
9
|
+
*/
|
|
10
|
+
comment: string;
|
|
11
|
+
index_defs: FxOrmSqlDDLSync__DbIndex.CollectionDbIndexInfo[];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare namespace FxOrmSqlDDLSync__DbIndex {
|
|
2
|
+
interface DbIndexInfo {
|
|
3
|
+
name?: string;
|
|
4
|
+
columns: (string | {
|
|
5
|
+
string: number;
|
|
6
|
+
column: string;
|
|
7
|
+
})[];
|
|
8
|
+
unique?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface CollectionDbIndexInfo extends Required<DbIndexInfo> {
|
|
11
|
+
collection: string;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { IDbDriver } from '../../db-driver/index';
|
|
2
|
+
import { FxOrmCoreCallbackNS, FxOrmDialect } from "../../orm-core/index";
|
|
3
|
+
import { IProperty } from "../../orm-property/index";
|
|
4
|
+
import { IPropTransformer } from '../../orm-property/Property';
|
|
5
|
+
import { FxOrmSqlDDLSync__Collection } from "./Collection";
|
|
6
|
+
import { FxOrmSqlDDLSync__DbIndex } from "./DbIndex";
|
|
7
|
+
import { FxOrmSqlDDLSync } from "./_common";
|
|
8
|
+
export declare namespace FxOrmSqlDDLSync__Dialect {
|
|
9
|
+
export type DialectType = 'mysql' | 'mssql' | 'sqlite' | 'postgresql' | 'dm';
|
|
10
|
+
export type PurposeToGetRawType = 'alter_table' | 'create_table' | 'add_column' | 'alter_column';
|
|
11
|
+
type ITypedDriver<T extends IDbDriver.ISQLConn> = IDbDriver.ITypedDriver<T>;
|
|
12
|
+
export interface Dialect<ConnType extends IDbDriver.ISQLConn> extends FxOrmDialect.DDLDialect<ITypedDriver<ConnType>> {
|
|
13
|
+
addForeignKey: {
|
|
14
|
+
(driver: ITypedDriver<ConnType>, tableName: string, options: any, cb: FxOrmCoreCallbackNS.ExecutionCallback<any>): void;
|
|
15
|
+
};
|
|
16
|
+
addForeignKeySync: {
|
|
17
|
+
(driver: ITypedDriver<ConnType>, tableName: string, options: any): any;
|
|
18
|
+
};
|
|
19
|
+
dropForeignKey: {
|
|
20
|
+
(driver: ITypedDriver<ConnType>, tableName: string, columnName: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<any>): void;
|
|
21
|
+
};
|
|
22
|
+
dropForeignKeySync: {
|
|
23
|
+
(driver: ITypedDriver<ConnType>, tableName: string, columnName: string): any;
|
|
24
|
+
};
|
|
25
|
+
getCollectionProperties: {
|
|
26
|
+
(driver: ITypedDriver<ConnType>, collection: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<Record<string, IProperty>>): void;
|
|
27
|
+
};
|
|
28
|
+
getCollectionPropertiesSync: {
|
|
29
|
+
(driver: ITypedDriver<ConnType>, collection: string): Record<string, IProperty>;
|
|
30
|
+
};
|
|
31
|
+
getCollectionIndexes: {
|
|
32
|
+
(driver: ITypedDriver<ConnType>, collection: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<Record<string, FxOrmSqlDDLSync__DbIndex.DbIndexInfo>>): void;
|
|
33
|
+
};
|
|
34
|
+
getCollectionIndexesSync: {
|
|
35
|
+
(driver: ITypedDriver<ConnType>, collection: string): Record<string, FxOrmSqlDDLSync__DbIndex.DbIndexInfo>;
|
|
36
|
+
};
|
|
37
|
+
addIndex: {
|
|
38
|
+
(driver: ITypedDriver<ConnType>, name: string, unique: boolean, collection: FxOrmSqlDDLSync.TableName, columns: string[], cb: FxOrmCoreCallbackNS.ExecutionCallback<any>): void;
|
|
39
|
+
};
|
|
40
|
+
addIndexSync: {
|
|
41
|
+
(driver: ITypedDriver<ConnType>, name: string, unique: boolean, collection: FxOrmSqlDDLSync.TableName, columns: string[]): any;
|
|
42
|
+
};
|
|
43
|
+
removeIndex: {
|
|
44
|
+
(driver: ITypedDriver<ConnType>, name: string, collection: FxOrmSqlDDLSync.TableName, cb: FxOrmCoreCallbackNS.ExecutionCallback<any>): void;
|
|
45
|
+
};
|
|
46
|
+
removeIndexSync: {
|
|
47
|
+
(driver: ITypedDriver<ConnType>, name: string, collection: FxOrmSqlDDLSync.TableName): any;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* @description transform semantic property to raw string in db
|
|
51
|
+
* @experimental
|
|
52
|
+
*/
|
|
53
|
+
toRawType: (property: PropTransformerParams[0], ctx: PropTransformerParams[1] & {
|
|
54
|
+
driver?: ITypedDriver<ConnType>;
|
|
55
|
+
userOptions?: {
|
|
56
|
+
useDefaultValue?: boolean;
|
|
57
|
+
};
|
|
58
|
+
}) => ReturnType<IPropTransformer<any>['toStorageType']>;
|
|
59
|
+
/**
|
|
60
|
+
* process composite keys
|
|
61
|
+
*/
|
|
62
|
+
processKeys?: {
|
|
63
|
+
(keys: string[]): string[];
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* transform type between property and column
|
|
67
|
+
*/
|
|
68
|
+
supportsType?: {
|
|
69
|
+
(type: string): string;
|
|
70
|
+
};
|
|
71
|
+
convertIndexes?: <T extends FxOrmSqlDDLSync__DbIndex.DbIndexInfo>(collection: FxOrmSqlDDLSync__Collection.Collection['name'], db_idxes: T[]) => (typeof db_idxes);
|
|
72
|
+
[extra: string]: any;
|
|
73
|
+
}
|
|
74
|
+
type PropTransformerParams = Parameters<IPropTransformer<any>['toStorageType']>;
|
|
75
|
+
export interface TypeResult<T = any> {
|
|
76
|
+
value: T;
|
|
77
|
+
before?: false | (() => any);
|
|
78
|
+
}
|
|
79
|
+
export type DialectResult<T = any> = TypeResult<T>;
|
|
80
|
+
export {};
|
|
81
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { IDbDriver } from "../../db-driver/index";
|
|
2
|
+
import { FxOrmCoreCallbackNS } from "../../orm-core/index";
|
|
3
|
+
import { IProperty } from "../../orm-property/index";
|
|
4
|
+
import { FxOrmSqlDDLSync__Dialect } from "./Dialect";
|
|
5
|
+
import { FxOrmSqlDDLSync__DbIndex } from "./DbIndex";
|
|
6
|
+
export declare namespace FxOrmSqlDDLSync__Driver {
|
|
7
|
+
interface CustomPropertyType<T extends IDbDriver.IConnTypeEnum = IDbDriver.IConnTypeEnum> {
|
|
8
|
+
datastoreType(prop?: IProperty, opts?: {
|
|
9
|
+
collection: string;
|
|
10
|
+
driver: IDbDriver<T>;
|
|
11
|
+
}): string;
|
|
12
|
+
valueToProperty?(value?: any, prop?: any): any;
|
|
13
|
+
propertyToValue?(value?: any, prop?: any): any;
|
|
14
|
+
[ext_cfg_name: string]: any;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @description one protocol driver should implement
|
|
18
|
+
*/
|
|
19
|
+
interface Driver<T extends IDbDriver.IConnTypeEnum> extends IDbDriver<T> {
|
|
20
|
+
dialect: FxOrmSqlDDLSync__Dialect.DialectType;
|
|
21
|
+
/**
|
|
22
|
+
* @description sync table/collection
|
|
23
|
+
*/
|
|
24
|
+
sync: {
|
|
25
|
+
<T = any>(): T;
|
|
26
|
+
<T = any>(cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* @description drop table/collection
|
|
30
|
+
*/
|
|
31
|
+
drop: {
|
|
32
|
+
<T = any>(): T;
|
|
33
|
+
<T = any>(cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void;
|
|
34
|
+
};
|
|
35
|
+
customTypes?: {
|
|
36
|
+
[type_name: string]: CustomPropertyType<T>;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
interface DbIndexInfo_MySQL extends FxOrmSqlDDLSync__DbIndex.DbIndexInfo {
|
|
40
|
+
index_name: string;
|
|
41
|
+
column_name: string;
|
|
42
|
+
non_unique: number | boolean;
|
|
43
|
+
}
|
|
44
|
+
interface DbIndexInfo_PostgreSQL extends FxOrmSqlDDLSync__DbIndex.DbIndexInfo {
|
|
45
|
+
indisprimary: "1" | "0" | boolean;
|
|
46
|
+
indisunique: "1" | "0" | boolean;
|
|
47
|
+
relname: string;
|
|
48
|
+
attname: string;
|
|
49
|
+
}
|
|
50
|
+
interface DbIndexInfo_SQLite extends FxOrmSqlDDLSync__DbIndex.DbIndexInfo {
|
|
51
|
+
unique: boolean;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare namespace FxOrmSqlDDLSync__SQL {
|
|
2
|
+
interface TableOptions {
|
|
3
|
+
name: string;
|
|
4
|
+
keys?: string[];
|
|
5
|
+
columns?: string[];
|
|
6
|
+
comment?: string;
|
|
7
|
+
}
|
|
8
|
+
interface IndexOptions extends TableOptions {
|
|
9
|
+
unique?: boolean;
|
|
10
|
+
collection?: string;
|
|
11
|
+
}
|
|
12
|
+
interface TableColumnOptionsBase {
|
|
13
|
+
name: string;
|
|
14
|
+
}
|
|
15
|
+
interface CheckTableHasColumnOptions {
|
|
16
|
+
name: string;
|
|
17
|
+
column: string;
|
|
18
|
+
}
|
|
19
|
+
interface AddColumnOptions extends TableColumnOptionsBase {
|
|
20
|
+
column: string;
|
|
21
|
+
first?: boolean;
|
|
22
|
+
after?: string | false;
|
|
23
|
+
}
|
|
24
|
+
interface AlterColumnOptions extends TableColumnOptionsBase {
|
|
25
|
+
column: string;
|
|
26
|
+
}
|
|
27
|
+
interface AlertColumnRenameOptions extends TableColumnOptionsBase {
|
|
28
|
+
oldColName: string;
|
|
29
|
+
newColName: string;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { IDbDriver } from "../../db-driver/index";
|
|
2
|
+
import type { IProperty } from '../../orm-property/index';
|
|
3
|
+
export declare namespace FxOrmSqlDDLSync {
|
|
4
|
+
type TableName = string;
|
|
5
|
+
type ColumnName = string;
|
|
6
|
+
interface SyncOptions<ConnType extends IDbDriver.IConnTypeEnum = IDbDriver.IConnTypeEnum> {
|
|
7
|
+
dbdriver: IDbDriver<ConnType>;
|
|
8
|
+
debug?: Function | false;
|
|
9
|
+
/**
|
|
10
|
+
* @default true
|
|
11
|
+
*/
|
|
12
|
+
suppressColumnDrop?: boolean;
|
|
13
|
+
syncStrategy?: FxOrmSqlDDLSync.SyncCollectionOptions['strategy'];
|
|
14
|
+
}
|
|
15
|
+
interface SyncResult {
|
|
16
|
+
changes: number;
|
|
17
|
+
}
|
|
18
|
+
interface SyncCollectionOptions {
|
|
19
|
+
columns?: Record<string, IProperty>;
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated
|
|
22
|
+
*/
|
|
23
|
+
strategy?: 'soft' | 'hard' | 'mixed';
|
|
24
|
+
/**
|
|
25
|
+
* @default true
|
|
26
|
+
*/
|
|
27
|
+
suppressColumnDrop?: boolean;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { IDbDriver } from "../db-driver/index";
|
|
2
|
+
import type { FxDbDriverNS } from "../db-driver/Typo";
|
|
3
|
+
import type { IProperty } from "../orm-property/index";
|
|
4
|
+
import type { FxOrmSqlDDLSync } from "./Typo/_common";
|
|
5
|
+
import type { FxOrmSqlDDLSync__Collection } from "./Typo/Collection";
|
|
6
|
+
export declare function logJson(group: string, detail: any): string;
|
|
7
|
+
import sqlQueryDialects = require('../sql-query/Dialects');
|
|
8
|
+
import { FxOrmSqlDDLSync__DbIndex } from './Typo/DbIndex';
|
|
9
|
+
type ISqlQueryDialects = typeof sqlQueryDialects;
|
|
10
|
+
export declare function addSqlQueryDialect(type: string, Dialect: any): void;
|
|
11
|
+
export declare function getAllSqlQueryDialects(type: string): {
|
|
12
|
+
psql: import("../sql-query/Typo").FxSqlQueryDialect.Dialect<import("../sql-query/Typo").FxSqlQueryDialect.DialectType>;
|
|
13
|
+
mysql: import("../sql-query/Typo").FxSqlQueryDialect.Dialect<import("../sql-query/Typo").FxSqlQueryDialect.DialectType>;
|
|
14
|
+
postgresql: import("../sql-query/Typo").FxSqlQueryDialect.Dialect<import("../sql-query/Typo").FxSqlQueryDialect.DialectType>;
|
|
15
|
+
sqlite: import("../sql-query/Typo").FxSqlQueryDialect.Dialect<import("../sql-query/Typo").FxSqlQueryDialect.DialectType>;
|
|
16
|
+
mssql: import("../sql-query/Typo").FxSqlQueryDialect.Dialect<import("../sql-query/Typo").FxSqlQueryDialect.DialectType>;
|
|
17
|
+
dm: import("../sql-query/Typo").FxSqlQueryDialect.Dialect<import("../sql-query/Typo").FxSqlQueryDialect.DialectType>;
|
|
18
|
+
};
|
|
19
|
+
export declare function getSqlQueryDialect(type: FxDbDriverNS.DriverType | 'postgresql'): ISqlQueryDialects[keyof ISqlQueryDialects];
|
|
20
|
+
export declare function arraify<T = any>(item: T | T[]): T[];
|
|
21
|
+
export declare function getCollectionMapsTo_PropertyNameDict(collection: FxOrmSqlDDLSync__Collection.Collection): {
|
|
22
|
+
[k: string]: string;
|
|
23
|
+
};
|
|
24
|
+
export declare function filterPropertyDefaultValue(property: IProperty, ctx: {
|
|
25
|
+
collection: string;
|
|
26
|
+
property: IProperty;
|
|
27
|
+
driver: IDbDriver;
|
|
28
|
+
}): any;
|
|
29
|
+
export declare function filterSyncStrategy(strategy: FxOrmSqlDDLSync.SyncCollectionOptions['strategy']): "soft" | "hard" | "mixed";
|
|
30
|
+
export declare function filterSuppressColumnDrop(suppressColumnDrop: boolean, db_type: FxDbDriverNS.DriverType): boolean;
|
|
31
|
+
export declare function psqlGetEnumTypeName(collection_name: string, column_name: string): string;
|
|
32
|
+
export declare function psqlRepairEnumTypes(columns: Record<string, IProperty> | IProperty[], collection_name: string, dbdriver: IDbDriver.ITypedDriver<Class_DbConnection>): void;
|
|
33
|
+
/**
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export declare function extractCollectionIndexes(collection: FxOrmSqlDDLSync__Collection.Collection['name'], property_key: string, property: IProperty, driver_type: string, ret_indexes?: FxOrmSqlDDLSync__DbIndex.CollectionDbIndexInfo[]): FxOrmSqlDDLSync__DbIndex.CollectionDbIndexInfo[];
|
|
37
|
+
/** @internal this will change input */
|
|
38
|
+
export declare function normalizeDefinedProperty(property: IProperty, driver_type: string): IProperty;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/// <reference types="@fibjs/types" />
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.logJson = logJson;
|
|
5
|
+
exports.addSqlQueryDialect = addSqlQueryDialect;
|
|
6
|
+
exports.getAllSqlQueryDialects = getAllSqlQueryDialects;
|
|
7
|
+
exports.getSqlQueryDialect = getSqlQueryDialect;
|
|
8
|
+
exports.arraify = arraify;
|
|
9
|
+
exports.getCollectionMapsTo_PropertyNameDict = getCollectionMapsTo_PropertyNameDict;
|
|
10
|
+
exports.filterPropertyDefaultValue = filterPropertyDefaultValue;
|
|
11
|
+
exports.filterSyncStrategy = filterSyncStrategy;
|
|
12
|
+
exports.filterSuppressColumnDrop = filterSuppressColumnDrop;
|
|
13
|
+
exports.psqlGetEnumTypeName = psqlGetEnumTypeName;
|
|
14
|
+
exports.psqlRepairEnumTypes = psqlRepairEnumTypes;
|
|
15
|
+
exports.extractCollectionIndexes = extractCollectionIndexes;
|
|
16
|
+
exports.normalizeDefinedProperty = normalizeDefinedProperty;
|
|
17
|
+
const coroutine = require("coroutine");
|
|
18
|
+
function logJson(group, detail) {
|
|
19
|
+
let json = null;
|
|
20
|
+
try {
|
|
21
|
+
json = JSON.stringify(detail, null, '\t');
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
throw 'Error occured when trying to log detail';
|
|
25
|
+
}
|
|
26
|
+
if (process.env.DEBUG)
|
|
27
|
+
console.notice(json);
|
|
28
|
+
return json;
|
|
29
|
+
}
|
|
30
|
+
const sqlQueryDialects = require("../sql-query/Dialects");
|
|
31
|
+
function addSqlQueryDialect(type, Dialect) {
|
|
32
|
+
sqlQueryDialects[type] = Dialect;
|
|
33
|
+
}
|
|
34
|
+
function getAllSqlQueryDialects(type) {
|
|
35
|
+
return Object.assign(Object.assign({}, sqlQueryDialects), { psql: sqlQueryDialects['postgresql'] });
|
|
36
|
+
}
|
|
37
|
+
function getSqlQueryDialect(type) {
|
|
38
|
+
switch (type) {
|
|
39
|
+
default:
|
|
40
|
+
// some times others libs could mount faked dialect to sqlQueryDialects, allow return it
|
|
41
|
+
return sqlQueryDialects[type] || null;
|
|
42
|
+
// case 'mongodb':
|
|
43
|
+
case 'redis':
|
|
44
|
+
throw new Error('[getSqlQueryDialect] unsupported driver type: ' + type);
|
|
45
|
+
case 'postgresql':
|
|
46
|
+
case 'psql':
|
|
47
|
+
return sqlQueryDialects['postgresql'];
|
|
48
|
+
case 'sqlite':
|
|
49
|
+
case 'mysql':
|
|
50
|
+
case 'dm':
|
|
51
|
+
// case 'mssql':
|
|
52
|
+
return sqlQueryDialects[type];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function arraify(item) {
|
|
56
|
+
return Array.isArray(item) ? item : [item];
|
|
57
|
+
}
|
|
58
|
+
function getCollectionMapsTo_PropertyNameDict(collection) {
|
|
59
|
+
const hash = {};
|
|
60
|
+
Object.keys(collection.properties).forEach(pname => {
|
|
61
|
+
const prop = collection.properties[pname];
|
|
62
|
+
if (prop.mapsTo)
|
|
63
|
+
hash[prop.mapsTo] = pname;
|
|
64
|
+
});
|
|
65
|
+
return hash;
|
|
66
|
+
}
|
|
67
|
+
function filterPropertyDefaultValue(property, ctx) {
|
|
68
|
+
let _dftValue;
|
|
69
|
+
if (property.hasOwnProperty('defaultValue'))
|
|
70
|
+
if (typeof property.defaultValue === 'function') {
|
|
71
|
+
_dftValue = property.defaultValue(ctx);
|
|
72
|
+
}
|
|
73
|
+
else
|
|
74
|
+
_dftValue = property.defaultValue;
|
|
75
|
+
return _dftValue;
|
|
76
|
+
}
|
|
77
|
+
function filterSyncStrategy(strategy) {
|
|
78
|
+
switch (strategy) {
|
|
79
|
+
case 'hard':
|
|
80
|
+
case 'soft':
|
|
81
|
+
case 'mixed':
|
|
82
|
+
break;
|
|
83
|
+
default:
|
|
84
|
+
strategy = 'soft';
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
return strategy;
|
|
88
|
+
}
|
|
89
|
+
function filterSuppressColumnDrop(suppressColumnDrop, db_type) {
|
|
90
|
+
if (db_type === 'sqlite')
|
|
91
|
+
return true;
|
|
92
|
+
return !!suppressColumnDrop;
|
|
93
|
+
}
|
|
94
|
+
function psqlGetEnumTypeName(collection_name, column_name) {
|
|
95
|
+
return `${collection_name}_enum_${column_name.toLowerCase()}`;
|
|
96
|
+
}
|
|
97
|
+
function psqlRepairEnumTypes(columns, collection_name, dbdriver) {
|
|
98
|
+
const enumProperties = Object.values(columns).filter(col => col.type === 'enum');
|
|
99
|
+
if (!enumProperties.length)
|
|
100
|
+
return;
|
|
101
|
+
const sqlQueryDialect = getSqlQueryDialect('psql');
|
|
102
|
+
const rows = dbdriver.execute(`SELECT * FROM pg_catalog.pg_type WHERE typname IN ${[`(${enumProperties.map(p => sqlQueryDialect.escapeVal(psqlGetEnumTypeName(collection_name, p.name))).join(', ')})`]}`);
|
|
103
|
+
const allExistedTypes = new Set(rows.map(row => row.typname));
|
|
104
|
+
const missingEnumTypeProperties = enumProperties.filter(p => !allExistedTypes.has(psqlGetEnumTypeName(collection_name, p.name)));
|
|
105
|
+
coroutine.parallel(missingEnumTypeProperties, (property) => {
|
|
106
|
+
const type = psqlGetEnumTypeName(collection_name, property.mapsTo.toLowerCase());
|
|
107
|
+
const values = property.values.map(function (val) {
|
|
108
|
+
return sqlQueryDialect.escapeVal(val);
|
|
109
|
+
});
|
|
110
|
+
dbdriver.execute(`CREATE TYPE ${type} AS ENUM (${values})`);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* @description compute system's index name by dialect type
|
|
115
|
+
*
|
|
116
|
+
* @param collection collection to indexed
|
|
117
|
+
* @param prop column's property
|
|
118
|
+
*/
|
|
119
|
+
function getIndexName(collection, prop, dialect_type) {
|
|
120
|
+
const post = prop.unique ? 'unique' : 'index';
|
|
121
|
+
if (dialect_type == 'sqlite') {
|
|
122
|
+
return collection + '_' + prop.name + '_' + post;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
return prop.name + '_' + post;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* @internal
|
|
130
|
+
*/
|
|
131
|
+
function extractCollectionIndexes(collection, property_key, property, driver_type, ret_indexes = []) {
|
|
132
|
+
let found;
|
|
133
|
+
if (property.unique) {
|
|
134
|
+
let mixed_arr_unique = property.unique;
|
|
135
|
+
if (!Array.isArray(property.unique)) {
|
|
136
|
+
mixed_arr_unique = [property.unique];
|
|
137
|
+
}
|
|
138
|
+
for (let i = 0; i < mixed_arr_unique.length; i++) {
|
|
139
|
+
if (mixed_arr_unique[i] === true) {
|
|
140
|
+
ret_indexes.push({
|
|
141
|
+
collection,
|
|
142
|
+
name: getIndexName(collection, property, driver_type),
|
|
143
|
+
unique: true,
|
|
144
|
+
columns: [property_key]
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
found = false;
|
|
149
|
+
for (let j = 0; j < ret_indexes.length; j++) {
|
|
150
|
+
if (ret_indexes[j].name == mixed_arr_unique[i]) {
|
|
151
|
+
found = true;
|
|
152
|
+
ret_indexes[j].columns.push(property_key);
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (!found) {
|
|
157
|
+
ret_indexes.push({
|
|
158
|
+
collection,
|
|
159
|
+
name: mixed_arr_unique[i],
|
|
160
|
+
unique: true,
|
|
161
|
+
columns: [property_key]
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (property.index) {
|
|
168
|
+
let mixed_arr_index = property.index;
|
|
169
|
+
if (!Array.isArray(property.index)) {
|
|
170
|
+
mixed_arr_index = [property.index];
|
|
171
|
+
}
|
|
172
|
+
for (let i = 0; i < mixed_arr_index.length; i++) {
|
|
173
|
+
if (mixed_arr_index[i] === true) {
|
|
174
|
+
ret_indexes.push({
|
|
175
|
+
collection,
|
|
176
|
+
name: getIndexName(collection, property, driver_type),
|
|
177
|
+
unique: false,
|
|
178
|
+
columns: [property_key]
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
found = false;
|
|
183
|
+
for (let j = 0; j < ret_indexes.length; j++) {
|
|
184
|
+
if (ret_indexes[j].name == mixed_arr_index[i]) {
|
|
185
|
+
found = true;
|
|
186
|
+
ret_indexes[j].columns.push(property_key);
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (!found) {
|
|
191
|
+
ret_indexes.push({
|
|
192
|
+
collection,
|
|
193
|
+
name: mixed_arr_index[i],
|
|
194
|
+
columns: [property_key],
|
|
195
|
+
unique: false,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return ret_indexes;
|
|
202
|
+
}
|
|
203
|
+
/** @internal this will change input */
|
|
204
|
+
function normalizeDefinedProperty(property, driver_type) {
|
|
205
|
+
if (driver_type === 'mysql') {
|
|
206
|
+
/**
|
|
207
|
+
* for mysql, on creating table, column with meta auto_increment
|
|
208
|
+
* should be specified as primary key explicitly on table-level
|
|
209
|
+
*/
|
|
210
|
+
if (property.serial || property.type === 'serial') {
|
|
211
|
+
property.type = 'serial';
|
|
212
|
+
property.key = true;
|
|
213
|
+
property.primary = true;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return property;
|
|
217
|
+
}
|