orange-orm 5.2.4 → 5.3.1
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/README.md +10 -0
- package/deno.lock +75 -0
- package/dist/index.browser.mjs +116 -50
- package/dist/index.mjs +444 -69
- package/docs/changelog.md +5 -0
- package/other.db +0 -0
- package/package.json +2 -1
- package/src/bunSqlite/newTransaction.js +2 -1
- package/src/client/clientMap.js +2 -0
- package/src/client/createProviders.js +8 -0
- package/src/client/index.js +2 -1
- package/src/client/map.js +1 -0
- package/src/getManyDto.js +7 -5
- package/src/index.d.ts +1 -0
- package/src/index.js +11 -1
- package/src/map.d.ts +3 -0
- package/src/map2.d.ts +3 -0
- package/src/mariaDb/newDatabase.js +101 -0
- package/src/mariaDb/newPool.js +13 -0
- package/src/mariaDb/newTransaction.js +126 -0
- package/src/mssql/newTransaction.js +2 -1
- package/src/mySql/newTransaction.js +27 -1
- package/src/nodeSqlite/newTransaction.js +2 -1
- package/src/oracle/newTransaction.js +2 -1
- package/src/patchTable.js +1 -5
- package/src/pg/pool/newPgPool.js +1 -1
- package/src/sqlite3/newTransaction.js +2 -1
- package/src/table/column/bigint/newEncode.js +1 -1
- package/src/table/column/date/newEncode.js +1 -1
- package/src/table/column/dateWithTimeZone/newEncode.js +14 -10
- package/src/table/column/string/newLikeColumnArg.js +1 -1
- package/src/table/column.js +2 -7
- package/src/table/commands/delete/singleCommand/newSingleCommandCore.js +5 -1
- package/src/table/commands/newInsertAndForgetCommand.js +2 -2
- package/src/table/commands/newUpdateCommandCore.js +23 -3
- package/src/table/isJsonUpdateSupported.js +1 -1
- package/src/table/relatedTable/aggregate.js +4 -5
- package/src/table/relatedTable/where.js +4 -5
- package/src/table/relation/newManyCacheCore.js +1 -1
- package/src/table/resultToRows/dbRowToRow.js +38 -5
- package/src/tedious/newTransaction.js +2 -1
- package/src/table/query/extractLimitQuery.js +0 -23
package/docs/changelog.md
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
## Changelog
|
|
2
|
+
__5.3.1__
|
|
3
|
+
Fixes crashes in getById/getMany when a missing relation has nested hasMany/hasOne/references in the strategy. [#177](https://github.com/alfateam/orange-orm/issues/177)
|
|
4
|
+
Added max parameter chunking for getManyDto hasMany subqueries on MSSQL, SQLite and Oracle.
|
|
5
|
+
__5.3.0__
|
|
6
|
+
Support for MariaDB [#169](https://github.com/alfateam/orange-orm/issues/169)
|
|
2
7
|
__5.2.4__
|
|
3
8
|
Meta parameter in validator is optional
|
|
4
9
|
__5.2.3__
|
package/other.db
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -19,6 +19,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
|
|
|
19
19
|
rdb.pool = pool;
|
|
20
20
|
}
|
|
21
21
|
rdb.engine = 'sqlite';
|
|
22
|
+
rdb.maxParameters = 32766;
|
|
22
23
|
rdb.encodeBoolean = encodeBoolean;
|
|
23
24
|
rdb.encodeBinary = encodeBinary;
|
|
24
25
|
rdb.decodeBinary = decodeBinary;
|
|
@@ -106,4 +107,4 @@ function decodeJSON(value) {
|
|
|
106
107
|
return JSON.parse(value);
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
module.exports = newResolveTransaction;
|
|
110
|
+
module.exports = newResolveTransaction;
|
package/src/client/clientMap.js
CHANGED
|
@@ -37,6 +37,7 @@ function map(index, _fn) {
|
|
|
37
37
|
dbMap.mssql = throwDb;
|
|
38
38
|
dbMap.mssqlNative = throwDb;
|
|
39
39
|
dbMap.mysql = throwDb;
|
|
40
|
+
dbMap.mariadb = throwDb;
|
|
40
41
|
dbMap.sap = throwDb;
|
|
41
42
|
dbMap.oracle = throwDb;
|
|
42
43
|
dbMap.sqlite = throwDb;
|
|
@@ -65,6 +66,7 @@ function map(index, _fn) {
|
|
|
65
66
|
onFinal.mssql = () => index({ db: throwDb, providers: dbMap });
|
|
66
67
|
onFinal.mssqlNative = () => index({ db: throwDb, providers: dbMap });
|
|
67
68
|
onFinal.mysql = () => index({ db: throwDb, providers: dbMap });
|
|
69
|
+
onFinal.mariadb = () => index({ db: throwDb, providers: dbMap });
|
|
68
70
|
onFinal.sap = () => index({ db: throwDb, providers: dbMap });
|
|
69
71
|
onFinal.oracle = () => index({ db: throwDb, providers: dbMap });
|
|
70
72
|
onFinal.sqlite = () => index({ db: throwDb, providers: dbMap });
|
|
@@ -38,6 +38,11 @@ function createProviders(index) {
|
|
|
38
38
|
return createPool.bind(null, 'mysql');
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
|
+
Object.defineProperty(dbMap, 'mariadb', {
|
|
42
|
+
get: function() {
|
|
43
|
+
return createPool.bind(null, 'mariadb');
|
|
44
|
+
}
|
|
45
|
+
});
|
|
41
46
|
Object.defineProperty(dbMap, 'sap', {
|
|
42
47
|
get: function() {
|
|
43
48
|
return createPool.bind(null, 'sap');
|
|
@@ -102,6 +107,9 @@ function negotiateCachedPool(fn, providers) {
|
|
|
102
107
|
get mysql() {
|
|
103
108
|
return createPool.bind(null, 'mysql');
|
|
104
109
|
},
|
|
110
|
+
get mariadb() {
|
|
111
|
+
return createPool.bind(null, 'mariadb');
|
|
112
|
+
},
|
|
105
113
|
get sap() {
|
|
106
114
|
return createPool.bind(null, 'sap');
|
|
107
115
|
},
|
package/src/client/index.js
CHANGED
|
@@ -65,6 +65,7 @@ function rdbClient(options = {}) {
|
|
|
65
65
|
client.oracle = onProvider.bind(null, 'oracle');
|
|
66
66
|
client.http = onProvider.bind(null, 'http');//todo
|
|
67
67
|
client.mysql = onProvider.bind(null, 'mysql');
|
|
68
|
+
client.mariadb = onProvider.bind(null, 'mariadb');
|
|
68
69
|
client.express = express;
|
|
69
70
|
client.hono = hono;
|
|
70
71
|
client.close = close;
|
|
@@ -1085,7 +1086,7 @@ function column(path, ...previous) {
|
|
|
1085
1086
|
if (arguments[i][isColumnProxyKey])
|
|
1086
1087
|
args[i] = { [columnRefKey]: arguments[i][columnPathKey] };
|
|
1087
1088
|
else
|
|
1088
|
-
args[i] = arguments[i](tableProxy(
|
|
1089
|
+
args[i] = arguments[i](tableProxy());
|
|
1089
1090
|
}
|
|
1090
1091
|
else
|
|
1091
1092
|
args[i] = arguments[i];
|
package/src/client/map.js
CHANGED
|
@@ -46,6 +46,7 @@ function map(index, context, providers, fn) {
|
|
|
46
46
|
context.mssql = connect.bind(null, 'mssql');
|
|
47
47
|
context.mssqlNative = connect.bind(null, 'mssqlNative');
|
|
48
48
|
context.mysql = connect.bind(null, 'mysql');
|
|
49
|
+
context.mariadb = connect.bind(null, 'mariadb');
|
|
49
50
|
context.sap = connect.bind(null, 'sap');
|
|
50
51
|
context.oracle = connect.bind(null, 'oracle');
|
|
51
52
|
context.sqlite = connect.bind(null, 'sqlite');
|
package/src/getManyDto.js
CHANGED
|
@@ -126,16 +126,18 @@ async function decode(context, strategy, span, rows, keys = rows.length > 0 ? Ob
|
|
|
126
126
|
outRow[column.alias] = column.decode(context, row[keys[j]]);
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
if (outRow) {
|
|
130
|
+
for (let j = 0; j < aggregateKeys.length; j++) {
|
|
131
|
+
const key = aggregateKeys[j];
|
|
132
|
+
const parse = span.aggregates[key].column?.decode || ((context, arg) => Number.parseFloat(arg));
|
|
133
|
+
outRow[key] = parse(context, row[keys[j + columnsLength]]);
|
|
134
|
+
}
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
outRows[i] = outRow;
|
|
136
138
|
if (updateParent)
|
|
137
139
|
updateParent(outRow, i);
|
|
138
|
-
if (shouldCreateMap) {
|
|
140
|
+
if (shouldCreateMap && outRow) {
|
|
139
141
|
fkIds[i] = getIds(outRow);
|
|
140
142
|
addToMap(rowsMap, fkIds[i], outRow);
|
|
141
143
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ declare namespace r {
|
|
|
28
28
|
function mssql(connectionString: string, options?: PoolOptions): Pool;
|
|
29
29
|
function mssqlNative(connectionString: string, options?: PoolOptions): Pool;
|
|
30
30
|
function mysql(connectionString: string, options?: PoolOptions): Pool;
|
|
31
|
+
function mariadb(connectionString: string, options?: PoolOptions): Pool;
|
|
31
32
|
function oracle(config: PoolAttributes, options?: PoolOptions): Pool;
|
|
32
33
|
function on(type: 'query', cb: (e: QueryEvent) => void): void;
|
|
33
34
|
function off(type: 'query', cb: (e: QueryEvent) => void): void;
|
package/src/index.js
CHANGED
|
@@ -6,6 +6,7 @@ const map = require('./client/map');
|
|
|
6
6
|
const runtimes = require('./runtimes');
|
|
7
7
|
|
|
8
8
|
let _mySql;
|
|
9
|
+
let _mariadb;
|
|
9
10
|
let _pg;
|
|
10
11
|
let _pglite;
|
|
11
12
|
let _sqlite;
|
|
@@ -16,7 +17,9 @@ let _oracle;
|
|
|
16
17
|
let _d1;
|
|
17
18
|
|
|
18
19
|
var connectViaPool = function(connectionString) {
|
|
19
|
-
if (connectionString.indexOf && connectionString.indexOf('
|
|
20
|
+
if (connectionString.indexOf && connectionString.indexOf('mariadb') === 0)
|
|
21
|
+
return connectViaPool.mariadb.apply(null, arguments);
|
|
22
|
+
else if (connectionString.indexOf && connectionString.indexOf('mysql') === 0)
|
|
20
23
|
return connectViaPool.mySql.apply(null, arguments);
|
|
21
24
|
else if (connectionString.indexOf && connectionString.indexOf('postgres') === 0)
|
|
22
25
|
connectViaPool.pg.apply(null, arguments);
|
|
@@ -57,6 +60,13 @@ Object.defineProperty(connectViaPool, 'mySql', {
|
|
|
57
60
|
return _mySql;
|
|
58
61
|
}
|
|
59
62
|
});
|
|
63
|
+
Object.defineProperty(connectViaPool, 'mariadb', {
|
|
64
|
+
get: function() {
|
|
65
|
+
if (!_mariadb)
|
|
66
|
+
_mariadb = require('./mariaDb/newDatabase');
|
|
67
|
+
return _mariadb;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
60
70
|
Object.defineProperty(connectViaPool, 'pglite', {
|
|
61
71
|
get: function() {
|
|
62
72
|
if (!_pglite)
|
package/src/map.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ type DbConnectable<T> = {
|
|
|
41
41
|
mssql(connectionString: string, options?: PoolOptions): DBClient<SchemaFromMappedDb<T>>;
|
|
42
42
|
mssqlNative(connectionString: string, options?: PoolOptions): DBClient<SchemaFromMappedDb<T>>;
|
|
43
43
|
mysql(connectionString: string, options?: PoolOptions): DBClient<SchemaFromMappedDb<T>>;
|
|
44
|
+
mariadb(connectionString: string, options?: PoolOptions): DBClient<SchemaFromMappedDb<T>>;
|
|
44
45
|
oracle(config: PoolAttributes, options?: PoolOptions): DBClient<SchemaFromMappedDb<T>>;
|
|
45
46
|
};
|
|
46
47
|
|
|
@@ -71,6 +72,8 @@ interface Connectors {
|
|
|
71
72
|
sap(connectionString: string, options?: PoolOptions): Pool;
|
|
72
73
|
mssql(connectionConfig: ConnectionConfiguration, options?: PoolOptions): Pool;
|
|
73
74
|
mssql(connectionString: string, options?: PoolOptions): Pool;
|
|
75
|
+
mysql(connectionString: string, options?: PoolOptions): Pool;
|
|
76
|
+
mariadb(connectionString: string, options?: PoolOptions): Pool;
|
|
74
77
|
oracle(config: PoolAttributes, options?: PoolOptions): Pool;
|
|
75
78
|
}
|
|
76
79
|
|
package/src/map2.d.ts
CHANGED
|
@@ -881,6 +881,8 @@ interface Connectors {
|
|
|
881
881
|
sap(connectionString: string, options?: PoolOptions): Pool;
|
|
882
882
|
mssql(connectionConfig: ConnectionConfiguration, options?: PoolOptions): Pool;
|
|
883
883
|
mssql(connectionString: string, options?: PoolOptions): Pool;
|
|
884
|
+
mysql(connectionString: string, options?: PoolOptions): Pool;
|
|
885
|
+
mariadb(connectionString: string, options?: PoolOptions): Pool;
|
|
884
886
|
oracle(config: PoolAttributes, options?: PoolOptions): Pool;
|
|
885
887
|
}
|
|
886
888
|
|
|
@@ -895,6 +897,7 @@ type DbConnectable<M extends Record<string, TableDefinition<M>>> = {
|
|
|
895
897
|
mssql(connectionString: string, options?: PoolOptions): DBClient<M>;
|
|
896
898
|
mssqlNative(connectionString: string, options?: PoolOptions): DBClient<M>;
|
|
897
899
|
mysql(connectionString: string, options?: PoolOptions): DBClient<M>;
|
|
900
|
+
mariadb(connectionString: string, options?: PoolOptions): DBClient<M>;
|
|
898
901
|
oracle(config: PoolAttributes, options?: PoolOptions): DBClient<M>;
|
|
899
902
|
};
|
|
900
903
|
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
let createDomain = require('../createDomain');
|
|
2
|
+
let newTransaction = require('./newTransaction');
|
|
3
|
+
let _begin = require('../table/begin');
|
|
4
|
+
let commit = require('../table/commit');
|
|
5
|
+
let rollback = require('../table/rollback');
|
|
6
|
+
let newPool = require('./newPool');
|
|
7
|
+
let express = require('../hostExpress');
|
|
8
|
+
let hono = require('../hostHono');
|
|
9
|
+
let hostLocal = require('../hostLocal');
|
|
10
|
+
let doQuery = require('../query');
|
|
11
|
+
let releaseDbClient = require('../table/releaseDbClient');
|
|
12
|
+
|
|
13
|
+
function newDatabase(connectionString, poolOptions) {
|
|
14
|
+
if (!connectionString)
|
|
15
|
+
throw new Error('Connection string cannot be empty');
|
|
16
|
+
poolOptions = poolOptions || { min: 1 };
|
|
17
|
+
var pool = newPool(connectionString, poolOptions);
|
|
18
|
+
|
|
19
|
+
let c = { poolFactory: pool, hostLocal, express, hono };
|
|
20
|
+
|
|
21
|
+
c.transaction = function(options, fn) {
|
|
22
|
+
if ((arguments.length === 1) && (typeof options === 'function')) {
|
|
23
|
+
fn = options;
|
|
24
|
+
options = undefined;
|
|
25
|
+
}
|
|
26
|
+
let domain = createDomain();
|
|
27
|
+
|
|
28
|
+
if (!fn)
|
|
29
|
+
throw new Error('transaction requires a function');
|
|
30
|
+
return domain.run(runInTransaction);
|
|
31
|
+
|
|
32
|
+
async function runInTransaction() {
|
|
33
|
+
let result;
|
|
34
|
+
let transaction = newTransaction(domain, pool, options);
|
|
35
|
+
await new Promise(transaction)
|
|
36
|
+
.then(begin)
|
|
37
|
+
.then(() => fn(domain))
|
|
38
|
+
.then((res) => result = res)
|
|
39
|
+
.then(() => commit(domain))
|
|
40
|
+
.then(null, (e) => rollback(domain, e));
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function begin() {
|
|
45
|
+
return _begin(domain, options);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
c.createTransaction = function(options) {
|
|
50
|
+
let domain = createDomain();
|
|
51
|
+
let transaction = newTransaction(domain, pool);
|
|
52
|
+
let p = domain.run(() => new Promise(transaction).then(begin));
|
|
53
|
+
|
|
54
|
+
function run(fn) {
|
|
55
|
+
return p.then(() => fn(domain));
|
|
56
|
+
}
|
|
57
|
+
run.rollback = rollback.bind(null, domain);
|
|
58
|
+
run.commit = commit.bind(null, domain);
|
|
59
|
+
return run;
|
|
60
|
+
|
|
61
|
+
function begin() {
|
|
62
|
+
return _begin(domain, options);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
c.query = function(query) {
|
|
67
|
+
let domain = createDomain();
|
|
68
|
+
let transaction = newTransaction(domain, pool);
|
|
69
|
+
let p = domain.run(() => new Promise(transaction)
|
|
70
|
+
.then(() => doQuery(domain, query).then(onResult, onError)));
|
|
71
|
+
return p;
|
|
72
|
+
|
|
73
|
+
function onResult(result) {
|
|
74
|
+
releaseDbClient(domain);
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function onError(e) {
|
|
79
|
+
releaseDbClient(domain);
|
|
80
|
+
throw e;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
c.rollback = rollback;
|
|
85
|
+
c.commit = commit;
|
|
86
|
+
|
|
87
|
+
c.end = function() {
|
|
88
|
+
if (poolOptions)
|
|
89
|
+
return pool.end();
|
|
90
|
+
else
|
|
91
|
+
return Promise.resolve();
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
c.accept = function(caller) {
|
|
95
|
+
caller.visitMySql();
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
return c;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
module.exports = newDatabase;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const mySqlNewPool = require('../mySql/newPool');
|
|
2
|
+
|
|
3
|
+
function normalizeConnectionString(connectionString) {
|
|
4
|
+
if (typeof connectionString === 'string' && connectionString.indexOf('mariadb://') === 0)
|
|
5
|
+
return 'mysql://' + connectionString.slice('mariadb://'.length);
|
|
6
|
+
return connectionString;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function newPool(connectionString, poolOptions) {
|
|
10
|
+
return mySqlNewPool(normalizeConnectionString(connectionString), poolOptions);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = newPool;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
const wrapQuery = require('../mySql/wrapQuery');
|
|
2
|
+
const wrapCommand = require('../mySql/wrapCommand');
|
|
3
|
+
const encodeBoolean = require('../mySql/encodeBoolean');
|
|
4
|
+
const deleteFromSql = require('../mySql/deleteFromSql');
|
|
5
|
+
const selectForUpdateSql = require('../mySql/selectForUpdateSql');
|
|
6
|
+
const lastInsertedSql = require('../mySql/lastInsertedSql');
|
|
7
|
+
const limitAndOffset = require('../mySql/limitAndOffset');
|
|
8
|
+
const formatBigintOut = require('../mySql/formatBigintOut');
|
|
9
|
+
const insertSql = require('../mySql/insertSql');
|
|
10
|
+
const insert = require('../mySql/insert');
|
|
11
|
+
const quote = require('../mySql/quote');
|
|
12
|
+
|
|
13
|
+
function newResolveTransaction(domain, pool, { readonly = false } = {}) {
|
|
14
|
+
var rdb = { poolFactory: pool };
|
|
15
|
+
if (!pool.connect) {
|
|
16
|
+
pool = pool();
|
|
17
|
+
rdb.pool = pool;
|
|
18
|
+
}
|
|
19
|
+
rdb.engine = 'mariadb';
|
|
20
|
+
rdb.encodeBoolean = encodeBoolean;
|
|
21
|
+
rdb.decodeJSON = decodeJSON;
|
|
22
|
+
rdb.encodeDate = encodeDate;
|
|
23
|
+
rdb.encodeDateTz = encodeDateTz;
|
|
24
|
+
rdb.encodeJSON = JSON.stringify;
|
|
25
|
+
rdb.deleteFromSql = deleteFromSql;
|
|
26
|
+
rdb.selectForUpdateSql = selectForUpdateSql;
|
|
27
|
+
rdb.lastInsertedIsSeparate = true;
|
|
28
|
+
rdb.lastInsertedSql = lastInsertedSql;
|
|
29
|
+
rdb.formatBigintOut = formatBigintOut;
|
|
30
|
+
rdb.insertSql = insertSql;
|
|
31
|
+
rdb.insert = insert;
|
|
32
|
+
rdb.multipleStatements = false;
|
|
33
|
+
rdb.limitAndOffset = limitAndOffset;
|
|
34
|
+
rdb.accept = function(caller) {
|
|
35
|
+
caller.visitMySql();
|
|
36
|
+
};
|
|
37
|
+
rdb.aggregateCount = 0;
|
|
38
|
+
rdb.quote = quote;
|
|
39
|
+
rdb.cache = {};
|
|
40
|
+
rdb.changes = [];
|
|
41
|
+
|
|
42
|
+
if (readonly) {
|
|
43
|
+
rdb.dbClient = {
|
|
44
|
+
executeQuery: function(query, callback) {
|
|
45
|
+
pool.connect((err, client, done) => {
|
|
46
|
+
if (err) {
|
|
47
|
+
return callback(err);
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
wrapQuery(domain, client)(query, (err, res) => {
|
|
51
|
+
done();
|
|
52
|
+
callback(err, res);
|
|
53
|
+
});
|
|
54
|
+
} catch (e) {
|
|
55
|
+
done();
|
|
56
|
+
callback(e);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
executeCommand: function(query, callback) {
|
|
61
|
+
pool.connect((err, client, done) => {
|
|
62
|
+
if (err) {
|
|
63
|
+
return callback(err);
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
wrapCommand(domain, client)(query, (err, res) => {
|
|
67
|
+
done();
|
|
68
|
+
callback(err, res);
|
|
69
|
+
});
|
|
70
|
+
} catch (e) {
|
|
71
|
+
done();
|
|
72
|
+
callback(e);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
domain.rdb = rdb;
|
|
78
|
+
return (onSuccess) => onSuccess();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return function(onSuccess, onError) {
|
|
82
|
+
pool.connect(onConnected);
|
|
83
|
+
|
|
84
|
+
function onConnected(err, client, done) {
|
|
85
|
+
try {
|
|
86
|
+
if (err) {
|
|
87
|
+
onError(err);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
client.executeQuery = wrapQuery(domain, client);
|
|
91
|
+
client.executeCommand = wrapCommand(domain, client);
|
|
92
|
+
rdb.dbClient = client;
|
|
93
|
+
rdb.dbClientDone = done;
|
|
94
|
+
domain.rdb = rdb;
|
|
95
|
+
onSuccess();
|
|
96
|
+
} catch (e) {
|
|
97
|
+
onError(e);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function decodeJSON(value) {
|
|
104
|
+
return JSON.parse(value);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function encodeDate(date) {
|
|
108
|
+
date = date.toISOString ? removeTimezone(date.toISOString()) : removeTimezone(date);
|
|
109
|
+
return date;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function removeTimezone(isoString) {
|
|
113
|
+
let dateTimePattern = /[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(.[0-9]{3})?/;
|
|
114
|
+
let match = isoString.match(dateTimePattern);
|
|
115
|
+
return match ? match[0] : isoString;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function encodeDateTz(date) {
|
|
119
|
+
if (date && date.toISOString)
|
|
120
|
+
return removeTimezone(date.toISOString());
|
|
121
|
+
if (typeof date === 'string' && /(Z|[+-][0-9]{2}:[0-9]{2})$/.test(date))
|
|
122
|
+
return removeTimezone(new Date(date).toISOString());
|
|
123
|
+
return date;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
module.exports = newResolveTransaction;
|
|
@@ -19,6 +19,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
|
|
|
19
19
|
rdb.pool = pool;
|
|
20
20
|
}
|
|
21
21
|
rdb.engine = 'mssqlNative';
|
|
22
|
+
rdb.maxParameters = 2100;
|
|
22
23
|
rdb.encodeBoolean = encodeBoolean;
|
|
23
24
|
rdb.decodeJSON = decodeJSON;
|
|
24
25
|
rdb.encodeJSON = JSON.stringify;
|
|
@@ -117,4 +118,4 @@ function decodeJSON(value){
|
|
|
117
118
|
return JSON.parse(value);
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
module.exports = newResolveTransaction;
|
|
121
|
+
module.exports = newResolveTransaction;
|
|
@@ -18,6 +18,9 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
|
|
|
18
18
|
}
|
|
19
19
|
rdb.engine = 'mysql';
|
|
20
20
|
rdb.encodeBoolean = encodeBoolean;
|
|
21
|
+
rdb.decodeJSON = decodeJSON;
|
|
22
|
+
rdb.encodeDate = encodeDate;
|
|
23
|
+
rdb.encodeDateTz = encodeDateTz;
|
|
21
24
|
rdb.encodeJSON = JSON.stringify;
|
|
22
25
|
rdb.deleteFromSql = deleteFromSql;
|
|
23
26
|
rdb.selectForUpdateSql = selectForUpdateSql;
|
|
@@ -97,4 +100,27 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
|
|
|
97
100
|
};
|
|
98
101
|
}
|
|
99
102
|
|
|
100
|
-
|
|
103
|
+
function decodeJSON(value) {
|
|
104
|
+
return JSON.parse(value);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function encodeDate(date) {
|
|
108
|
+
date = date.toISOString ? removeTimezone(date.toISOString()) : removeTimezone(date);
|
|
109
|
+
return date;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function removeTimezone(isoString) {
|
|
113
|
+
let dateTimePattern = /[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(.[0-9]{3})?/;
|
|
114
|
+
let match = isoString.match(dateTimePattern);
|
|
115
|
+
return match ? match[0] : isoString;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function encodeDateTz(date) {
|
|
119
|
+
if (date && date.toISOString)
|
|
120
|
+
return removeTimezone(date.toISOString());
|
|
121
|
+
if (typeof date === 'string' && /(Z|[+-][0-9]{2}:[0-9]{2})$/.test(date))
|
|
122
|
+
return removeTimezone(new Date(date).toISOString());
|
|
123
|
+
return date;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
module.exports = newResolveTransaction;
|
|
@@ -19,6 +19,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
|
|
|
19
19
|
rdb.pool = pool;
|
|
20
20
|
}
|
|
21
21
|
rdb.engine = 'sqlite';
|
|
22
|
+
rdb.maxParameters = 32766;
|
|
22
23
|
rdb.encodeBoolean = encodeBoolean;
|
|
23
24
|
rdb.encodeBinary = encodeBinary;
|
|
24
25
|
rdb.decodeBinary = decodeBinary;
|
|
@@ -106,4 +107,4 @@ function decodeJSON(value) {
|
|
|
106
107
|
return JSON.parse(value);
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
module.exports = newResolveTransaction;
|
|
110
|
+
module.exports = newResolveTransaction;
|
|
@@ -21,6 +21,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
|
|
|
21
21
|
|
|
22
22
|
rdb.begin = 'SET TRANSACTION ISOLATION LEVEL READ COMMITTED';
|
|
23
23
|
rdb.engine = 'oracle';
|
|
24
|
+
rdb.maxParameters = 32768;
|
|
24
25
|
rdb.encodeBoolean = encodeBoolean;
|
|
25
26
|
rdb.decodeJSON = decodeJSON;
|
|
26
27
|
rdb.encodeJSON = JSON.stringify;
|
|
@@ -110,4 +111,4 @@ function decodeJSON(value) {
|
|
|
110
111
|
return JSON.parse(value);
|
|
111
112
|
}
|
|
112
113
|
|
|
113
|
-
module.exports = newResolveTransaction;
|
|
114
|
+
module.exports = newResolveTransaction;
|
package/src/patchTable.js
CHANGED
|
@@ -267,8 +267,6 @@ async function patchTableCore(context, table, patches, { strategy = undefined, d
|
|
|
267
267
|
let result;
|
|
268
268
|
for (let i = 0; i < relation.columns.length; i++) {
|
|
269
269
|
let p = relation.columns[i].alias;
|
|
270
|
-
let dto = {};
|
|
271
|
-
dto[p] = row[p];
|
|
272
270
|
result = await remove({ path: ['dummy', p], oldValue: (oldValue || {})[p], op, options: options }, table, row) || result;
|
|
273
271
|
}
|
|
274
272
|
return result || {};
|
|
@@ -281,9 +279,7 @@ async function patchTableCore(context, table, patches, { strategy = undefined, d
|
|
|
281
279
|
let p = relation.columns[i].alias;
|
|
282
280
|
let childKey = relation.childTable._primaryColumns[i].alias;
|
|
283
281
|
if (path[1] === childKey) {
|
|
284
|
-
|
|
285
|
-
dto[p] = row[p];
|
|
286
|
-
result = await remove({ path: ['dummy', p], oldValue: (oldValue || {})[p], op, options: options }, table, row) || result;
|
|
282
|
+
result = await remove({ path: ['dummy', p], oldValue: oldValue[p], op, options: options }, table, row) || result;
|
|
287
283
|
break;
|
|
288
284
|
}
|
|
289
285
|
}
|
package/src/pg/pool/newPgPool.js
CHANGED
|
@@ -22,7 +22,7 @@ function newPgPool(connectionString, poolOptions) {
|
|
|
22
22
|
if (!pg) {
|
|
23
23
|
pg = await import('pg');
|
|
24
24
|
pg = pg.default || pg;
|
|
25
|
-
let types = pg.types
|
|
25
|
+
let types = pg.types;
|
|
26
26
|
types.setTypeParser(1700, function(val) {
|
|
27
27
|
return parseFloat(val);
|
|
28
28
|
});
|
|
@@ -17,6 +17,7 @@ function newResolveTransaction(domain, pool, { readonly = false } = {}) {
|
|
|
17
17
|
rdb.pool = pool;
|
|
18
18
|
}
|
|
19
19
|
rdb.engine = 'sqlite';
|
|
20
|
+
rdb.maxParameters = 32766;
|
|
20
21
|
rdb.encodeBoolean = encodeBoolean;
|
|
21
22
|
rdb.decodeJSON = decodeJSON;
|
|
22
23
|
rdb.encodeJSON = JSON.stringify;
|
|
@@ -102,4 +103,4 @@ function decodeJSON(value) {
|
|
|
102
103
|
return JSON.parse(value);
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
module.exports = newResolveTransaction;
|
|
106
|
+
module.exports = newResolveTransaction;
|
|
@@ -1,38 +1,43 @@
|
|
|
1
1
|
var newPara = require('../../query/newParameterized');
|
|
2
2
|
var purify = require('../date/purify');
|
|
3
|
+
var getSessionContext = require('../../getSessionContext');
|
|
4
|
+
var getSessionSingleton = require('../../getSessionSingleton');
|
|
3
5
|
|
|
4
6
|
function _new(column) {
|
|
5
|
-
var encode = function(
|
|
7
|
+
var encode = function(context, value) {
|
|
6
8
|
value = purify(value);
|
|
7
9
|
if (value == null) {
|
|
8
10
|
if (column.dbNull === null)
|
|
9
11
|
return newPara('null');
|
|
10
12
|
return newPara('\'' + column.dbNull + '\'');
|
|
11
13
|
}
|
|
12
|
-
|
|
14
|
+
var ctx = getSessionContext(context);
|
|
15
|
+
var encodeCore = ctx.encodeDateTz || ctx.encodeDate || encodeDate;
|
|
16
|
+
return newPara('?', [encodeCore(value)]);
|
|
13
17
|
};
|
|
14
18
|
|
|
15
|
-
encode.unsafe = function(
|
|
19
|
+
encode.unsafe = function(context, value) {
|
|
16
20
|
value = purify(value);
|
|
17
21
|
if (value == null) {
|
|
18
22
|
if (column.dbNull === null)
|
|
19
23
|
return 'null';
|
|
20
24
|
return '\'' + column.dbNull + '\'';
|
|
21
25
|
}
|
|
22
|
-
|
|
26
|
+
var encodeCore = getSessionSingleton(context, 'encodeDateTz') || getSessionSingleton(context, 'encodeDate') || encodeDate;
|
|
27
|
+
return encodeCore(value);
|
|
23
28
|
};
|
|
24
29
|
|
|
25
|
-
encode.direct = function(
|
|
26
|
-
|
|
30
|
+
encode.direct = function(context, value) {
|
|
31
|
+
var encodeCore = getSessionSingleton(context, 'encodeDateTz') || getSessionSingleton(context, 'encodeDate') || encodeDate;
|
|
32
|
+
return encodeCore(value);
|
|
27
33
|
};
|
|
28
34
|
|
|
29
35
|
return encode;
|
|
30
|
-
|
|
31
|
-
|
|
32
36
|
}
|
|
37
|
+
|
|
33
38
|
function encodeDate(date) {
|
|
34
39
|
if (date.toISOString)
|
|
35
|
-
return truncate(date.toISOString(
|
|
40
|
+
return truncate(date.toISOString());
|
|
36
41
|
return truncate(date);
|
|
37
42
|
}
|
|
38
43
|
|
|
@@ -40,5 +45,4 @@ function truncate(date) {
|
|
|
40
45
|
return date;
|
|
41
46
|
}
|
|
42
47
|
|
|
43
|
-
|
|
44
48
|
module.exports = _new;
|
|
@@ -6,7 +6,7 @@ function newLikeColumnArg(context, column, encodedArg, prefix, suffix) {
|
|
|
6
6
|
var encodedSuffix = suffix ? column.encode(context, suffix) : null;
|
|
7
7
|
var engine = getSessionSingleton(context, 'engine');
|
|
8
8
|
|
|
9
|
-
if (engine === 'mysql')
|
|
9
|
+
if (engine === 'mysql' || engine === 'mariadb')
|
|
10
10
|
return concatWithFunction(encodedPrefix, encodedArg, encodedSuffix);
|
|
11
11
|
if (engine === 'mssql' || engine === 'mssqlNative')
|
|
12
12
|
return concatWithOperator('+', encodedPrefix, encodedArg, encodedSuffix);
|