orange-orm 5.2.4 → 5.3.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/README.md +10 -0
- package/deno.lock +75 -0
- package/dist/index.browser.mjs +56 -16
- package/dist/index.mjs +378 -35
- package/docs/changelog.md +2 -0
- package/other.db +0 -0
- package/package.json +1 -1
- package/src/client/clientMap.js +2 -0
- package/src/client/createProviders.js +8 -0
- package/src/client/index.js +1 -0
- package/src/client/map.js +1 -0
- 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/mySql/newTransaction.js +27 -1
- package/src/table/column/dateWithTimeZone/newEncode.js +14 -10
- package/src/table/column/string/newLikeColumnArg.js +1 -1
- package/src/table/commands/delete/singleCommand/newSingleCommandCore.js +5 -1
- package/src/table/commands/newUpdateCommandCore.js +23 -3
- package/src/table/isJsonUpdateSupported.js +1 -1
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;
|
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/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;
|
|
@@ -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;
|
|
@@ -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, '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, '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);
|
|
@@ -60,7 +60,7 @@ function newSingleCommandCore(context, table, filter, alias, concurrencyState) {
|
|
|
60
60
|
if (engine === 'pg') {
|
|
61
61
|
return newParameterized(columnSql + ' IS NOT DISTINCT FROM ' + encoded.sql(), encoded.parameters);
|
|
62
62
|
}
|
|
63
|
-
if (engine === 'mysql') {
|
|
63
|
+
if (engine === 'mysql' || engine === 'mariadb') {
|
|
64
64
|
return newParameterized(columnSql + ' <=> ' + encoded.sql(), encoded.parameters);
|
|
65
65
|
}
|
|
66
66
|
if (engine === 'sqlite') {
|
|
@@ -101,6 +101,10 @@ function newSingleCommandCore(context, table, filter, alias, concurrencyState) {
|
|
|
101
101
|
const jsonValue = JSON.stringify(value === undefined ? null : value);
|
|
102
102
|
return newParameterized('CAST(? AS JSON)', [jsonValue]);
|
|
103
103
|
}
|
|
104
|
+
if (engine === 'mariadb') {
|
|
105
|
+
const jsonValue = JSON.stringify(value === undefined ? null : value);
|
|
106
|
+
return newParameterized('JSON_EXTRACT(?, \'$\')', [jsonValue]);
|
|
107
|
+
}
|
|
104
108
|
if (engine === 'sqlite') {
|
|
105
109
|
if (isJsonObject(value)) {
|
|
106
110
|
const jsonValue = JSON.stringify(value);
|
|
@@ -84,7 +84,7 @@ function newUpdateCommandCore(context, table, columns, row, concurrencyState) {
|
|
|
84
84
|
if (engine === 'pg') {
|
|
85
85
|
command = command.append(separator + columnSql + ' IS NOT DISTINCT FROM ').append(encoded);
|
|
86
86
|
}
|
|
87
|
-
else if (engine === 'mysql') {
|
|
87
|
+
else if (engine === 'mysql' || engine === 'mariadb') {
|
|
88
88
|
command = command.append(separator + columnSql + ' <=> ').append(encoded);
|
|
89
89
|
}
|
|
90
90
|
else if (engine === 'sqlite') {
|
|
@@ -123,7 +123,7 @@ function newUpdateCommandCore(context, table, columns, row, concurrencyState) {
|
|
|
123
123
|
if (engine === 'pg') {
|
|
124
124
|
command = command.append(separator).append(columnExpr).append(' IS NOT DISTINCT FROM ').append(encoded);
|
|
125
125
|
}
|
|
126
|
-
else if (engine === 'mysql') {
|
|
126
|
+
else if (engine === 'mysql' || engine === 'mariadb') {
|
|
127
127
|
command = command.append(separator).append(columnExpr).append(' <=> ').append(encoded);
|
|
128
128
|
}
|
|
129
129
|
else if (engine === 'sqlite') {
|
|
@@ -184,6 +184,11 @@ function newUpdateCommandCore(context, table, columns, row, concurrencyState) {
|
|
|
184
184
|
const sql = 'JSON_SET(' + expr.sql() + ', ' + jsonPath.sql + ', CAST(? AS JSON))';
|
|
185
185
|
return newParameterized(sql, expr.parameters.concat(jsonPath.parameters, [jsonValue]));
|
|
186
186
|
}
|
|
187
|
+
if (engine === 'mariadb') {
|
|
188
|
+
const jsonValue = JSON.stringify(value === undefined ? null : value);
|
|
189
|
+
const sql = 'JSON_SET(' + expr.sql() + ', ' + jsonPath.sql + ', JSON_EXTRACT(?, \'$\'))';
|
|
190
|
+
return newParameterized(sql, expr.parameters.concat(jsonPath.parameters, [jsonValue]));
|
|
191
|
+
}
|
|
187
192
|
if (engine === 'sqlite') {
|
|
188
193
|
const jsonValue = JSON.stringify(value === undefined ? null : value);
|
|
189
194
|
const sql = 'json_set(' + expr.sql() + ', ' + jsonPath.sql + ', json(?))';
|
|
@@ -208,7 +213,7 @@ function newUpdateCommandCore(context, table, columns, row, concurrencyState) {
|
|
|
208
213
|
const sql = expr.sql() + ' #- ' + pathLiteral;
|
|
209
214
|
return newParameterized(sql, expr.parameters);
|
|
210
215
|
}
|
|
211
|
-
if (engine === 'mysql') {
|
|
216
|
+
if (engine === 'mysql' || engine === 'mariadb') {
|
|
212
217
|
const sql = 'JSON_REMOVE(' + expr.sql() + ', ' + jsonPath.sql + ')';
|
|
213
218
|
return newParameterized(sql, expr.parameters.concat(jsonPath.parameters));
|
|
214
219
|
}
|
|
@@ -236,6 +241,12 @@ function newUpdateCommandCore(context, table, columns, row, concurrencyState) {
|
|
|
236
241
|
const sql = 'JSON_EXTRACT(' + columnSql + ', ' + jsonPath.sql + ')';
|
|
237
242
|
return newParameterized(sql, jsonPath.parameters);
|
|
238
243
|
}
|
|
244
|
+
if (engine === 'mariadb') {
|
|
245
|
+
const sql = isJsonObject(oldValue)
|
|
246
|
+
? 'JSON_EXTRACT(' + columnSql + ', ' + jsonPath.sql + ')'
|
|
247
|
+
: 'JSON_UNQUOTE(JSON_EXTRACT(' + columnSql + ', ' + jsonPath.sql + '))';
|
|
248
|
+
return newParameterized(sql, jsonPath.parameters);
|
|
249
|
+
}
|
|
239
250
|
if (engine === 'sqlite') {
|
|
240
251
|
const sql = 'json_extract(' + columnSql + ', ' + jsonPath.sql + ')';
|
|
241
252
|
return newParameterized(sql, jsonPath.parameters);
|
|
@@ -311,6 +322,15 @@ function newUpdateCommandCore(context, table, columns, row, concurrencyState) {
|
|
|
311
322
|
const jsonValue = JSON.stringify(value === undefined ? null : value);
|
|
312
323
|
return newParameterized('CAST(? AS JSON)', [jsonValue]);
|
|
313
324
|
}
|
|
325
|
+
if (engine === 'mariadb') {
|
|
326
|
+
if (isJsonObject(value)) {
|
|
327
|
+
const jsonValue = JSON.stringify(value);
|
|
328
|
+
return newParameterized('JSON_EXTRACT(?, \'$\')', [jsonValue]);
|
|
329
|
+
}
|
|
330
|
+
if (value === null || value === undefined)
|
|
331
|
+
return newParameterized('null');
|
|
332
|
+
return newParameterized('?', [String(value)]);
|
|
333
|
+
}
|
|
314
334
|
if (engine === 'sqlite') {
|
|
315
335
|
if (isJsonObject(value)) {
|
|
316
336
|
const jsonValue = JSON.stringify(value);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function isJsonUpdateSupported(engine) {
|
|
2
|
-
return engine === 'pg' || engine === 'mysql' || engine === 'sqlite' || engine === 'mssql' || engine === 'mssqlNative' || engine === 'oracle';
|
|
2
|
+
return engine === 'pg' || engine === 'mysql' || engine === 'mariadb' || engine === 'sqlite' || engine === 'mssql' || engine === 'mssqlNative' || engine === 'oracle';
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
module.exports = isJsonUpdateSupported;
|