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
package/lib/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const vm = require("vm");
|
|
4
|
-
const patch = require('./patch');
|
|
5
|
-
const sbox = new vm.SandBox({
|
|
6
|
-
util: require('util'),
|
|
7
|
-
events: require('events'),
|
|
8
|
-
url: require('url'),
|
|
9
|
-
sqlite3: require('./modules/sqlite3'),
|
|
10
|
-
mysql: require('./modules/mysql')
|
|
11
|
-
});
|
|
12
|
-
const orm = sbox.require('orm', __filename);
|
|
13
|
-
module.exports = patch(orm);
|
package/lib/modules/mysql.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/// <reference path="index.d.ts" />
|
|
3
|
-
/// <reference path="../../@types/index.d.ts" />
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
const db = require("db");
|
|
6
|
-
class Database {
|
|
7
|
-
constructor(connOpts) {
|
|
8
|
-
this.opts = connOpts;
|
|
9
|
-
}
|
|
10
|
-
on(ev) { }
|
|
11
|
-
ping(cb) {
|
|
12
|
-
setImmediate(cb);
|
|
13
|
-
}
|
|
14
|
-
connect(cb) {
|
|
15
|
-
const that = this;
|
|
16
|
-
const openMySQL = db.openMySQL;
|
|
17
|
-
openMySQL(this.opts, function (e, conn) {
|
|
18
|
-
if (!e)
|
|
19
|
-
that.conn = conn;
|
|
20
|
-
cb(e);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
query(sql, cb) {
|
|
24
|
-
this.conn.execute(sql, cb);
|
|
25
|
-
}
|
|
26
|
-
execute(sql) {
|
|
27
|
-
return this.conn.execute(sql);
|
|
28
|
-
}
|
|
29
|
-
end(cb) {
|
|
30
|
-
this.conn.close(cb);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.createConnection = function (connOpts) {
|
|
34
|
-
return new Database(connOpts);
|
|
35
|
-
};
|
package/lib/modules/sqlite3.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/// <reference path="index.d.ts" />
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const db = require("db");
|
|
5
|
-
class Database {
|
|
6
|
-
constructor(fname) {
|
|
7
|
-
this.conn = db.openSQLite(fname);
|
|
8
|
-
}
|
|
9
|
-
on(ev) { }
|
|
10
|
-
all(sql, cb) {
|
|
11
|
-
this.conn.execute(sql, cb);
|
|
12
|
-
}
|
|
13
|
-
get(sql, cb) {
|
|
14
|
-
this.all(sql, function (e, r) {
|
|
15
|
-
if (e)
|
|
16
|
-
cb(e);
|
|
17
|
-
cb(e, r[0]);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
execute(sql) {
|
|
21
|
-
return this.conn.execute(sql);
|
|
22
|
-
}
|
|
23
|
-
close() {
|
|
24
|
-
this.conn.close();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.Database = Database;
|
package/lib/patch.js
DELETED
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/// <reference path="../@types/index.d.ts" />
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const util = require("util");
|
|
5
|
-
const url = require("url");
|
|
6
|
-
// patch async function to sync function
|
|
7
|
-
function patchSync(o, funcs) {
|
|
8
|
-
funcs.forEach(function (func) {
|
|
9
|
-
const old_func = o[func];
|
|
10
|
-
if (old_func) {
|
|
11
|
-
Object.defineProperty(o, func + 'Sync', {
|
|
12
|
-
value: util.sync(old_func),
|
|
13
|
-
writable: true
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
// hook find, patch result
|
|
19
|
-
function patchResult(o) {
|
|
20
|
-
var old_func = o.find;
|
|
21
|
-
var m = o.model || o;
|
|
22
|
-
var comps = ['val', 'from', 'to'];
|
|
23
|
-
if (old_func.is_new)
|
|
24
|
-
return;
|
|
25
|
-
/**
|
|
26
|
-
* filter the Date-Type SelectQuery Property corresponding item when call find-like executor ('find', 'get', 'where')
|
|
27
|
-
* @param opt
|
|
28
|
-
*/
|
|
29
|
-
function filter_date(opt) {
|
|
30
|
-
for (var k in opt) {
|
|
31
|
-
if (k === 'or')
|
|
32
|
-
opt[k].forEach(filter_date);
|
|
33
|
-
else {
|
|
34
|
-
var p = m.allProperties[k];
|
|
35
|
-
if (p && p.type === 'date') {
|
|
36
|
-
var v = opt[k];
|
|
37
|
-
if (!util.isDate(v)) {
|
|
38
|
-
if (util.isNumber(v) || util.isString(v))
|
|
39
|
-
opt[k] = new Date(v);
|
|
40
|
-
else if (util.isObject(v)) {
|
|
41
|
-
comps.forEach(c => {
|
|
42
|
-
var v1 = v[c];
|
|
43
|
-
if (util.isArray(v1)) {
|
|
44
|
-
v1.forEach((v2, i) => {
|
|
45
|
-
if (!util.isDate(v2))
|
|
46
|
-
v1[i] = new Date(v2);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
else if (v1 !== undefined && !util.isDate(v1)) {
|
|
50
|
-
v[c] = new Date(v1);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
var new_func = function () {
|
|
60
|
-
var opt = arguments[0];
|
|
61
|
-
if (util.isObject(opt) && !util.isFunction(opt)) {
|
|
62
|
-
/** filter opt to make Date-Type SelectQuery Property corresponding item */
|
|
63
|
-
filter_date(opt);
|
|
64
|
-
}
|
|
65
|
-
var rs = old_func.apply(this, Array.prototype.slice.apply(arguments));
|
|
66
|
-
if (rs) {
|
|
67
|
-
patchResult(rs);
|
|
68
|
-
patchSync(rs, [
|
|
69
|
-
"count",
|
|
70
|
-
"first",
|
|
71
|
-
"last",
|
|
72
|
-
'all',
|
|
73
|
-
'where',
|
|
74
|
-
'find',
|
|
75
|
-
'remove',
|
|
76
|
-
'run'
|
|
77
|
-
]);
|
|
78
|
-
}
|
|
79
|
-
return rs;
|
|
80
|
-
};
|
|
81
|
-
new_func.is_new = true;
|
|
82
|
-
o.where = o.all = o.find = new_func;
|
|
83
|
-
}
|
|
84
|
-
function patchObject(m) {
|
|
85
|
-
var methods = [
|
|
86
|
-
"save",
|
|
87
|
-
"remove",
|
|
88
|
-
"validate",
|
|
89
|
-
"model"
|
|
90
|
-
];
|
|
91
|
-
function enum_associations(assoc) {
|
|
92
|
-
assoc.forEach(function (item) {
|
|
93
|
-
if (item.getAccessor)
|
|
94
|
-
methods.push(item.getAccessor);
|
|
95
|
-
if (item.setAccessor)
|
|
96
|
-
methods.push(item.setAccessor);
|
|
97
|
-
if (item.hasAccessor)
|
|
98
|
-
methods.push(item.hasAccessor);
|
|
99
|
-
if (item.delAccessor)
|
|
100
|
-
methods.push(item.delAccessor);
|
|
101
|
-
if (item.addAccessor)
|
|
102
|
-
methods.push(item.addAccessor);
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
// patch associations methods
|
|
106
|
-
var opts = m.__opts;
|
|
107
|
-
if (opts) {
|
|
108
|
-
enum_associations(opts.one_associations);
|
|
109
|
-
enum_associations(opts.many_associations);
|
|
110
|
-
enum_associations(opts.extend_associations);
|
|
111
|
-
enum_associations(opts.association_properties);
|
|
112
|
-
for (var f in opts.fieldToPropertyMap) {
|
|
113
|
-
if (opts.fieldToPropertyMap[f].lazyload) {
|
|
114
|
-
var name = f.charAt(0).toUpperCase() + f.slice(1);
|
|
115
|
-
methods.push('get' + name);
|
|
116
|
-
methods.push('set' + name);
|
|
117
|
-
methods.push('remove' + name);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
;
|
|
121
|
-
}
|
|
122
|
-
patchSync(m, methods);
|
|
123
|
-
}
|
|
124
|
-
function patchHas(m, funcs) {
|
|
125
|
-
funcs.forEach(function (func) {
|
|
126
|
-
var old_func = m[func];
|
|
127
|
-
if (old_func)
|
|
128
|
-
m[func] = function () {
|
|
129
|
-
var r = old_func.apply(this, Array.prototype.slice.apply(arguments));
|
|
130
|
-
var name = arguments[0];
|
|
131
|
-
name = 'findBy' + name.charAt(0).toUpperCase() + name.slice(1);
|
|
132
|
-
patchSync(this, [name]);
|
|
133
|
-
return r;
|
|
134
|
-
};
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
function patchAggregate(m) {
|
|
138
|
-
var aggregate = m.aggregate;
|
|
139
|
-
m.aggregate = function () {
|
|
140
|
-
var r = aggregate.apply(this, Array.prototype.slice.apply(arguments));
|
|
141
|
-
patchSync(r, ['get']);
|
|
142
|
-
return r;
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
function patchModel(m, opts) {
|
|
146
|
-
var _afterAutoFetch;
|
|
147
|
-
if (opts !== undefined && opts.hooks)
|
|
148
|
-
_afterAutoFetch = opts.hooks.afterAutoFetch;
|
|
149
|
-
m.afterAutoFetch(function (next) {
|
|
150
|
-
patchObject(this);
|
|
151
|
-
if (_afterAutoFetch) {
|
|
152
|
-
if (_afterAutoFetch.length > 0)
|
|
153
|
-
return _afterAutoFetch(next);
|
|
154
|
-
_afterAutoFetch();
|
|
155
|
-
}
|
|
156
|
-
next();
|
|
157
|
-
});
|
|
158
|
-
patchResult(m);
|
|
159
|
-
patchSync(m, [
|
|
160
|
-
"clear",
|
|
161
|
-
"count",
|
|
162
|
-
"exists",
|
|
163
|
-
"one",
|
|
164
|
-
"where",
|
|
165
|
-
'all',
|
|
166
|
-
'create',
|
|
167
|
-
'drop',
|
|
168
|
-
'find',
|
|
169
|
-
'get',
|
|
170
|
-
'sync'
|
|
171
|
-
]);
|
|
172
|
-
patchHas(m, [
|
|
173
|
-
'hasOne',
|
|
174
|
-
'extendsTo'
|
|
175
|
-
]);
|
|
176
|
-
patchAggregate(m);
|
|
177
|
-
}
|
|
178
|
-
function patchInsert(table, data, keyProperties, cb) {
|
|
179
|
-
var q = this.query.insert()
|
|
180
|
-
.into(table)
|
|
181
|
-
.set(data)
|
|
182
|
-
.build();
|
|
183
|
-
this.db.all(q, function (err, info) {
|
|
184
|
-
if (err)
|
|
185
|
-
return cb(err);
|
|
186
|
-
if (!keyProperties)
|
|
187
|
-
return cb(null);
|
|
188
|
-
var i, ids = {}, prop;
|
|
189
|
-
if (keyProperties.length == 1 && keyProperties[0].type == 'serial') {
|
|
190
|
-
ids[keyProperties[0].name] = info.insertId;
|
|
191
|
-
return cb(null, ids);
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
for (i = 0; i < keyProperties.length; i++) {
|
|
195
|
-
prop = keyProperties[i];
|
|
196
|
-
// Zero is a valid value for an ID column
|
|
197
|
-
ids[prop.name] = data[prop.mapsTo] !== undefined ? data[prop.mapsTo] : null;
|
|
198
|
-
}
|
|
199
|
-
return cb(null, ids);
|
|
200
|
-
}
|
|
201
|
-
}.bind(this));
|
|
202
|
-
}
|
|
203
|
-
;
|
|
204
|
-
function patchDriver(driver) {
|
|
205
|
-
if (driver.dialect === 'sqlite')
|
|
206
|
-
driver.insert = patchInsert;
|
|
207
|
-
var propertyToValue = driver.propertyToValue;
|
|
208
|
-
driver.propertyToValue = function (value, property) {
|
|
209
|
-
if (property.type === 'date' &&
|
|
210
|
-
(util.isNumber(value) || util.isString(value)))
|
|
211
|
-
value = new Date(value);
|
|
212
|
-
return propertyToValue.call(this, value, property);
|
|
213
|
-
};
|
|
214
|
-
var valueToProperty = driver.valueToProperty;
|
|
215
|
-
driver.valueToProperty = function (value, property) {
|
|
216
|
-
if (property.type === 'date' &&
|
|
217
|
-
(util.isNumber(value) || util.isString(value)))
|
|
218
|
-
value = new Date(value);
|
|
219
|
-
return valueToProperty.call(this, value, property);
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
function execQuerySync(query, opt) {
|
|
223
|
-
if (arguments.length == 2)
|
|
224
|
-
query = this.query.escape(query, opt);
|
|
225
|
-
return this.db.execute(query);
|
|
226
|
-
}
|
|
227
|
-
module.exports = function (orm) {
|
|
228
|
-
var conn = util.sync(orm.connect);
|
|
229
|
-
orm.connectSync = function (opts) {
|
|
230
|
-
if (typeof opts == 'string')
|
|
231
|
-
opts = url.parse(opts, true).toJSON();
|
|
232
|
-
else if (typeof opts == 'object')
|
|
233
|
-
opts = util.clone(opts);
|
|
234
|
-
if (opts.protocol === 'sqlite:' && opts.timezone === undefined)
|
|
235
|
-
opts.timezone = 'UTC';
|
|
236
|
-
var db = conn.call(this, opts);
|
|
237
|
-
patchSync(db, [
|
|
238
|
-
'sync',
|
|
239
|
-
'close',
|
|
240
|
-
'drop',
|
|
241
|
-
'ping'
|
|
242
|
-
]);
|
|
243
|
-
patchDriver(db.driver);
|
|
244
|
-
var def = db.define;
|
|
245
|
-
db.define = function (name, properties, opts) {
|
|
246
|
-
if (opts !== undefined) {
|
|
247
|
-
opts = util.clone(opts);
|
|
248
|
-
if (opts.hooks !== undefined)
|
|
249
|
-
opts.hooks = util.clone(opts.hooks);
|
|
250
|
-
}
|
|
251
|
-
var m = def.call(this, name, properties, opts);
|
|
252
|
-
patchModel(m, opts);
|
|
253
|
-
return m;
|
|
254
|
-
};
|
|
255
|
-
db.begin = function () {
|
|
256
|
-
return this.driver.db.conn.begin();
|
|
257
|
-
};
|
|
258
|
-
db.commit = function () {
|
|
259
|
-
return this.driver.db.conn.commit();
|
|
260
|
-
};
|
|
261
|
-
db.rollback = function () {
|
|
262
|
-
return this.driver.db.conn.rollback();
|
|
263
|
-
};
|
|
264
|
-
db.trans = function (func) {
|
|
265
|
-
return this.driver.db.conn.trans(func);
|
|
266
|
-
};
|
|
267
|
-
db.driver.execQuerySync = execQuerySync;
|
|
268
|
-
return db;
|
|
269
|
-
};
|
|
270
|
-
return orm;
|
|
271
|
-
};
|