fib-orm 1.4.1 → 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 -193
- 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,74 @@
|
|
|
1
|
+
/// <reference types="@fibjs/types" />
|
|
2
|
+
const util = require("util");
|
|
3
|
+
const helpers = require("../Helpers");
|
|
4
|
+
const DataTypes = {
|
|
5
|
+
id: 'INT IDENTITY(1,1) NOT NULL PRIMARY KEY',
|
|
6
|
+
int: 'INTEGER',
|
|
7
|
+
float: 'DOUBLE',
|
|
8
|
+
bool: 'BIT',
|
|
9
|
+
text: 'TEXT'
|
|
10
|
+
};
|
|
11
|
+
const escape = function (query, args) {
|
|
12
|
+
return helpers.escapeQuery(Dialect, query, args);
|
|
13
|
+
};
|
|
14
|
+
const escapeId = function (...args) {
|
|
15
|
+
return args.map(function (el) {
|
|
16
|
+
if (typeof el == "object") {
|
|
17
|
+
return el.str.replace(/\?:(id|value)/g, function (m) {
|
|
18
|
+
if (m == "?:id") {
|
|
19
|
+
return escapeId(el.escapes.shift());
|
|
20
|
+
}
|
|
21
|
+
return escapeVal(el.escapes.shift());
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return el.split(".").map(function (ele) {
|
|
25
|
+
return "\"" + ele.replace(/\"/g, "\"\"") + "\"";
|
|
26
|
+
}).join(".");
|
|
27
|
+
}).join(".");
|
|
28
|
+
};
|
|
29
|
+
const escapeVal = function (val, timeZone) {
|
|
30
|
+
if (val === undefined || val === null || typeof val === "symbol") {
|
|
31
|
+
return 'NULL';
|
|
32
|
+
}
|
|
33
|
+
if (Array.isArray(val)) {
|
|
34
|
+
if (val.length === 1 && Array.isArray(val[0])) {
|
|
35
|
+
return "(" + val[0].map(escapeVal.bind(this)) + ")";
|
|
36
|
+
}
|
|
37
|
+
return "(" + val.map(escapeVal.bind(this)).join(", ") + ")";
|
|
38
|
+
}
|
|
39
|
+
if (util.isDate(val)) {
|
|
40
|
+
return "'" + helpers.dateToString(val, timeZone || "local", { dialect: 'dm' }) + "'";
|
|
41
|
+
}
|
|
42
|
+
if (Buffer.isBuffer(val)) {
|
|
43
|
+
return helpers.bufferToString(val, 'dm');
|
|
44
|
+
}
|
|
45
|
+
switch (typeof val) {
|
|
46
|
+
case "number":
|
|
47
|
+
if (!isFinite(val)) {
|
|
48
|
+
val = val.toString();
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
return val.toString();
|
|
52
|
+
case "boolean":
|
|
53
|
+
return val ? "1" : "0";
|
|
54
|
+
case "function":
|
|
55
|
+
return val(Dialect);
|
|
56
|
+
case "string":
|
|
57
|
+
break;
|
|
58
|
+
case "bigint":
|
|
59
|
+
return val.toString();
|
|
60
|
+
default:
|
|
61
|
+
val = JSON.stringify(val);
|
|
62
|
+
}
|
|
63
|
+
return "'" + val.replace(/\'/g, "''") + "'";
|
|
64
|
+
};
|
|
65
|
+
const Dialect = {
|
|
66
|
+
type: 'dm',
|
|
67
|
+
DataTypes,
|
|
68
|
+
escape,
|
|
69
|
+
escapeId,
|
|
70
|
+
escapeVal,
|
|
71
|
+
limitAsTop: false,
|
|
72
|
+
knex: null
|
|
73
|
+
};
|
|
74
|
+
module.exports = Dialect;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as mysql from './mysql';
|
|
2
|
+
export { mysql };
|
|
3
|
+
import * as postgresql from './postgresql';
|
|
4
|
+
export { postgresql };
|
|
5
|
+
import * as sqlite from './sqlite';
|
|
6
|
+
export { sqlite };
|
|
7
|
+
import * as mssql from './mssql';
|
|
8
|
+
export { mssql };
|
|
9
|
+
import * as dm from './dm';
|
|
10
|
+
export { dm };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.dm = exports.mssql = exports.sqlite = exports.postgresql = exports.mysql = void 0;
|
|
3
|
+
const mysql = require("./mysql");
|
|
4
|
+
exports.mysql = mysql;
|
|
5
|
+
const postgresql = require("./postgresql");
|
|
6
|
+
exports.postgresql = postgresql;
|
|
7
|
+
const sqlite = require("./sqlite");
|
|
8
|
+
exports.sqlite = sqlite;
|
|
9
|
+
const mssql = require("./mssql");
|
|
10
|
+
exports.mssql = mssql;
|
|
11
|
+
const dm = require("./dm");
|
|
12
|
+
exports.dm = dm;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/// <reference types="@fibjs/types" />
|
|
2
|
+
const util = require("util");
|
|
3
|
+
const helpers = require("../Helpers");
|
|
4
|
+
const DataTypes = {
|
|
5
|
+
id: 'INT IDENTITY(1,1) NOT NULL PRIMARY KEY',
|
|
6
|
+
int: 'INT',
|
|
7
|
+
float: 'FLOAT',
|
|
8
|
+
bool: 'BIT',
|
|
9
|
+
text: 'TEXT'
|
|
10
|
+
};
|
|
11
|
+
const escape = function (query, args) {
|
|
12
|
+
return helpers.escapeQuery(Dialect, query, args);
|
|
13
|
+
};
|
|
14
|
+
function escapeId(...els) {
|
|
15
|
+
return els.map(function (el) {
|
|
16
|
+
if (typeof el == "object") {
|
|
17
|
+
return el.str.replace(/\?:(id|value)/g, function (m) {
|
|
18
|
+
if (m == "?:id") {
|
|
19
|
+
return escapeId(el.escapes.shift());
|
|
20
|
+
}
|
|
21
|
+
return escapeVal(el.escapes.shift());
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return "[" + el + "]";
|
|
25
|
+
}).join(".");
|
|
26
|
+
}
|
|
27
|
+
;
|
|
28
|
+
const escapeVal = function (val, timeZone) {
|
|
29
|
+
if (val === undefined || val === null || typeof val === "symbol") {
|
|
30
|
+
return 'NULL';
|
|
31
|
+
}
|
|
32
|
+
if (Array.isArray(val)) {
|
|
33
|
+
if (val.length === 1 && Array.isArray(val[0])) {
|
|
34
|
+
return "(" + val[0].map(escapeVal.bind(this)) + ")";
|
|
35
|
+
}
|
|
36
|
+
return "(" + val.map(escapeVal.bind(this)).join(", ") + ")";
|
|
37
|
+
}
|
|
38
|
+
if (util.isDate(val)) {
|
|
39
|
+
return "'" + helpers.dateToString(val, timeZone || "local", { dialect: 'mssql' }) + "'";
|
|
40
|
+
}
|
|
41
|
+
if (Buffer.isBuffer(val)) {
|
|
42
|
+
return helpers.bufferToString(val, 'mssql');
|
|
43
|
+
}
|
|
44
|
+
switch (typeof val) {
|
|
45
|
+
case "number":
|
|
46
|
+
if (!isFinite(val)) {
|
|
47
|
+
val = val.toString();
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
return val;
|
|
51
|
+
case "boolean":
|
|
52
|
+
return val ? 1 : 0;
|
|
53
|
+
case "function":
|
|
54
|
+
return val(Dialect);
|
|
55
|
+
case "string":
|
|
56
|
+
break;
|
|
57
|
+
case "bigint":
|
|
58
|
+
return val.toString();
|
|
59
|
+
default:
|
|
60
|
+
val = JSON.stringify(val);
|
|
61
|
+
}
|
|
62
|
+
return "'" + val.replace(/\'/g, "''") + "'";
|
|
63
|
+
};
|
|
64
|
+
const Dialect = {
|
|
65
|
+
type: 'mssql',
|
|
66
|
+
DataTypes,
|
|
67
|
+
escape,
|
|
68
|
+
escapeId,
|
|
69
|
+
escapeVal,
|
|
70
|
+
limitAsTop: true,
|
|
71
|
+
knex: null
|
|
72
|
+
};
|
|
73
|
+
module.exports = Dialect;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/// <reference types="@fibjs/types" />
|
|
2
|
+
const util = require("util");
|
|
3
|
+
const helpers = require("../Helpers");
|
|
4
|
+
const DataTypes = {
|
|
5
|
+
id: 'INTEGER PRIMARY KEY AUTO_INCREMENT',
|
|
6
|
+
int: 'INTEGER',
|
|
7
|
+
float: 'FLOAT(12,2)',
|
|
8
|
+
bool: 'TINYINT(1)',
|
|
9
|
+
text: 'TEXT'
|
|
10
|
+
};
|
|
11
|
+
function escape(query, args) {
|
|
12
|
+
return helpers.escapeQuery(Dialect, query, args);
|
|
13
|
+
}
|
|
14
|
+
function escapeId(...els) {
|
|
15
|
+
return els.map(function (el) {
|
|
16
|
+
if (typeof el == "object") {
|
|
17
|
+
return el.str.replace(/\?:(id|value)/g, function (m) {
|
|
18
|
+
if (m == "?:id") {
|
|
19
|
+
return escapeId(el.escapes.shift());
|
|
20
|
+
}
|
|
21
|
+
return escapeVal(el.escapes.shift());
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return "`" + el.replace(/`/g, '``') + "`";
|
|
25
|
+
}).join(".");
|
|
26
|
+
}
|
|
27
|
+
;
|
|
28
|
+
function escapeVal(val, timeZone) {
|
|
29
|
+
if (val === undefined || val === null || typeof val === "symbol") {
|
|
30
|
+
return 'NULL';
|
|
31
|
+
}
|
|
32
|
+
if (Buffer.isBuffer(val)) {
|
|
33
|
+
return helpers.bufferToString(val, 'mysql');
|
|
34
|
+
}
|
|
35
|
+
if (Array.isArray(val)) {
|
|
36
|
+
return arrayToList(val, timeZone || "local");
|
|
37
|
+
}
|
|
38
|
+
if (util.isDate(val)) {
|
|
39
|
+
val = helpers.dateToString(val, timeZone || "local", { dialect: 'mysql' });
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
switch (typeof val) {
|
|
43
|
+
case 'boolean':
|
|
44
|
+
return (val) ? 'true' : 'false';
|
|
45
|
+
case 'number':
|
|
46
|
+
if (!isFinite(val)) {
|
|
47
|
+
val = val.toString();
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
return val + '';
|
|
51
|
+
case "object":
|
|
52
|
+
return objectToValues(val, timeZone || "Z");
|
|
53
|
+
case "function":
|
|
54
|
+
return val(Dialect);
|
|
55
|
+
case 'bigint':
|
|
56
|
+
return val.toString();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
val = val.replace(/[\0\n\r\b\t\\\'\"\x1a]/g, function (s) {
|
|
60
|
+
switch (s) {
|
|
61
|
+
case "\0": return "\\0";
|
|
62
|
+
case "\n": return "\\n";
|
|
63
|
+
case "\r": return "\\r";
|
|
64
|
+
case "\b": return "\\b";
|
|
65
|
+
case "\t": return "\\t";
|
|
66
|
+
case "\x1a": return "\\Z";
|
|
67
|
+
default: return "\\" + s;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return "'" + val + "'";
|
|
71
|
+
}
|
|
72
|
+
;
|
|
73
|
+
function objectToValues(object, timeZone) {
|
|
74
|
+
var values = [];
|
|
75
|
+
for (var key in object) {
|
|
76
|
+
var value = object[key];
|
|
77
|
+
if (typeof value === 'function') {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
values.push(escapeId(key) + ' = ' + escapeVal(value, timeZone));
|
|
81
|
+
}
|
|
82
|
+
return values.join(', ');
|
|
83
|
+
}
|
|
84
|
+
function arrayToList(array, timeZone) {
|
|
85
|
+
return "(" + array.map(function (v) {
|
|
86
|
+
if (Array.isArray(v))
|
|
87
|
+
return arrayToList(v);
|
|
88
|
+
return escapeVal(v, timeZone);
|
|
89
|
+
}).join(', ') + ")";
|
|
90
|
+
}
|
|
91
|
+
const Dialect = {
|
|
92
|
+
type: 'mysql',
|
|
93
|
+
DataTypes,
|
|
94
|
+
escape,
|
|
95
|
+
escapeId,
|
|
96
|
+
escapeVal,
|
|
97
|
+
limitAsTop: false,
|
|
98
|
+
knex: null
|
|
99
|
+
};
|
|
100
|
+
module.exports = Dialect;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const util = require("util");
|
|
2
|
+
const helpers = require("../Helpers");
|
|
3
|
+
const DataTypes = {
|
|
4
|
+
id: 'SERIAL PRIMARY KEY',
|
|
5
|
+
int: 'INTEGER',
|
|
6
|
+
float: 'REAL',
|
|
7
|
+
bool: 'SMALLINT',
|
|
8
|
+
text: 'TEXT'
|
|
9
|
+
};
|
|
10
|
+
const escape = function (query, args) {
|
|
11
|
+
return helpers.escapeQuery(Dialect, query, args);
|
|
12
|
+
};
|
|
13
|
+
const escapeId = function (...args) {
|
|
14
|
+
return args.map(function (el) {
|
|
15
|
+
if (typeof el == "object") {
|
|
16
|
+
return el.str.replace(/\?:(id|value)/g, function (m) {
|
|
17
|
+
if (m == "?:id") {
|
|
18
|
+
return escapeId(el.escapes.shift());
|
|
19
|
+
}
|
|
20
|
+
// ?:value
|
|
21
|
+
return escapeVal(el.escapes.shift());
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return el.split(".").map(function (ele) { return "\"" + ele.replace(/\"/g, "\"\"") + "\""; }).join(".");
|
|
25
|
+
}).join(".");
|
|
26
|
+
};
|
|
27
|
+
const escapeVal = function (val, timeZone) {
|
|
28
|
+
if (val === undefined || val === null || typeof val === "symbol") {
|
|
29
|
+
return 'NULL';
|
|
30
|
+
}
|
|
31
|
+
if (Array.isArray(val)) {
|
|
32
|
+
if (val.length === 1 && Array.isArray(val[0])) {
|
|
33
|
+
return "(" + val[0].map(escapeVal.bind(this)) + ")";
|
|
34
|
+
}
|
|
35
|
+
return "(" + val.map(escapeVal.bind(this)).join(", ") + ")";
|
|
36
|
+
}
|
|
37
|
+
if (util.isDate(val)) {
|
|
38
|
+
return "'" + helpers.dateToString(val, timeZone || "local", { dialect: 'postgresql' }) + "'";
|
|
39
|
+
}
|
|
40
|
+
if (Buffer.isBuffer(val)) {
|
|
41
|
+
return helpers.bufferToString(val, 'postgresql');
|
|
42
|
+
}
|
|
43
|
+
switch (typeof val) {
|
|
44
|
+
case "number":
|
|
45
|
+
if (!isFinite(val)) {
|
|
46
|
+
val = val.toString();
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
return val.toString();
|
|
50
|
+
case "boolean":
|
|
51
|
+
return val ? "true" : "false";
|
|
52
|
+
case "function":
|
|
53
|
+
return val(exports);
|
|
54
|
+
case "string":
|
|
55
|
+
break;
|
|
56
|
+
case "bigint":
|
|
57
|
+
return val.toString();
|
|
58
|
+
default:
|
|
59
|
+
val = JSON.stringify(val);
|
|
60
|
+
}
|
|
61
|
+
// No need to escape backslashes with default PostgreSQL 9.1+ config.
|
|
62
|
+
// Google 'postgresql standard_conforming_strings' for details.
|
|
63
|
+
return "'" + val.replace(/\'/g, "''") + "'";
|
|
64
|
+
};
|
|
65
|
+
const defaultValuesStmt = "DEFAULT VALUES";
|
|
66
|
+
const Dialect = {
|
|
67
|
+
type: 'postgresql',
|
|
68
|
+
DataTypes,
|
|
69
|
+
escape,
|
|
70
|
+
escapeId,
|
|
71
|
+
escapeVal,
|
|
72
|
+
limitAsTop: false,
|
|
73
|
+
knex: null,
|
|
74
|
+
defaultValuesStmt
|
|
75
|
+
};
|
|
76
|
+
module.exports = Dialect;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const util = require("util");
|
|
2
|
+
const helpers = require("../Helpers");
|
|
3
|
+
const DataTypes = {
|
|
4
|
+
isSQLITE: true,
|
|
5
|
+
id: 'INTEGER PRIMARY KEY AUTOINCREMENT',
|
|
6
|
+
int: 'INTEGER',
|
|
7
|
+
float: 'FLOAT(12,2)',
|
|
8
|
+
bool: 'TINYINT(1)',
|
|
9
|
+
text: 'TEXT'
|
|
10
|
+
};
|
|
11
|
+
function escape(query, args) {
|
|
12
|
+
return helpers.escapeQuery(Dialect, query, args);
|
|
13
|
+
}
|
|
14
|
+
const escapeId = require("./mysql").escapeId;
|
|
15
|
+
function escapeVal(val, timeZone) {
|
|
16
|
+
if (val === undefined || val === null || typeof val === "symbol") {
|
|
17
|
+
return 'NULL';
|
|
18
|
+
}
|
|
19
|
+
if (Array.isArray(val)) {
|
|
20
|
+
if (val.length === 1 && Array.isArray(val[0])) {
|
|
21
|
+
return "(" + val[0].map(escapeVal.bind(this)) + ")";
|
|
22
|
+
}
|
|
23
|
+
return "(" + val.map(escapeVal.bind(this)).join(", ") + ")";
|
|
24
|
+
}
|
|
25
|
+
if (util.isDate(val)) {
|
|
26
|
+
return "'" + helpers.dateToString(val, timeZone || "local", { dialect: 'sqlite' }) + "'";
|
|
27
|
+
}
|
|
28
|
+
if (Buffer.isBuffer(val)) {
|
|
29
|
+
return helpers.bufferToString(val, 'sqlite');
|
|
30
|
+
}
|
|
31
|
+
switch (typeof val) {
|
|
32
|
+
case "number":
|
|
33
|
+
if (!isFinite(val)) {
|
|
34
|
+
val = val.toString();
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
return val;
|
|
38
|
+
case "boolean":
|
|
39
|
+
return val ? 1 : 0;
|
|
40
|
+
case "function":
|
|
41
|
+
return val(Dialect);
|
|
42
|
+
case "string":
|
|
43
|
+
break;
|
|
44
|
+
case "bigint":
|
|
45
|
+
return val.toString();
|
|
46
|
+
default:
|
|
47
|
+
val = JSON.stringify(val);
|
|
48
|
+
}
|
|
49
|
+
return "'" + val.replace(/\'/g, "''") + "'";
|
|
50
|
+
}
|
|
51
|
+
;
|
|
52
|
+
const Dialect = {
|
|
53
|
+
type: 'sqlite',
|
|
54
|
+
DataTypes,
|
|
55
|
+
escape,
|
|
56
|
+
escapeId,
|
|
57
|
+
escapeVal,
|
|
58
|
+
limitAsTop: false,
|
|
59
|
+
knex: null
|
|
60
|
+
};
|
|
61
|
+
module.exports = Dialect;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/// <reference types="@fibjs/types" />
|
|
2
|
+
import { FxSqlQueryDialect } from "./Typo/Dialect";
|
|
3
|
+
import { FxSqlQuery } from "./Typo/Query";
|
|
4
|
+
import { FxSqlQueryChainBuilder } from "./Typo/Query-ChainBuilder";
|
|
5
|
+
import { FxSqlQuerySql } from "./Typo/Sql";
|
|
6
|
+
export declare function escapeQuery(Dialect: FxSqlQueryDialect.Dialect, query: FxSqlQuerySql.SqlFragmentStr, args: FxSqlQuerySql.SqlAssignmentValues): FxSqlQuerySql.SqlFragmentStr;
|
|
7
|
+
export declare function dateToString(date: number | Date, timeZone: FxSqlQuery.FxSqlQueryTimezone, opts: FxSqlQueryChainBuilder.ChainBuilderOptions): string;
|
|
8
|
+
export declare function zeroPad(number: string | number, n?: number): string;
|
|
9
|
+
export declare function get_table_alias(sql: FxSqlQuerySql.SqlQueryChainDescriptor, table: string | FxSqlQuerySql.SqlFromTableInput): string;
|
|
10
|
+
export declare function parseTableInputStr(table_name: FxSqlQuerySql.SqlTableInputType, dialect?: FxSqlQueryDialect.DialectType): FxSqlQuerySql.SqlTableTuple;
|
|
11
|
+
export declare function pickAliasFromFromDescriptor(fd: FxSqlQuerySql.QueryFromDescriptor): string;
|
|
12
|
+
export declare function pickColumnAsFromSelectFieldsDescriptor(sitem: FxSqlQuerySql.SqlSelectFieldItemDescriptor): FxSqlQuerySql.SqlSelectFieldItemDescriptor['as'];
|
|
13
|
+
export declare function autoIncreatementTableIndex(from: FxSqlQuerySql.SqlQueryChainDescriptor['from']): number;
|
|
14
|
+
export declare function defaultTableAliasNameRule(idx: number): string;
|
|
15
|
+
export declare function ucfirst(str?: string): string;
|
|
16
|
+
export declare function ensureNumber(num: any): any;
|
|
17
|
+
export declare function bufferToString(buffer: Class_Buffer | string, dialect: FxSqlQueryDialect.DialectType): string;
|
|
18
|
+
export declare const DialectTypes: FxSqlQueryDialect.DialectType[];
|
|
19
|
+
export declare function escapeValForKnex(val: any, Dialect: FxSqlQueryDialect.Dialect, opts: FxSqlQueryChainBuilder.ChainBuilderOptions): any;
|
|
20
|
+
export declare function cutOffOrderDirectionFromColumnFirstStr(col_name: string): {
|
|
21
|
+
col_name: string;
|
|
22
|
+
direction: FxSqlQuerySql.SqlOrderDescriptor['d'];
|
|
23
|
+
};
|
|
24
|
+
export declare function maybeKnexSubQuery(input: any): input is import('../knex/types').Knex.QueryBuilder;
|
|
25
|
+
export declare function maybeKnexRaw(input: any): input is import('../knex/types').Knex.Raw;
|
|
26
|
+
export declare function maybeKnexRawOrQueryBuilder(input: any): input is import('../knex/types').Knex.QueryBuilder | import('../knex/types').Knex.Raw;
|
|
27
|
+
export declare function isWrapperdSubQuerySelect(sql: any): sql is `(${string})`;
|
|
28
|
+
/** @internal */
|
|
29
|
+
export declare function convertSqlFromTable(sql_from_item: FxSqlQuerySql.QueryFromDescriptor, knex: import('../knex/types').Knex, isSubQuery?: boolean): string | import("../knex/types").Knex.Raw<any>;
|
|
30
|
+
export declare class ChainBuilderBase implements FxSqlQueryChainBuilder.ChainBuilder {
|
|
31
|
+
protected Dialect: FxSqlQueryDialect.Dialect;
|
|
32
|
+
readonly knex: FxSqlQuery.Class_Query['knex'];
|
|
33
|
+
constructor(Dialect: FxSqlQueryDialect.Dialect);
|
|
34
|
+
/**
|
|
35
|
+
* @override
|
|
36
|
+
*/
|
|
37
|
+
build(): string;
|
|
38
|
+
}
|