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,266 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.Driver = void 0;
|
|
3
|
+
const util = require("util");
|
|
4
|
+
const sqlite3_1 = require("../DB/sqlite3");
|
|
5
|
+
const shared = require("./_shared");
|
|
6
|
+
const DDL = require("./_ddl-sql");
|
|
7
|
+
const Sync = require("../../../sql-ddl-sync/index");
|
|
8
|
+
const utils = require("./_utils");
|
|
9
|
+
const Utilities = require("../../Utilities");
|
|
10
|
+
const Query_1 = require("../../../sql-query/Query");
|
|
11
|
+
const _dml_helpers_1 = require("./_dml-helpers");
|
|
12
|
+
exports.Driver = function (config, connection, opts) {
|
|
13
|
+
this.dialect = 'sqlite';
|
|
14
|
+
this.opts = opts || {};
|
|
15
|
+
this.customTypes = {};
|
|
16
|
+
Object.defineProperty(this, 'db', {
|
|
17
|
+
value: connection || new sqlite3_1.Database(config),
|
|
18
|
+
writable: false
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(this, 'sqlDriver', {
|
|
21
|
+
value: this.db,
|
|
22
|
+
writable: false
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(this, 'config', {
|
|
25
|
+
value: this.db.config,
|
|
26
|
+
writable: false
|
|
27
|
+
});
|
|
28
|
+
if (!this.config.timezone)
|
|
29
|
+
this.config.timezone = "local";
|
|
30
|
+
Object.defineProperty(this, 'ddlSync', {
|
|
31
|
+
value: Sync.dialect(this.dialect),
|
|
32
|
+
writable: false
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(this, 'query', {
|
|
35
|
+
value: new Query_1.Query({ dialect: this.dialect, timezone: this.config.timezone }),
|
|
36
|
+
writable: false
|
|
37
|
+
});
|
|
38
|
+
utils.getKnexInstance(this);
|
|
39
|
+
this.aggregate_functions = ["ABS", "ROUND",
|
|
40
|
+
"AVG", "MIN", "MAX",
|
|
41
|
+
"RANDOM",
|
|
42
|
+
"SUM", "COUNT",
|
|
43
|
+
"DISTINCT"];
|
|
44
|
+
};
|
|
45
|
+
util.extend(exports.Driver.prototype, shared, DDL);
|
|
46
|
+
exports.Driver.prototype.ping = function (cb) {
|
|
47
|
+
Utilities.takeAwayResult({ error: null }, { callback: cb, use_tick: true });
|
|
48
|
+
return this;
|
|
49
|
+
};
|
|
50
|
+
exports.Driver.prototype.on = function (ev, cb) {
|
|
51
|
+
if (ev == "error") {
|
|
52
|
+
this.db.eventor.on("error", cb);
|
|
53
|
+
}
|
|
54
|
+
return this;
|
|
55
|
+
};
|
|
56
|
+
exports.Driver.prototype.connect = function (cb) {
|
|
57
|
+
const errResults = Utilities.catchBlocking(() => this.db.connect());
|
|
58
|
+
Utilities.takeAwayResult(errResults, { no_throw: !!cb, callback: cb });
|
|
59
|
+
return errResults.result;
|
|
60
|
+
};
|
|
61
|
+
exports.Driver.prototype.close = function (cb) {
|
|
62
|
+
const errResults = Utilities.catchBlocking(() => this.db.close());
|
|
63
|
+
Utilities.takeAwayResult(errResults, { no_throw: !!cb, callback: cb });
|
|
64
|
+
return errResults.result;
|
|
65
|
+
};
|
|
66
|
+
exports.Driver.prototype.getQuery = function () {
|
|
67
|
+
return this.query;
|
|
68
|
+
};
|
|
69
|
+
exports.Driver.prototype.execSimpleQuery = function (query, cb) {
|
|
70
|
+
if (this.opts.debug) {
|
|
71
|
+
require("../../Debug").sql('sqlite', query);
|
|
72
|
+
}
|
|
73
|
+
return this.db.all(query, cb);
|
|
74
|
+
};
|
|
75
|
+
exports.Driver.prototype.find = function (selectFields, table, conditions, opts) {
|
|
76
|
+
const { from_tuple, pure_table, alias } = Utilities.parseTableInputForSelect(table);
|
|
77
|
+
const __pointTypeMapsTo = opts.__pointTypeMapsTo || [];
|
|
78
|
+
const ctx = {
|
|
79
|
+
table,
|
|
80
|
+
fromTuple: from_tuple,
|
|
81
|
+
selectFields,
|
|
82
|
+
selectVirtualFields: opts.selectVirtualFields || []
|
|
83
|
+
};
|
|
84
|
+
let q = this.query.select();
|
|
85
|
+
q = typeof (opts === null || opts === void 0 ? void 0 : opts.generateSqlSelect) === 'function' ? (opts === null || opts === void 0 ? void 0 : opts.generateSqlSelect.call(this, ctx, q)) || q : Utilities.DEFAULT_GENERATE_SQL_QUERY_SELECT.call(this, ctx, q);
|
|
86
|
+
if (opts.offset) {
|
|
87
|
+
q.offset(opts.offset);
|
|
88
|
+
}
|
|
89
|
+
if (typeof opts.limit == "number") {
|
|
90
|
+
q.limit(opts.limit);
|
|
91
|
+
}
|
|
92
|
+
else if (opts.offset) {
|
|
93
|
+
// OFFSET cannot be used without LIMIT so we use the biggest INTEGER number possible
|
|
94
|
+
q.limit('9223372036854775807');
|
|
95
|
+
}
|
|
96
|
+
utils.buildBaseConditionsToQuery.apply(this, [q, pure_table, conditions, opts.topConditions]);
|
|
97
|
+
utils.buildOrderToQuery.apply(this, [q, opts.order]);
|
|
98
|
+
utils.buildMergeToQuery.apply(this, [q, opts.merge]);
|
|
99
|
+
utils.buildExistsToQuery.apply(this, [q, alias, opts.exists]);
|
|
100
|
+
const results = this.execSimpleQuery(q.build());
|
|
101
|
+
if (__pointTypeMapsTo.length > 0 && Array.isArray(results)) {
|
|
102
|
+
results.forEach(item => {
|
|
103
|
+
__pointTypeMapsTo.forEach(field => {
|
|
104
|
+
item[field] = (0, _dml_helpers_1.safeParseJson)((0, _dml_helpers_1.unwrapQuote)(item[field]));
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return results;
|
|
109
|
+
};
|
|
110
|
+
exports.Driver.prototype.count = function (table, conditions, opts, cb) {
|
|
111
|
+
const { from_tuple, pure_table, alias } = Utilities.parseTableInputForSelect(table);
|
|
112
|
+
const q = this.query.select()
|
|
113
|
+
.from(from_tuple)
|
|
114
|
+
.count(null, 'c');
|
|
115
|
+
utils.buildBaseConditionsToQuery.apply(this, [q, pure_table, conditions]);
|
|
116
|
+
utils.buildMergeToQuery.apply(this, [q, opts.merge, conditions]);
|
|
117
|
+
utils.buildExistsToQuery.apply(this, [q, alias, opts.exists]);
|
|
118
|
+
return this.execSimpleQuery(q.build(), cb);
|
|
119
|
+
};
|
|
120
|
+
exports.Driver.prototype.insert = function (table, data, keyProperties, cb) {
|
|
121
|
+
var q = this.query.insert()
|
|
122
|
+
.into(table)
|
|
123
|
+
.set(data)
|
|
124
|
+
.build();
|
|
125
|
+
const syncResponse = Utilities.catchBlocking(() => {
|
|
126
|
+
const info = this.execSimpleQuery(q);
|
|
127
|
+
if (!keyProperties)
|
|
128
|
+
return null;
|
|
129
|
+
var ids = {}, prop;
|
|
130
|
+
if (keyProperties.length == 1 && keyProperties[0].type == 'serial') {
|
|
131
|
+
ids[keyProperties[0].name] = info.insertId;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
for (let i = 0; i < keyProperties.length; i++) {
|
|
135
|
+
prop = keyProperties[i];
|
|
136
|
+
// Zero is a valid value for an ID column
|
|
137
|
+
ids[prop.name] = data[prop.mapsTo] !== undefined ? data[prop.mapsTo] : null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return ids;
|
|
141
|
+
});
|
|
142
|
+
Utilities.takeAwayResult(syncResponse, { callback: cb });
|
|
143
|
+
return syncResponse.result;
|
|
144
|
+
};
|
|
145
|
+
exports.Driver.prototype.update = function (table, changes, conditions, cb) {
|
|
146
|
+
var q = this.query.update()
|
|
147
|
+
.into(table)
|
|
148
|
+
.set(changes)
|
|
149
|
+
.where(conditions)
|
|
150
|
+
.build();
|
|
151
|
+
return this.execSimpleQuery(q, cb);
|
|
152
|
+
};
|
|
153
|
+
exports.Driver.prototype.remove = function (table, conditions, cb) {
|
|
154
|
+
var q = this.query.remove()
|
|
155
|
+
.from(table)
|
|
156
|
+
.where(conditions)
|
|
157
|
+
.build();
|
|
158
|
+
return this.execSimpleQuery(q, cb);
|
|
159
|
+
};
|
|
160
|
+
exports.Driver.prototype.clear = function (table, cb) {
|
|
161
|
+
const syncResponse = Utilities.catchBlocking(() => {
|
|
162
|
+
this.execQuery(this.query.remove()
|
|
163
|
+
.from(table)
|
|
164
|
+
.build());
|
|
165
|
+
this.execQuery(this.query.remove()
|
|
166
|
+
.from(table)
|
|
167
|
+
.where({ name: 'sqlite_sequence' })
|
|
168
|
+
.build());
|
|
169
|
+
});
|
|
170
|
+
Utilities.takeAwayResult(syncResponse, { callback: cb });
|
|
171
|
+
return syncResponse.result;
|
|
172
|
+
};
|
|
173
|
+
exports.Driver.prototype.valueToProperty = function (value, property) {
|
|
174
|
+
var v, customType;
|
|
175
|
+
switch (property.type) {
|
|
176
|
+
case "boolean":
|
|
177
|
+
value = !!value;
|
|
178
|
+
break;
|
|
179
|
+
case "object":
|
|
180
|
+
if (typeof value == "object" && !Buffer.isBuffer(value)) {
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
value = JSON.parse(value);
|
|
185
|
+
}
|
|
186
|
+
catch (e) {
|
|
187
|
+
value = null;
|
|
188
|
+
}
|
|
189
|
+
break;
|
|
190
|
+
case "binary": {
|
|
191
|
+
// compat with standard behavior of `JSON.stringify`/`JSON.parse`
|
|
192
|
+
if (value && value.type === 'Buffer' && Array.isArray(value.data)) {
|
|
193
|
+
value = Buffer.from(value.data);
|
|
194
|
+
}
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case "number":
|
|
198
|
+
if (typeof value == 'string') {
|
|
199
|
+
switch (value.trim()) {
|
|
200
|
+
case 'Infinity':
|
|
201
|
+
case '-Infinity':
|
|
202
|
+
case 'NaN':
|
|
203
|
+
value = Number(value);
|
|
204
|
+
break;
|
|
205
|
+
default:
|
|
206
|
+
v = parseFloat(value);
|
|
207
|
+
if (Number.isFinite(v)) {
|
|
208
|
+
value = v;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
break;
|
|
213
|
+
case "integer":
|
|
214
|
+
if (typeof value == 'string') {
|
|
215
|
+
v = parseInt(value);
|
|
216
|
+
if (Number.isFinite(v)) {
|
|
217
|
+
value = v;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
break;
|
|
221
|
+
case "date":
|
|
222
|
+
if (util.isNumber(value) || util.isString(value))
|
|
223
|
+
value = new Date(value);
|
|
224
|
+
break;
|
|
225
|
+
default:
|
|
226
|
+
customType = this.customTypes[property.type];
|
|
227
|
+
if (customType && 'valueToProperty' in customType) {
|
|
228
|
+
value = customType.valueToProperty(value, property);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return value;
|
|
232
|
+
};
|
|
233
|
+
exports.Driver.prototype.propertyToValue = function (value, property) {
|
|
234
|
+
switch (property.type) {
|
|
235
|
+
case "boolean":
|
|
236
|
+
value = (value) ? 1 : 0;
|
|
237
|
+
break;
|
|
238
|
+
case "object":
|
|
239
|
+
if (value !== null) {
|
|
240
|
+
value = JSON.stringify(value);
|
|
241
|
+
}
|
|
242
|
+
break;
|
|
243
|
+
case "date":
|
|
244
|
+
if (util.isNumber(value) || util.isString(value))
|
|
245
|
+
value = new Date(value);
|
|
246
|
+
break;
|
|
247
|
+
default:
|
|
248
|
+
const customType = this.customTypes[property.type];
|
|
249
|
+
if (customType && 'propertyToValue' in customType) {
|
|
250
|
+
value = customType.propertyToValue(value);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return value;
|
|
254
|
+
};
|
|
255
|
+
Object.defineProperty(exports.Driver.prototype, "isSql", {
|
|
256
|
+
value: true
|
|
257
|
+
});
|
|
258
|
+
function convertTimezone(tz) {
|
|
259
|
+
if (tz == "Z")
|
|
260
|
+
return 0;
|
|
261
|
+
var m = tz.match(/([\+\-\s])(\d\d):?(\d\d)?/);
|
|
262
|
+
if (m) {
|
|
263
|
+
return (m[1] == '-' ? -1 : 1) * (parseInt(m[2], 10) + ((m[3] ? parseInt(m[3], 10) : 0) / 60)) * 60;
|
|
264
|
+
}
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FxOrmError } from "./Typo/Error";
|
|
2
|
+
export default class ORMError extends Error {
|
|
3
|
+
static codes: FxOrmError.PredefineErrorCodes;
|
|
4
|
+
name: string;
|
|
5
|
+
message: string;
|
|
6
|
+
code: number | string;
|
|
7
|
+
literalCode: string;
|
|
8
|
+
[k: string]: any;
|
|
9
|
+
constructor(message: string, code?: keyof FxOrmError.PredefineErrorCodes, extras?: any);
|
|
10
|
+
toString(): string;
|
|
11
|
+
}
|
package/lib/orm/Error.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const codes = {
|
|
3
|
+
QUERY_ERROR: 1,
|
|
4
|
+
NOT_FOUND: 2,
|
|
5
|
+
NOT_DEFINED: 3,
|
|
6
|
+
NO_SUPPORT: 4,
|
|
7
|
+
MISSING_CALLBACK: 5,
|
|
8
|
+
PARAM_MISMATCH: 6,
|
|
9
|
+
CONNECTION_LOST: 10,
|
|
10
|
+
BAD_MODEL: 15
|
|
11
|
+
};
|
|
12
|
+
class ORMError extends Error {
|
|
13
|
+
constructor(message, code, extras) {
|
|
14
|
+
super();
|
|
15
|
+
this.name = 'ORMError';
|
|
16
|
+
this.message = '';
|
|
17
|
+
this.code = 0;
|
|
18
|
+
this.literalCode = '';
|
|
19
|
+
Error.call(this);
|
|
20
|
+
Error.captureStackTrace(this, this.constructor);
|
|
21
|
+
this.message = message;
|
|
22
|
+
if (code) {
|
|
23
|
+
this.code = codes[code];
|
|
24
|
+
this.literalCode = code;
|
|
25
|
+
if (!this.code) {
|
|
26
|
+
throw new Error("Invalid error code: " + code);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (extras) {
|
|
30
|
+
for (let k in extras) {
|
|
31
|
+
this[k] = extras[k];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
toString() {
|
|
36
|
+
return '[ORMError ' + this.literalCode + ': ' + this.message + ']';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.default = ORMError;
|
|
40
|
+
ORMError.codes = codes;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { FxDbDriverNS, IDbDriver } from "../db-driver/index";
|
|
2
|
+
import { FxOrmNS } from './Typo/ORM';
|
|
3
|
+
import { FxOrmInstance } from './Typo/instance';
|
|
4
|
+
import { FxOrmAssociation } from './Typo/assoc';
|
|
5
|
+
import { FxOrmModel } from './Typo/model';
|
|
6
|
+
import { FxOrmHook } from './Typo/hook';
|
|
7
|
+
import { FxOrmProperty } from "./Typo/property";
|
|
8
|
+
export declare function buildDbDriver(opts: string | FxDbDriverNS.DBConnectionConfig): FxOrmNS.ORMLike | IDbDriver;
|
|
9
|
+
export declare function pickProperties<T extends FxOrmModel.Model = FxOrmModel.Model>(m: T, picker: ((p: FxOrmProperty.NormalizedProperty, k: string, m: T) => boolean)): Record<string, FxOrmProperty.NormalizedProperty>;
|
|
10
|
+
export declare function getManyAssociationItemFromInstanceByExtname(instance: FxOrmInstance.Instance, extend_name: string): FxOrmAssociation.InstanceAssociationItem_HasMany;
|
|
11
|
+
export declare function getOneAssociationItemFromInstanceByExtname(instance: FxOrmInstance.Instance, extend_name: string): FxOrmAssociation.InstanceAssociationItem_HasOne;
|
|
12
|
+
export declare function getExtendsToAssociationItemFromInstanceByExtname(instance: FxOrmInstance.Instance, extend_name: string): FxOrmAssociation.InstanceAssociationItem_ExtendTos;
|
|
13
|
+
export declare function getAssociationItemFromInstanceByExtname(reltype: string, inst: FxOrmInstance.Instance, extend_name: string): FxOrmAssociation.InstanceAssociationItem;
|
|
14
|
+
export declare function getManyAssociationItemFromInstanceByAssocModel(instance: FxOrmInstance.Instance, assoc_model: FxOrmModel.Model): FxOrmAssociation.InstanceAssociationItem_HasMany;
|
|
15
|
+
export declare function getOneAssociationItemFromInstanceByAssocModel(instance: FxOrmInstance.Instance, assoc_model: FxOrmModel.Model): FxOrmAssociation.InstanceAssociationItem_HasOne;
|
|
16
|
+
export declare function getExtendsToAssociationItemFromInstanceByAssocModel(instance: FxOrmInstance.Instance, assoc_model: FxOrmModel.Model): FxOrmAssociation.InstanceAssociationItem_ExtendTos;
|
|
17
|
+
export declare function getAssociationItemFromInstanceByAssocModel(reltype: string, inst: FxOrmInstance.Instance, assoc_model: FxOrmModel.Model): FxOrmAssociation.InstanceAssociationItem;
|
|
18
|
+
export declare function getManyAssociationItemFromModel(ext_name: string, _model: FxOrmModel.Model): FxOrmAssociation.InstanceAssociationItem_HasMany;
|
|
19
|
+
export declare function getOneAssociationItemFromModel(ext_name: string, _model: FxOrmModel.Model): FxOrmAssociation.InstanceAssociationItem_HasOne;
|
|
20
|
+
export declare function getExtendsToAssociationItemFromModel(ext_name: string, _model: FxOrmModel.Model): FxOrmAssociation.InstanceAssociationItem_ExtendTos;
|
|
21
|
+
export declare function getAssociationItemFromModel(reltype: string, extend_name: string, _model: FxOrmModel.Model): FxOrmAssociation.InstanceAssociationItem;
|
|
22
|
+
export declare function tryGetAssociationItemFromModel(extend_name: string, _model: FxOrmModel.Model): FxOrmAssociation.InstanceAssociationItem;
|
|
23
|
+
export declare function prependHook(hooks: FxOrmModel.Hooks, hookName: keyof FxOrmModel.Hooks, preLogic: FxOrmHook.HookActionCallback | FxOrmHook.HookResultCallback): void;
|
|
24
|
+
export declare function preReplaceHook(m: FxOrmModel.Model, opts: FxOrmModel.ModelDefineOptions, hookName: keyof FxOrmModel.Hooks, cb: (this: FxOrmInstance.Instance, inst: FxOrmInstance.Instance) => void): void;
|
|
25
|
+
export declare const hookTrigger: FxOrmHook.HookTrigger<any, any>;
|
|
26
|
+
export declare const hookWait: FxOrmHook.HookWait<FxOrmInstance.Instance<Record<string, FxOrmInstance.FieldRuntimeType>, Record<string, (...args: any) => any>>, any>;
|
|
27
|
+
export declare function selectArgs(args: ArrayLike<any>, callback: {
|
|
28
|
+
(arg_type: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function", arg: any, idx: number): void;
|
|
29
|
+
}): void;
|
|
30
|
+
export declare function parseDriverUidAndTableNameFromUID(uid: string): {
|
|
31
|
+
driver_uid: string;
|
|
32
|
+
table: string;
|
|
33
|
+
driver_table_uid: string;
|
|
34
|
+
};
|
|
35
|
+
export declare function valueOrComputeFunction<T = Exclude<any, Function>>(input: T | ((...args: any[]) => T), args?: any[], thisArg?: any): T;
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.valueOrComputeFunction = exports.parseDriverUidAndTableNameFromUID = exports.selectArgs = exports.hookWait = exports.hookTrigger = exports.preReplaceHook = exports.prependHook = exports.tryGetAssociationItemFromModel = exports.getAssociationItemFromModel = exports.getExtendsToAssociationItemFromModel = exports.getOneAssociationItemFromModel = exports.getManyAssociationItemFromModel = exports.getAssociationItemFromInstanceByAssocModel = exports.getExtendsToAssociationItemFromInstanceByAssocModel = exports.getOneAssociationItemFromInstanceByAssocModel = exports.getManyAssociationItemFromInstanceByAssocModel = exports.getAssociationItemFromInstanceByExtname = exports.getExtendsToAssociationItemFromInstanceByExtname = exports.getOneAssociationItemFromInstanceByExtname = exports.getManyAssociationItemFromInstanceByExtname = exports.pickProperties = exports.buildDbDriver = void 0;
|
|
3
|
+
const index_1 = require("../db-driver/index");
|
|
4
|
+
const Hook = require("./Hook");
|
|
5
|
+
const Utilities = require("./Utilities");
|
|
6
|
+
const Error_1 = require("./Error");
|
|
7
|
+
function buildDbDriver(opts) {
|
|
8
|
+
if (!opts) {
|
|
9
|
+
return Utilities.ORM_Error(new Error_1.default("CONNECTION_URL_EMPTY", 'PARAM_MISMATCH'));
|
|
10
|
+
}
|
|
11
|
+
else if (typeof opts === 'string') {
|
|
12
|
+
if (opts.trim().length === 0) {
|
|
13
|
+
return Utilities.ORM_Error(new Error_1.default("CONNECTION_URL_EMPTY", 'PARAM_MISMATCH'));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
let driver = null;
|
|
17
|
+
try {
|
|
18
|
+
driver = index_1.Driver.create(opts);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (error.message === '[driver.config] invalid protocol')
|
|
22
|
+
return Utilities.ORM_Error(new Error_1.default("CONNECTION_URL_NO_PROTOCOL", 'PARAM_MISMATCH'));
|
|
23
|
+
}
|
|
24
|
+
const config = driver.config;
|
|
25
|
+
const isSqlite = config.protocol === 'sqlite:';
|
|
26
|
+
if (isSqlite && config.timezone === undefined)
|
|
27
|
+
driver.extend_config.timezone = 'UTC';
|
|
28
|
+
return driver;
|
|
29
|
+
}
|
|
30
|
+
exports.buildDbDriver = buildDbDriver;
|
|
31
|
+
/* model helpers :start */
|
|
32
|
+
// TODO: add test case
|
|
33
|
+
function pickProperties(m, picker) {
|
|
34
|
+
return Object.entries(m.__propertiesByName).reduce((accu, [k, prop]) => {
|
|
35
|
+
if (picker(prop, k, m)) {
|
|
36
|
+
accu[k] = prop;
|
|
37
|
+
}
|
|
38
|
+
;
|
|
39
|
+
return accu;
|
|
40
|
+
}, {});
|
|
41
|
+
}
|
|
42
|
+
exports.pickProperties = pickProperties;
|
|
43
|
+
/* model helpers :end */
|
|
44
|
+
function manyAssocsFromInst(instance) {
|
|
45
|
+
return instance.__instRtd.many_associations;
|
|
46
|
+
}
|
|
47
|
+
function oneAssocsFromInst(instance) {
|
|
48
|
+
return instance.__instRtd.one_associations;
|
|
49
|
+
}
|
|
50
|
+
function extendsToAssocsFromInst(instance) {
|
|
51
|
+
return instance.__instRtd.extend_associations;
|
|
52
|
+
}
|
|
53
|
+
/* by instance extname :start */
|
|
54
|
+
function getManyAssociationItemFromInstanceByExtname(instance, extend_name) {
|
|
55
|
+
const many_assocs = manyAssocsFromInst(instance);
|
|
56
|
+
return many_assocs.find(a => a.name === extend_name);
|
|
57
|
+
}
|
|
58
|
+
exports.getManyAssociationItemFromInstanceByExtname = getManyAssociationItemFromInstanceByExtname;
|
|
59
|
+
function getOneAssociationItemFromInstanceByExtname(instance, extend_name) {
|
|
60
|
+
const one_assocs = oneAssocsFromInst(instance);
|
|
61
|
+
return one_assocs.find(a => a.name === extend_name);
|
|
62
|
+
}
|
|
63
|
+
exports.getOneAssociationItemFromInstanceByExtname = getOneAssociationItemFromInstanceByExtname;
|
|
64
|
+
function getExtendsToAssociationItemFromInstanceByExtname(instance, extend_name) {
|
|
65
|
+
const extendsto_assocs = extendsToAssocsFromInst(instance);
|
|
66
|
+
return extendsto_assocs.find(a => a.name === extend_name);
|
|
67
|
+
}
|
|
68
|
+
exports.getExtendsToAssociationItemFromInstanceByExtname = getExtendsToAssociationItemFromInstanceByExtname;
|
|
69
|
+
function getAssociationItemFromInstanceByExtname(reltype, inst, extend_name) {
|
|
70
|
+
switch (reltype) {
|
|
71
|
+
default:
|
|
72
|
+
throw 'invalid association reltype!';
|
|
73
|
+
case 'extendsTo':
|
|
74
|
+
return getExtendsToAssociationItemFromInstanceByExtname(inst, extend_name);
|
|
75
|
+
case 'hasOne':
|
|
76
|
+
return getOneAssociationItemFromInstanceByExtname(inst, extend_name);
|
|
77
|
+
case 'hasMany':
|
|
78
|
+
return getManyAssociationItemFromInstanceByExtname(inst, extend_name);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.getAssociationItemFromInstanceByExtname = getAssociationItemFromInstanceByExtname;
|
|
82
|
+
/* by instance extname :end */
|
|
83
|
+
/* by instance x assoc_model :start */
|
|
84
|
+
function getManyAssociationItemFromInstanceByAssocModel(instance, assoc_model) {
|
|
85
|
+
const many_assocs = manyAssocsFromInst(instance);
|
|
86
|
+
return many_assocs.find(a => a.model === assoc_model);
|
|
87
|
+
}
|
|
88
|
+
exports.getManyAssociationItemFromInstanceByAssocModel = getManyAssociationItemFromInstanceByAssocModel;
|
|
89
|
+
function getOneAssociationItemFromInstanceByAssocModel(instance, assoc_model) {
|
|
90
|
+
const one_assocs = oneAssocsFromInst(instance);
|
|
91
|
+
return one_assocs.find(a => a.model === assoc_model);
|
|
92
|
+
}
|
|
93
|
+
exports.getOneAssociationItemFromInstanceByAssocModel = getOneAssociationItemFromInstanceByAssocModel;
|
|
94
|
+
function getExtendsToAssociationItemFromInstanceByAssocModel(instance, assoc_model) {
|
|
95
|
+
const extendsto_assocs = extendsToAssocsFromInst(instance);
|
|
96
|
+
return extendsto_assocs.find(a => a.model === assoc_model);
|
|
97
|
+
}
|
|
98
|
+
exports.getExtendsToAssociationItemFromInstanceByAssocModel = getExtendsToAssociationItemFromInstanceByAssocModel;
|
|
99
|
+
function getAssociationItemFromInstanceByAssocModel(reltype, inst, assoc_model) {
|
|
100
|
+
switch (reltype) {
|
|
101
|
+
default:
|
|
102
|
+
throw 'invalid association reltype!';
|
|
103
|
+
case 'extendsTo':
|
|
104
|
+
return getManyAssociationItemFromInstanceByAssocModel(inst, assoc_model);
|
|
105
|
+
case 'hasOne':
|
|
106
|
+
return getOneAssociationItemFromInstanceByAssocModel(inst, assoc_model);
|
|
107
|
+
case 'hasMany':
|
|
108
|
+
return getExtendsToAssociationItemFromInstanceByAssocModel(inst, assoc_model);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.getAssociationItemFromInstanceByAssocModel = getAssociationItemFromInstanceByAssocModel;
|
|
112
|
+
/* by instance x assoc_model :end */
|
|
113
|
+
/* by ext_name x _model :start */
|
|
114
|
+
function getManyAssociationItemFromModel(ext_name, _model) {
|
|
115
|
+
const rel_info = _model.associations[ext_name];
|
|
116
|
+
if (!rel_info || rel_info.type !== 'hasMany')
|
|
117
|
+
return null;
|
|
118
|
+
return rel_info.association;
|
|
119
|
+
}
|
|
120
|
+
exports.getManyAssociationItemFromModel = getManyAssociationItemFromModel;
|
|
121
|
+
function getOneAssociationItemFromModel(ext_name, _model) {
|
|
122
|
+
const rel_info = _model.associations[ext_name];
|
|
123
|
+
if (!rel_info || rel_info.type !== 'hasOne')
|
|
124
|
+
return null;
|
|
125
|
+
return rel_info.association;
|
|
126
|
+
}
|
|
127
|
+
exports.getOneAssociationItemFromModel = getOneAssociationItemFromModel;
|
|
128
|
+
function getExtendsToAssociationItemFromModel(ext_name, _model) {
|
|
129
|
+
const rel_info = _model.associations[ext_name];
|
|
130
|
+
if (!rel_info || rel_info.type !== 'extendsTo')
|
|
131
|
+
return null;
|
|
132
|
+
return rel_info.association;
|
|
133
|
+
}
|
|
134
|
+
exports.getExtendsToAssociationItemFromModel = getExtendsToAssociationItemFromModel;
|
|
135
|
+
function getAssociationItemFromModel(reltype, extend_name, _model) {
|
|
136
|
+
switch (reltype) {
|
|
137
|
+
default:
|
|
138
|
+
throw 'invalid association reltype!';
|
|
139
|
+
case 'extendsTo':
|
|
140
|
+
return getManyAssociationItemFromModel(extend_name, _model);
|
|
141
|
+
case 'hasOne':
|
|
142
|
+
return getOneAssociationItemFromModel(extend_name, _model);
|
|
143
|
+
case 'hasMany':
|
|
144
|
+
return getExtendsToAssociationItemFromModel(extend_name, _model);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.getAssociationItemFromModel = getAssociationItemFromModel;
|
|
148
|
+
function tryGetAssociationItemFromModel(extend_name, _model) {
|
|
149
|
+
return getManyAssociationItemFromModel(extend_name, _model) || getOneAssociationItemFromModel(extend_name, _model) || getExtendsToAssociationItemFromModel(extend_name, _model);
|
|
150
|
+
}
|
|
151
|
+
exports.tryGetAssociationItemFromModel = tryGetAssociationItemFromModel;
|
|
152
|
+
/* by ext_name x assoc_model :end */
|
|
153
|
+
/* hooks :start */
|
|
154
|
+
function prependHook(hooks, hookName, preLogic) {
|
|
155
|
+
if (typeof hooks[hookName] === 'function') {
|
|
156
|
+
var oldHook = hooks[hookName];
|
|
157
|
+
const callOldHook = function (next) {
|
|
158
|
+
if (typeof oldHook === 'function') {
|
|
159
|
+
if (oldHook.length > 0)
|
|
160
|
+
return oldHook.call(this, next);
|
|
161
|
+
oldHook.call(this);
|
|
162
|
+
}
|
|
163
|
+
if (typeof next === 'function')
|
|
164
|
+
next();
|
|
165
|
+
};
|
|
166
|
+
hooks[hookName] = function (next) {
|
|
167
|
+
if (preLogic.length > 0) {
|
|
168
|
+
var self = this;
|
|
169
|
+
return preLogic.call(this, function () {
|
|
170
|
+
callOldHook.call(self, next);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
preLogic.call(this);
|
|
174
|
+
callOldHook.call(this, next);
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
hooks[hookName] = preLogic;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
exports.prependHook = prependHook;
|
|
182
|
+
function preReplaceHook(m, opts, hookName, cb) {
|
|
183
|
+
var _oldHook;
|
|
184
|
+
if (opts !== undefined && opts.hooks)
|
|
185
|
+
_oldHook = opts.hooks[hookName];
|
|
186
|
+
m[hookName](function (next) {
|
|
187
|
+
cb.call(this, this);
|
|
188
|
+
if (_oldHook) {
|
|
189
|
+
if (_oldHook.length > 0) {
|
|
190
|
+
if (typeof next === 'boolean')
|
|
191
|
+
return _oldHook.call(this, next);
|
|
192
|
+
else
|
|
193
|
+
return _oldHook.call(this, next);
|
|
194
|
+
}
|
|
195
|
+
_oldHook.call(this);
|
|
196
|
+
}
|
|
197
|
+
if (typeof next === 'function')
|
|
198
|
+
next.call(this);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
exports.preReplaceHook = preReplaceHook;
|
|
202
|
+
exports.hookTrigger = Hook.trigger;
|
|
203
|
+
exports.hookWait = Hook.wait;
|
|
204
|
+
/* hooks: end */
|
|
205
|
+
/* arguments input :start */
|
|
206
|
+
function selectArgs(args, callback) {
|
|
207
|
+
// copy slice to ensure loop idx is correct
|
|
208
|
+
args = Array.prototype.slice.apply(args);
|
|
209
|
+
for (let i = 0, arg = null; i < args.length; i++) {
|
|
210
|
+
arg = args[i];
|
|
211
|
+
callback(typeof arg, arg, i);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
exports.selectArgs = selectArgs;
|
|
215
|
+
/* arguments input :end */
|
|
216
|
+
/* singleton helpers: start */
|
|
217
|
+
function parseDriverUidAndTableNameFromUID(uid) {
|
|
218
|
+
uid = uid || '';
|
|
219
|
+
const arr = uid.split('/');
|
|
220
|
+
return {
|
|
221
|
+
driver_uid: arr[0],
|
|
222
|
+
table: arr[1],
|
|
223
|
+
driver_table_uid: Utilities.makeIdForDriverTable(arr[0], arr[1])
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
exports.parseDriverUidAndTableNameFromUID = parseDriverUidAndTableNameFromUID;
|
|
227
|
+
/* singleton helpers: end */
|
|
228
|
+
function valueOrComputeFunction(input, args, thisArg) {
|
|
229
|
+
if (typeof input === 'function')
|
|
230
|
+
return input.apply(thisArg, args);
|
|
231
|
+
return input;
|
|
232
|
+
}
|
|
233
|
+
exports.valueOrComputeFunction = valueOrComputeFunction;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FxOrmHook } from './Typo/hook';
|
|
2
|
+
/**
|
|
3
|
+
* support hook style function
|
|
4
|
+
*
|
|
5
|
+
* function (success: boolean) {}
|
|
6
|
+
*/
|
|
7
|
+
export declare const trigger: FxOrmHook.HookTrigger<any, any>;
|
|
8
|
+
/**
|
|
9
|
+
* support hook style function
|
|
10
|
+
*
|
|
11
|
+
* function (next: Function) {}
|
|
12
|
+
*/
|
|
13
|
+
export declare const wait: FxOrmHook.HookWait;
|