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,34 @@
|
|
|
1
|
+
/// <reference types="@fibjs/enforce" />
|
|
2
|
+
export declare const required: FibjsEnforce.enforcementValidation;
|
|
3
|
+
export declare const notEmptyString: FibjsEnforce.enforcementValidation;
|
|
4
|
+
export declare const rangeNumber: FibjsEnforce.enforcementValidation;
|
|
5
|
+
export declare const rangeLength: FibjsEnforce.enforcementValidation;
|
|
6
|
+
export declare const insideList: FibjsEnforce.enforcementValidation;
|
|
7
|
+
export declare const outsideList: FibjsEnforce.enforcementValidation;
|
|
8
|
+
export declare const password: FibjsEnforce.enforcementValidation;
|
|
9
|
+
export declare const patterns: FibjsEnforce.enforcementsContainer;
|
|
10
|
+
import { FxOrmValidators } from "./Typo/Validators";
|
|
11
|
+
/**
|
|
12
|
+
* Check if a value is the same as a value
|
|
13
|
+
* of another property (useful for password
|
|
14
|
+
* checking).
|
|
15
|
+
**/
|
|
16
|
+
export declare function equalToProperty(name: string, msg?: string): FibjsEnforce.ValidationCallback;
|
|
17
|
+
/**
|
|
18
|
+
* Check if a property is unique in the collection.
|
|
19
|
+
* This can take a while because a query has to be made against the Model.
|
|
20
|
+
*
|
|
21
|
+
* Due to the async nature of node, and concurrent web server environments,
|
|
22
|
+
* an index on the database column is the only way to gurantee uniqueness.
|
|
23
|
+
*
|
|
24
|
+
* For sensibility's sake, undefined and null values are ignored for uniqueness
|
|
25
|
+
* checks.
|
|
26
|
+
*
|
|
27
|
+
* Options:
|
|
28
|
+
* ignoreCase: for postgres; mysql ignores case by default.
|
|
29
|
+
* scope: (Array) scope uniqueness to listed properties
|
|
30
|
+
**/
|
|
31
|
+
export declare function unique(opts?: {
|
|
32
|
+
ignoreCase?: boolean;
|
|
33
|
+
scope?: string[];
|
|
34
|
+
}, msg?: string): FxOrmValidators.ValidationCallback;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.unique = exports.equalToProperty = exports.patterns = exports.password = exports.outsideList = exports.insideList = exports.rangeLength = exports.rangeNumber = exports.notEmptyString = exports.required = void 0;
|
|
3
|
+
const Enforce = require("@fibjs/enforce");
|
|
4
|
+
const util = require("util");
|
|
5
|
+
exports.required = Enforce.required;
|
|
6
|
+
exports.notEmptyString = Enforce.notEmptyString;
|
|
7
|
+
exports.rangeNumber = Enforce.ranges.number;
|
|
8
|
+
exports.rangeLength = Enforce.ranges.length;
|
|
9
|
+
exports.insideList = Enforce.lists.inside;
|
|
10
|
+
exports.outsideList = Enforce.lists.outside;
|
|
11
|
+
exports.password = Enforce.security.password;
|
|
12
|
+
exports.patterns = Enforce.patterns;
|
|
13
|
+
/**
|
|
14
|
+
* Check if a value is the same as a value
|
|
15
|
+
* of another property (useful for password
|
|
16
|
+
* checking).
|
|
17
|
+
**/
|
|
18
|
+
function equalToProperty(name, msg) {
|
|
19
|
+
return function (v, next) {
|
|
20
|
+
if (v === this[name]) {
|
|
21
|
+
return next();
|
|
22
|
+
}
|
|
23
|
+
return next(msg || 'not-equal-to-property');
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
exports.equalToProperty = equalToProperty;
|
|
27
|
+
;
|
|
28
|
+
/**
|
|
29
|
+
* Check if a property is unique in the collection.
|
|
30
|
+
* This can take a while because a query has to be made against the Model.
|
|
31
|
+
*
|
|
32
|
+
* Due to the async nature of node, and concurrent web server environments,
|
|
33
|
+
* an index on the database column is the only way to gurantee uniqueness.
|
|
34
|
+
*
|
|
35
|
+
* For sensibility's sake, undefined and null values are ignored for uniqueness
|
|
36
|
+
* checks.
|
|
37
|
+
*
|
|
38
|
+
* Options:
|
|
39
|
+
* ignoreCase: for postgres; mysql ignores case by default.
|
|
40
|
+
* scope: (Array) scope uniqueness to listed properties
|
|
41
|
+
**/
|
|
42
|
+
function unique(opts = {}, msg = null) {
|
|
43
|
+
for (let k in arguments) {
|
|
44
|
+
const arg = arguments[k];
|
|
45
|
+
if (typeof arg === "string") {
|
|
46
|
+
msg = arg;
|
|
47
|
+
}
|
|
48
|
+
else if (typeof arg === "object") {
|
|
49
|
+
opts = arg;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return function (v, next, ctx) {
|
|
53
|
+
if (typeof v === "undefined" || v === null) {
|
|
54
|
+
return next();
|
|
55
|
+
}
|
|
56
|
+
// Cannot process on database engines which don't support SQL syntax
|
|
57
|
+
if (!ctx.driver.isSql) {
|
|
58
|
+
return next('not-supported');
|
|
59
|
+
}
|
|
60
|
+
var chain = ctx.model.find();
|
|
61
|
+
var chainQuery = function (prop, value) {
|
|
62
|
+
var query = null;
|
|
63
|
+
if (opts.ignoreCase === true && ctx.model.properties[prop] && ctx.model.properties[prop].type === 'text') {
|
|
64
|
+
query = util.format('LOWER(%s.%s) LIKE LOWER(?)', ctx.driver.query.escapeId(ctx.model.table), ctx.driver.query.escapeId(prop));
|
|
65
|
+
chain.where(query, [value]);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
query = {};
|
|
69
|
+
query[prop] = value;
|
|
70
|
+
chain.where(query);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
var handler = function (err, records) {
|
|
74
|
+
if (err) {
|
|
75
|
+
return next();
|
|
76
|
+
}
|
|
77
|
+
if (!records || records.length === 0) {
|
|
78
|
+
return next();
|
|
79
|
+
}
|
|
80
|
+
if (records.length === 1 && records[0][ctx.model.id + ''] === this[ctx.model.id + '']) {
|
|
81
|
+
return next();
|
|
82
|
+
}
|
|
83
|
+
return next(msg || 'not-unique');
|
|
84
|
+
}.bind(this);
|
|
85
|
+
chainQuery(ctx.property, v);
|
|
86
|
+
if (opts.scope) {
|
|
87
|
+
for (let s in opts.scope) {
|
|
88
|
+
let scopeProp = opts.scope[s];
|
|
89
|
+
// In SQL unique index land, NULL values are not considered equal.
|
|
90
|
+
if (ctx.instance[scopeProp] === undefined || ctx.instance[scopeProp] === null) {
|
|
91
|
+
return next();
|
|
92
|
+
}
|
|
93
|
+
chainQuery(scopeProp, ctx.instance[scopeProp]);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
chain.all(handler);
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
exports.unique = unique;
|
|
100
|
+
;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isModelConjunctionsKey(k: string): boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.isModelConjunctionsKey = void 0;
|
|
3
|
+
const model_conjunctions_keys = ['or', 'and', 'not_or', 'not_and', 'not'];
|
|
4
|
+
function isModelConjunctionsKey(k) {
|
|
5
|
+
return model_conjunctions_keys.includes(k);
|
|
6
|
+
}
|
|
7
|
+
exports.isModelConjunctionsKey = isModelConjunctionsKey;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FxOrmInstance } from '../Typo/instance';
|
|
2
|
+
import { FxOrmModel } from '../Typo/model';
|
|
3
|
+
/**
|
|
4
|
+
* filter the Date-Type SelectQuery Property corresponding item when call find-like executor ('find', 'get', 'where')
|
|
5
|
+
* @TODO add test about i
|
|
6
|
+
*
|
|
7
|
+
* @param conds
|
|
8
|
+
*/
|
|
9
|
+
export declare function filterDate(conds: FxOrmInstance.InstanceDataPayload, m: {
|
|
10
|
+
properties: FxOrmModel.Model['allProperties'];
|
|
11
|
+
}): void;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.filterDate = void 0;
|
|
3
|
+
const util = require("util");
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
function isNumbericDate(v) {
|
|
6
|
+
if (isNaN(v))
|
|
7
|
+
return false;
|
|
8
|
+
if (typeof v === 'number')
|
|
9
|
+
return true;
|
|
10
|
+
if (typeof v === 'string') {
|
|
11
|
+
return !isNaN(parseInt(v));
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const whereCondKeys = ['val', 'from', 'to'];
|
|
16
|
+
const queryComparators = ['eq', 'ne', 'gt', 'gte', 'lt', 'lte'];
|
|
17
|
+
const ALL_FILTER_KEYS = [].concat(whereCondKeys).concat(queryComparators);
|
|
18
|
+
/**
|
|
19
|
+
* filter the Date-Type SelectQuery Property corresponding item when call find-like executor ('find', 'get', 'where')
|
|
20
|
+
* @TODO add test about i
|
|
21
|
+
*
|
|
22
|
+
* @param conds
|
|
23
|
+
*/
|
|
24
|
+
// value | FxSqlQueryComparator.ComparatorNameType
|
|
25
|
+
function filterDate(conds, m) {
|
|
26
|
+
if (typeof conds !== 'object') {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
for (let k in conds) {
|
|
30
|
+
if ((0, common_1.isModelConjunctionsKey)(k))
|
|
31
|
+
Array.isArray(conds[k]) && conds[k].forEach((item) => filterDate(item, m));
|
|
32
|
+
else {
|
|
33
|
+
let p = m.properties[k];
|
|
34
|
+
if (p && p.type === 'date') {
|
|
35
|
+
let v = conds[k];
|
|
36
|
+
if (!util.isDate(v)) {
|
|
37
|
+
if (util.isNumber(v) || util.isString(v))
|
|
38
|
+
conds[k] = new Date(isNumbericDate(v) ? parseInt(v) : v);
|
|
39
|
+
else if (util.isObject(v)) {
|
|
40
|
+
ALL_FILTER_KEYS.forEach(c => {
|
|
41
|
+
let v1 = v[c];
|
|
42
|
+
if (Array.isArray(v1)) {
|
|
43
|
+
v1.forEach((v2, i) => {
|
|
44
|
+
if (!util.isDate(v2))
|
|
45
|
+
v1[i] = new Date(v2);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
else if (v1 !== undefined && !util.isDate(v1)) {
|
|
49
|
+
v[c] = new Date(isNumbericDate(v1) ? parseInt(v1) : v1);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.filterDate = filterDate;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/// <reference types="@fibjs/enforce" />
|
|
2
|
+
import { FxDbDriverNS, IDbDriver } from "../db-driver/index";
|
|
3
|
+
import SqlQuery = require("../sql-query/Query");
|
|
4
|
+
import { FxOrmCoreCallbackNS } from "../orm-core/index";
|
|
5
|
+
import { FxOrmDb } from "./Typo/Db";
|
|
6
|
+
import { FxOrmNS } from "./Typo/ORM";
|
|
7
|
+
import { FxOrmError } from "./Typo/Error";
|
|
8
|
+
import * as Settings from "./Settings";
|
|
9
|
+
import { addAdapter } from "./Adapters";
|
|
10
|
+
import * as validators from "./Validators";
|
|
11
|
+
import * as Helpers from "./Helpers";
|
|
12
|
+
import * as singleton from "./Singleton";
|
|
13
|
+
import { ORM } from './ORM';
|
|
14
|
+
export * as Property from "./Property";
|
|
15
|
+
import './Patch/fib-cache';
|
|
16
|
+
export declare function connectSync(opts?: string | FxDbDriverNS.DBConnectionConfig): ORM;
|
|
17
|
+
export declare function connect<T extends IDbDriver.ISQLConn = any>(uri?: string | FxDbDriverNS.DBConnectionConfig, cb?: FxOrmCoreCallbackNS.ExecutionCallback<IDbDriver<T>>): ORM;
|
|
18
|
+
export { ORM } from './ORM';
|
|
19
|
+
/**
|
|
20
|
+
* @description just re-export from @fibjs/enforce for convenience, you can also use `orm.enforce` for orm instances
|
|
21
|
+
*/
|
|
22
|
+
export declare const enforce: FibjsEnforce.ExportModule;
|
|
23
|
+
export declare const settings: import("./Typo/settings").FxOrmSettings.SettingInstance;
|
|
24
|
+
export declare function use(connection: FxOrmDb.Database, proto: string, opts: FxOrmNS.IUseOptions, cb: (err: Error, db?: FxOrmNS.ORM) => void): any;
|
|
25
|
+
export { addAdapter, Helpers, validators, Settings, singleton, };
|
|
26
|
+
export declare const ErrorCodes: FxOrmError.PredefineErrorCodes;
|
|
27
|
+
export declare function definePlugin<TOpts extends object>(definition: FxOrmNS.PluginConstructFn<TOpts>): FxOrmNS.PluginConstructFn<TOpts, FxOrmNS.ORM>;
|
|
28
|
+
export declare function defineModel<T = any>(definition: (db: FxOrmNS.ORM) => T): typeof definition;
|
|
29
|
+
export type { FxOrmNS } from './Typo/ORM';
|
|
30
|
+
export type { FxOrmModel } from './Typo/model';
|
|
31
|
+
export type { FxOrmInstance } from './Typo/instance';
|
|
32
|
+
export type { FxOrmAssociation } from './Typo/assoc';
|
|
33
|
+
export type { FxOrmProperty } from './Typo/property';
|
|
34
|
+
export type { FxOrmSettings } from './Typo/settings';
|
|
35
|
+
export type { FxOrmValidators } from './Typo/Validators';
|
|
36
|
+
export type { FxOrmError } from './Typo/Error';
|
|
37
|
+
export type { FxOrmQuery } from './Typo/query';
|
|
38
|
+
export type { FxOrmDb } from './Typo/Db';
|
|
39
|
+
export type { FxOrmDMLDriver } from './Typo/DMLDriver';
|
|
40
|
+
export type { FxOrmHook } from './Typo/hook';
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated use FxOrmNS.ORM directly
|
|
43
|
+
*/
|
|
44
|
+
export type ORMInstance = FxOrmNS.ORM;
|
|
45
|
+
/** @deprecated use require('../sql-query/Query').Text instead */
|
|
46
|
+
export declare const Text: SqlQuery.FxSqlQuery.TypedQueryObjectWrapper<"text", any>;
|
|
47
|
+
/** @deprecated use require('../sql-query/Query').comparators.between instead */
|
|
48
|
+
export declare const between: SqlQuery.FxSqlQueryComparatorFunction.between;
|
|
49
|
+
/** @deprecated use require('../sql-query/Query').comparators.not_between instead */
|
|
50
|
+
export declare const not_between: SqlQuery.FxSqlQueryComparatorFunction.not_between;
|
|
51
|
+
/** @deprecated use require('../sql-query/Query').comparators.like instead */
|
|
52
|
+
export declare const like: SqlQuery.FxSqlQueryComparatorFunction.like;
|
|
53
|
+
/** @deprecated use require('../sql-query/Query').comparators.not_like instead */
|
|
54
|
+
export declare const not_like: SqlQuery.FxSqlQueryComparatorFunction.not_like;
|
|
55
|
+
/** @deprecated use require('../sql-query/Query').comparators.eq instead */
|
|
56
|
+
export declare const eq: SqlQuery.FxSqlQueryComparatorFunction.eq;
|
|
57
|
+
/** @deprecated use require('../sql-query/Query').comparators.ne instead */
|
|
58
|
+
export declare const ne: SqlQuery.FxSqlQueryComparatorFunction.ne;
|
|
59
|
+
/** @deprecated use require('../sql-query/Query').comparators.gt instead */
|
|
60
|
+
export declare const gt: SqlQuery.FxSqlQueryComparatorFunction.gt;
|
|
61
|
+
/** @deprecated use require('../sql-query/Query').comparators.gte instead */
|
|
62
|
+
export declare const gte: SqlQuery.FxSqlQueryComparatorFunction.gte;
|
|
63
|
+
/** @deprecated use require('../sql-query/Query').comparators.lt instead */
|
|
64
|
+
export declare const lt: SqlQuery.FxSqlQueryComparatorFunction.lt;
|
|
65
|
+
/** @deprecated use require('../sql-query/Query').comparators.lte instead */
|
|
66
|
+
export declare const lte: SqlQuery.FxSqlQueryComparatorFunction.lte;
|
|
67
|
+
/** @deprecated use require('../sql-query/Query').comparators.not_in instead */
|
|
68
|
+
export declare const not_in: SqlQuery.FxSqlQueryComparatorFunction.not_in;
|
package/lib/orm/index.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.not_in = exports.lte = exports.lt = exports.gte = exports.gt = exports.ne = exports.eq = exports.not_like = exports.like = exports.not_between = exports.between = exports.Text = exports.defineModel = exports.definePlugin = exports.ErrorCodes = exports.singleton = exports.Settings = exports.validators = exports.Helpers = exports.addAdapter = exports.use = exports.settings = exports.enforce = exports.ORM = exports.connect = exports.connectSync = exports.Property = void 0;
|
|
3
|
+
const events = require("events");
|
|
4
|
+
const SqlQuery = require("../sql-query/Query");
|
|
5
|
+
const Enforces = require("@fibjs/enforce");
|
|
6
|
+
const Utilities = require("./Utilities");
|
|
7
|
+
const Settings = require("./Settings");
|
|
8
|
+
exports.Settings = Settings;
|
|
9
|
+
const Adapters_1 = require("./Adapters");
|
|
10
|
+
Object.defineProperty(exports, "addAdapter", { enumerable: true, get: function () { return Adapters_1.addAdapter; } });
|
|
11
|
+
const Error_1 = require("./Error");
|
|
12
|
+
const validators = require("./Validators");
|
|
13
|
+
exports.validators = validators;
|
|
14
|
+
const Helpers = require("./Helpers");
|
|
15
|
+
exports.Helpers = Helpers;
|
|
16
|
+
const singleton = require("./Singleton");
|
|
17
|
+
exports.singleton = singleton;
|
|
18
|
+
const ORM_1 = require("./ORM");
|
|
19
|
+
exports.Property = require("./Property");
|
|
20
|
+
require("./Patch/fib-cache");
|
|
21
|
+
function isOrmLikeErrorEmitter(parsedDBDriver) {
|
|
22
|
+
return !parsedDBDriver.hasOwnProperty('host') && parsedDBDriver instanceof events.EventEmitter;
|
|
23
|
+
}
|
|
24
|
+
function connectSync(opts) {
|
|
25
|
+
Helpers.selectArgs(arguments, function (type, arg) {
|
|
26
|
+
switch (type) {
|
|
27
|
+
default:
|
|
28
|
+
opts = arg;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
const dbdriver = Helpers.buildDbDriver(opts);
|
|
33
|
+
/**
|
|
34
|
+
* @pointless
|
|
35
|
+
*/
|
|
36
|
+
if (isOrmLikeErrorEmitter(dbdriver)) {
|
|
37
|
+
const errWaitor = Utilities.getErrWaitor(true);
|
|
38
|
+
dbdriver.on('connect', (err) => {
|
|
39
|
+
errWaitor.err = err;
|
|
40
|
+
errWaitor.evt.set();
|
|
41
|
+
});
|
|
42
|
+
errWaitor.evt.wait();
|
|
43
|
+
if (errWaitor.err)
|
|
44
|
+
throw errWaitor.err;
|
|
45
|
+
return dbdriver;
|
|
46
|
+
}
|
|
47
|
+
let adapterName = dbdriver.config.protocol.replace(/:$/, '');
|
|
48
|
+
let orm;
|
|
49
|
+
const syncResult = Utilities.catchBlocking(() => {
|
|
50
|
+
const DMLDriver = (0, Adapters_1.getAdapter)(adapterName);
|
|
51
|
+
const settings = Settings.Container(Settings.defaultSettingsInstance.get('*'));
|
|
52
|
+
const driver = new DMLDriver(dbdriver.uri, null, {
|
|
53
|
+
debug: dbdriver.extend_config.debug ? dbdriver.extend_config.debug : settings.get("connection.debug"),
|
|
54
|
+
settings: settings
|
|
55
|
+
});
|
|
56
|
+
driver.connect();
|
|
57
|
+
orm = new ORM_1.ORM(adapterName, driver, settings);
|
|
58
|
+
return orm;
|
|
59
|
+
});
|
|
60
|
+
if (syncResult.error && Utilities.isDriverNotSupportedError(syncResult.error)) {
|
|
61
|
+
syncResult.error = new Error_1.default("Connection protocol not supported - have you installed the database driver for " + adapterName + "?", 'NO_SUPPORT');
|
|
62
|
+
}
|
|
63
|
+
Utilities.takeAwayResult(syncResult, { no_throw: false });
|
|
64
|
+
return orm;
|
|
65
|
+
}
|
|
66
|
+
exports.connectSync = connectSync;
|
|
67
|
+
function connect(uri, cb) {
|
|
68
|
+
let args = Array.prototype.slice.apply(arguments);
|
|
69
|
+
Helpers.selectArgs(args, function (type, arg) {
|
|
70
|
+
switch (type) {
|
|
71
|
+
case 'function':
|
|
72
|
+
cb = arg;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
args = args.filter((x) => x !== cb);
|
|
77
|
+
const syncResponse = Utilities.catchBlocking(connectSync, args);
|
|
78
|
+
let orm = null;
|
|
79
|
+
if (syncResponse.error)
|
|
80
|
+
orm = Utilities.ORM_Error(syncResponse.error, cb);
|
|
81
|
+
else
|
|
82
|
+
orm = syncResponse.result;
|
|
83
|
+
Utilities.takeAwayResult(syncResponse, {
|
|
84
|
+
// no throw it, it could be processed with event handler
|
|
85
|
+
no_throw: true,
|
|
86
|
+
callback: cb
|
|
87
|
+
});
|
|
88
|
+
process.nextTick(() => {
|
|
89
|
+
orm.emit("connect", syncResponse.error, !syncResponse.error ? orm : null);
|
|
90
|
+
});
|
|
91
|
+
return orm;
|
|
92
|
+
}
|
|
93
|
+
exports.connect = connect;
|
|
94
|
+
;
|
|
95
|
+
var ORM_2 = require("./ORM");
|
|
96
|
+
Object.defineProperty(exports, "ORM", { enumerable: true, get: function () { return ORM_2.ORM; } });
|
|
97
|
+
/**
|
|
98
|
+
* @description just re-export from @fibjs/enforce for convenience, you can also use `orm.enforce` for orm instances
|
|
99
|
+
*/
|
|
100
|
+
exports.enforce = Enforces;
|
|
101
|
+
exports.settings = Settings.defaultSettingsInstance;
|
|
102
|
+
function use(connection, proto, opts, cb) {
|
|
103
|
+
if (typeof opts === "function") {
|
|
104
|
+
cb = opts;
|
|
105
|
+
opts = {};
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
const DMLDriver = (0, Adapters_1.getAdapter)(proto);
|
|
109
|
+
const settings = Settings.Container(Settings.defaultSettingsInstance.get('*'));
|
|
110
|
+
const driver = new DMLDriver(null, connection, {
|
|
111
|
+
debug: (opts.query && opts.query.debug === 'true'),
|
|
112
|
+
settings: settings
|
|
113
|
+
});
|
|
114
|
+
return cb(null, new ORM_1.ORM(proto, driver, settings));
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
return cb(err);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.use = use;
|
|
121
|
+
;
|
|
122
|
+
/* @internal */
|
|
123
|
+
exports.ErrorCodes = Error_1.default.codes;
|
|
124
|
+
function definePlugin(definition) {
|
|
125
|
+
return definition;
|
|
126
|
+
}
|
|
127
|
+
exports.definePlugin = definePlugin;
|
|
128
|
+
function defineModel(definition) {
|
|
129
|
+
return definition;
|
|
130
|
+
}
|
|
131
|
+
exports.defineModel = defineModel;
|
|
132
|
+
/** @deprecated use require('../sql-query/Query').Text instead */
|
|
133
|
+
exports.Text = SqlQuery.Text;
|
|
134
|
+
/** @deprecated use require('../sql-query/Query').comparators.between instead */
|
|
135
|
+
exports.between = SqlQuery.comparators.between;
|
|
136
|
+
/** @deprecated use require('../sql-query/Query').comparators.not_between instead */
|
|
137
|
+
exports.not_between = SqlQuery.comparators.not_between;
|
|
138
|
+
/** @deprecated use require('../sql-query/Query').comparators.like instead */
|
|
139
|
+
exports.like = SqlQuery.comparators.like;
|
|
140
|
+
/** @deprecated use require('../sql-query/Query').comparators.not_like instead */
|
|
141
|
+
exports.not_like = SqlQuery.comparators.not_like;
|
|
142
|
+
/** @deprecated use require('../sql-query/Query').comparators.eq instead */
|
|
143
|
+
exports.eq = SqlQuery.comparators.eq;
|
|
144
|
+
/** @deprecated use require('../sql-query/Query').comparators.ne instead */
|
|
145
|
+
exports.ne = SqlQuery.comparators.ne;
|
|
146
|
+
/** @deprecated use require('../sql-query/Query').comparators.gt instead */
|
|
147
|
+
exports.gt = SqlQuery.comparators.gt;
|
|
148
|
+
/** @deprecated use require('../sql-query/Query').comparators.gte instead */
|
|
149
|
+
exports.gte = SqlQuery.comparators.gte;
|
|
150
|
+
/** @deprecated use require('../sql-query/Query').comparators.lt instead */
|
|
151
|
+
exports.lt = SqlQuery.comparators.lt;
|
|
152
|
+
/** @deprecated use require('../sql-query/Query').comparators.lte instead */
|
|
153
|
+
exports.lte = SqlQuery.comparators.lte;
|
|
154
|
+
/** @deprecated use require('../sql-query/Query').comparators.in instead */
|
|
155
|
+
module.exports.in = SqlQuery.comparators.in;
|
|
156
|
+
/** @deprecated use require('../sql-query/Query').comparators.not_in instead */
|
|
157
|
+
exports.not_in = SqlQuery.comparators.not_in;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FxOrmCoreError } from "./error";
|
|
2
|
+
export declare namespace FxOrmCoreCallbackNS {
|
|
3
|
+
interface VoidCallback<T_RESULT = any, T_THIS = any> {
|
|
4
|
+
(this: T_THIS, err?: FxOrmCoreError.ExtendedError | null): T_RESULT;
|
|
5
|
+
}
|
|
6
|
+
interface ExecutionCallback<T, T_RESULT = any, T_THIS = any> {
|
|
7
|
+
(this: T_THIS, err?: string | FxOrmCoreError.ExtendedError | FxOrmCoreError.ExtendedError[] | null, result?: T): T_RESULT;
|
|
8
|
+
}
|
|
9
|
+
interface GenericCallback<T, T_RESULT = any, T_THIS = any> {
|
|
10
|
+
(this: T_THIS, err: FxOrmCoreError.ExtendedError | null, result?: T): T_RESULT;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { FxOrmCoreCallbackNS } from "./callback";
|
|
2
|
+
export declare namespace FxOrmDialect {
|
|
3
|
+
export type EscapeArgType = string | number | boolean | Date | String | Number | RegExp | Symbol;
|
|
4
|
+
type __AlertTableOptions = {
|
|
5
|
+
comment?: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* @description DDLDialect is dialct helpers to interact with database backend,
|
|
9
|
+
* to check if database has some features, get/remove data from it, or update date in it
|
|
10
|
+
*/
|
|
11
|
+
export interface DDLDialect<TDriver extends any> {
|
|
12
|
+
hasCollection: {
|
|
13
|
+
(driver: TDriver, name: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<boolean>): void;
|
|
14
|
+
};
|
|
15
|
+
hasCollectionSync: {
|
|
16
|
+
(driver: TDriver, name: string): boolean;
|
|
17
|
+
};
|
|
18
|
+
addPrimaryKey: {
|
|
19
|
+
<T extends any = any>(driver: TDriver, tableName: string, columnName: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void;
|
|
20
|
+
};
|
|
21
|
+
addPrimaryKeySync: {
|
|
22
|
+
<T extends any = any>(driver: TDriver, tableName: string, columnName: string): T;
|
|
23
|
+
};
|
|
24
|
+
dropPrimaryKey: {
|
|
25
|
+
<T extends any = any>(driver: TDriver, tableName: string, columnName: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void;
|
|
26
|
+
};
|
|
27
|
+
dropPrimaryKeySync: {
|
|
28
|
+
<T extends any = any>(driver: TDriver, tableName: string, columnName: string): T;
|
|
29
|
+
};
|
|
30
|
+
getCollectionColumns: {
|
|
31
|
+
<T extends any = any>(driver: TDriver, name: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T[]>): void;
|
|
32
|
+
};
|
|
33
|
+
getCollectionColumnsSync: {
|
|
34
|
+
<T extends any = any>(driver: TDriver, name: string): T[];
|
|
35
|
+
};
|
|
36
|
+
createCollection: {
|
|
37
|
+
<T extends any = any>(driver: TDriver, name: string, columns: string[], keys: string[], opts?: __AlertTableOptions, cb?: FxOrmCoreCallbackNS.ExecutionCallback<T>): void;
|
|
38
|
+
};
|
|
39
|
+
createCollectionSync: {
|
|
40
|
+
<T extends any = any>(driver: TDriver, name: string, columns: string[], keys: string[], opts?: __AlertTableOptions): T;
|
|
41
|
+
};
|
|
42
|
+
dropCollection: {
|
|
43
|
+
<T extends any = any>(driver: TDriver, name: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void;
|
|
44
|
+
};
|
|
45
|
+
dropCollectionSync: {
|
|
46
|
+
<T extends any = any>(driver: TDriver, name: string): T;
|
|
47
|
+
};
|
|
48
|
+
hasCollectionColumnsSync: {
|
|
49
|
+
(driver: TDriver, name: string, column: string | string[]): boolean;
|
|
50
|
+
};
|
|
51
|
+
hasCollectionColumns: {
|
|
52
|
+
(driver: TDriver, name: string, column: string | string[], cb: FxOrmCoreCallbackNS.ExecutionCallback<boolean>): void;
|
|
53
|
+
};
|
|
54
|
+
addCollectionColumn: {
|
|
55
|
+
<T extends any = any>(driver: TDriver, name: string, column: string, after_column: string | false, cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void;
|
|
56
|
+
};
|
|
57
|
+
addCollectionColumnSync: {
|
|
58
|
+
<T extends any = any>(driver: TDriver, name: string, column: string, after_column: string | false): T;
|
|
59
|
+
};
|
|
60
|
+
renameCollectionColumn: {
|
|
61
|
+
<T extends any = any>(driver: TDriver, name: string, oldColName: string, newColName: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void;
|
|
62
|
+
};
|
|
63
|
+
renameCollectionColumnSync: {
|
|
64
|
+
<T extends any = any>(driver: TDriver, name: string, oldColName: string, newColName: string): T;
|
|
65
|
+
};
|
|
66
|
+
modifyCollectionColumn: {
|
|
67
|
+
<T extends any = any>(driver: TDriver, name: string, column: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void;
|
|
68
|
+
};
|
|
69
|
+
modifyCollectionColumnSync: {
|
|
70
|
+
<T extends any = any>(driver: TDriver, name: string, column: string): T;
|
|
71
|
+
};
|
|
72
|
+
dropCollectionColumn: {
|
|
73
|
+
<T extends any = any>(driver: TDriver, name: string, column: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void;
|
|
74
|
+
};
|
|
75
|
+
dropCollectionColumnSync: {
|
|
76
|
+
<T extends any = any>(driver: TDriver, name: string, column: string): T;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export {};
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare namespace FxOrmCoreError {
|
|
2
|
+
interface ExtendedError extends Error {
|
|
3
|
+
code?: number | string;
|
|
4
|
+
[ext: string]: any;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
import type { FxOrmCoreCallbackNS } from "./callback";
|
|
8
|
+
import type { FxOrmCoreSyncNS } from "./sync";
|
|
9
|
+
export declare function catchBlocking<T = any>(executor: Function, args?: any[], opts?: {
|
|
10
|
+
thisArg?: any;
|
|
11
|
+
}): FxOrmCoreSyncNS.ExposedResult<T>;
|
|
12
|
+
export declare function takeAwayResult<RESULT_T = any>(input: FxOrmCoreSyncNS.ExposedResult<RESULT_T>, opts?: {
|
|
13
|
+
callback?: FxOrmCoreCallbackNS.ExecutionCallback<any, RESULT_T>;
|
|
14
|
+
use_tick?: boolean;
|
|
15
|
+
no_throw?: boolean;
|
|
16
|
+
}): void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.takeAwayResult = exports.catchBlocking = void 0;
|
|
3
|
+
function catchBlocking(executor, args, opts) {
|
|
4
|
+
let error, result;
|
|
5
|
+
const { thisArg = null } = opts || {};
|
|
6
|
+
try {
|
|
7
|
+
result = executor.apply(thisArg, args);
|
|
8
|
+
}
|
|
9
|
+
catch (ex) {
|
|
10
|
+
error = ex;
|
|
11
|
+
}
|
|
12
|
+
return { error, result };
|
|
13
|
+
}
|
|
14
|
+
exports.catchBlocking = catchBlocking;
|
|
15
|
+
function takeAwayResult(input, opts) {
|
|
16
|
+
const { use_tick = false, callback = null, } = opts || {};
|
|
17
|
+
const isFunc = typeof callback === 'function';
|
|
18
|
+
const { no_throw = isFunc } = opts || {};
|
|
19
|
+
if (!no_throw && input.error)
|
|
20
|
+
throw input.error;
|
|
21
|
+
if (isFunc)
|
|
22
|
+
if (use_tick)
|
|
23
|
+
process.nextTick(() => {
|
|
24
|
+
callback(input.error, input.result);
|
|
25
|
+
});
|
|
26
|
+
else
|
|
27
|
+
callback(input.error, input.result);
|
|
28
|
+
}
|
|
29
|
+
exports.takeAwayResult = takeAwayResult;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export import Utils = require('./utils');
|
|
2
|
+
export type { FxOrmCoreCallbackNS } from './callback';
|
|
3
|
+
export type { FxOrmCoreSyncNS } from './sync';
|
|
4
|
+
export type { FxOrmCoreError } from './error';
|
|
5
|
+
export type { FxOrmDialect } from './dialect';
|
|
6
|
+
export { catchBlocking, takeAwayResult, } from './error';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.takeAwayResult = exports.catchBlocking = void 0;
|
|
3
|
+
exports.Utils = require("./utils");
|
|
4
|
+
var error_1 = require("./error");
|
|
5
|
+
Object.defineProperty(exports, "catchBlocking", { enumerable: true, get: function () { return error_1.catchBlocking; } });
|
|
6
|
+
Object.defineProperty(exports, "takeAwayResult", { enumerable: true, get: function () { return error_1.takeAwayResult; } });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FxOrmCoreCallbackNS } from "./callback";
|
|
2
|
+
import type { FxOrmCoreError } from "./error";
|
|
3
|
+
export declare namespace FxOrmCoreSyncNS {
|
|
4
|
+
interface ExposedResult<T = any> {
|
|
5
|
+
error: FxOrmCoreError.ExtendedError;
|
|
6
|
+
result?: T;
|
|
7
|
+
}
|
|
8
|
+
interface SyncCallbackInputArags<T = any> {
|
|
9
|
+
callback?: FxOrmCoreCallbackNS.ExecutionCallback<T>;
|
|
10
|
+
is_sync?: boolean;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { catchBlocking as exposeErrAndResultFromSyncMethod, takeAwayResult as throwErrOrCallabckErrResult } from "./error";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.throwErrOrCallabckErrResult = exports.exposeErrAndResultFromSyncMethod = void 0;
|
|
3
|
+
var error_1 = require("./error");
|
|
4
|
+
Object.defineProperty(exports, "exposeErrAndResultFromSyncMethod", { enumerable: true, get: function () { return error_1.catchBlocking; } });
|
|
5
|
+
Object.defineProperty(exports, "throwErrOrCallabckErrResult", { enumerable: true, get: function () { return error_1.takeAwayResult; } });
|