orange-orm 5.2.3 → 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 +4 -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 +7 -6
- package/src/index.js +11 -1
- package/src/map.d.ts +21 -18
- 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;
|
|
@@ -100,7 +101,7 @@ declare namespace r {
|
|
|
100
101
|
date(): DateColumnDef;
|
|
101
102
|
}
|
|
102
103
|
export interface DateColumnDef {
|
|
103
|
-
validate(validator: (value?: Date | string, meta
|
|
104
|
+
validate(validator: (value?: Date | string, meta?: ValidationMeta) => void): DateColumnDef;
|
|
104
105
|
notNull(): DateColumnNotNullDef;
|
|
105
106
|
JSONSchema(schema: object, options?: Options): DateColumnDef;
|
|
106
107
|
serializable(value: boolean): DateColumnDef;
|
|
@@ -110,7 +111,7 @@ declare namespace r {
|
|
|
110
111
|
}
|
|
111
112
|
|
|
112
113
|
export interface DateColumnNotNullDef {
|
|
113
|
-
validate(validator: (value: Date | string, meta
|
|
114
|
+
validate(validator: (value: Date | string, meta?: ValidationMeta) => void): DateColumnNotNullDef;
|
|
114
115
|
JSONSchema(schema: object, options?: Options): DateColumnNotNullDef;
|
|
115
116
|
serializable(value: boolean): DateColumnNotNullDef;
|
|
116
117
|
as(dbName: string): DateColumnNotNullDef;
|
|
@@ -119,7 +120,7 @@ declare namespace r {
|
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
export interface BinaryColumnDef {
|
|
122
|
-
validate(validator: (value?: Buffer | string, meta
|
|
123
|
+
validate(validator: (value?: Buffer | string, meta?: ValidationMeta) => void): BinaryColumnDef;
|
|
123
124
|
notNull(): BinaryColumnNotNullDef;
|
|
124
125
|
JSONSchema(schema: object, options?: Options): BinaryColumnDef;
|
|
125
126
|
serializable(value: boolean): BinaryColumnDef;
|
|
@@ -129,7 +130,7 @@ declare namespace r {
|
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
export interface BinaryColumnNotNullDef {
|
|
132
|
-
validate(validator: (value: Buffer | string, meta
|
|
133
|
+
validate(validator: (value: Buffer | string, meta?: ValidationMeta) => void): BinaryColumnNotNullDef;
|
|
133
134
|
JSONSchema(schema: object, options?: Options): BinaryColumnNotNullDef;
|
|
134
135
|
serializable(value: boolean): BinaryColumnNotNullDef;
|
|
135
136
|
as(dbName: string): BinaryColumnNotNullDef;
|
|
@@ -138,7 +139,7 @@ declare namespace r {
|
|
|
138
139
|
}
|
|
139
140
|
|
|
140
141
|
export interface ColumnOf<T> {
|
|
141
|
-
validate(validator: (value?: T, meta
|
|
142
|
+
validate(validator: (value?: T, meta?: ValidationMeta) => void): ColumnOf<T>;
|
|
142
143
|
notNull(): ColumnNotNullOf<T>;
|
|
143
144
|
JSONSchema(schema: object, options?: Options): ColumnOf<T>;
|
|
144
145
|
serializable(value: boolean): ColumnOf<T>;
|
|
@@ -148,7 +149,7 @@ declare namespace r {
|
|
|
148
149
|
}
|
|
149
150
|
|
|
150
151
|
export interface ColumnNotNullOf<T> {
|
|
151
|
-
validate(validator: (value: T, meta
|
|
152
|
+
validate(validator: (value: T, meta?: ValidationMeta) => void): ColumnNotNullOf<T>;
|
|
152
153
|
notNull(): ColumnNotNullOf<T>;
|
|
153
154
|
JSONSchema(schema: object, options?: Options): ColumnNotNullOf<T>;
|
|
154
155
|
serializable(value: boolean): ColumnNotNullOf<T>;
|
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
|
|
|
@@ -659,90 +662,90 @@ interface ColumnType<M> {
|
|
|
659
662
|
|
|
660
663
|
type UuidValidator<M> = M extends NotNull
|
|
661
664
|
? {
|
|
662
|
-
validate(validator: (value: string, meta
|
|
665
|
+
validate(validator: (value: string, meta?: ValidationMeta) => void): UuidColumnTypeDef<M>;
|
|
663
666
|
}
|
|
664
667
|
: {
|
|
665
668
|
validate(
|
|
666
|
-
validator: (value?: string | null, meta
|
|
669
|
+
validator: (value?: string | null, meta?: ValidationMeta) => void
|
|
667
670
|
): UuidColumnTypeDef<M>;
|
|
668
671
|
};
|
|
669
672
|
type StringValidator<M> = M extends NotNull
|
|
670
673
|
? {
|
|
671
|
-
validate(validator: (value: string, meta
|
|
674
|
+
validate(validator: (value: string, meta?: ValidationMeta) => void): StringColumnTypeDef<M>;
|
|
672
675
|
}
|
|
673
676
|
: {
|
|
674
677
|
validate(
|
|
675
|
-
validator: (value?: string | null, meta
|
|
678
|
+
validator: (value?: string | null, meta?: ValidationMeta) => void
|
|
676
679
|
): StringColumnTypeDef<M>;
|
|
677
680
|
};
|
|
678
681
|
type NumericValidator<M> = M extends NotNull
|
|
679
682
|
? {
|
|
680
|
-
validate(validator: (value: number, meta
|
|
683
|
+
validate(validator: (value: number, meta?: ValidationMeta) => void): NumericColumnTypeDef<M>;
|
|
681
684
|
}
|
|
682
685
|
: {
|
|
683
686
|
validate(
|
|
684
|
-
validator: (value?: number | null, meta
|
|
687
|
+
validator: (value?: number | null, meta?: ValidationMeta) => void
|
|
685
688
|
): NumericColumnTypeDef<M>;
|
|
686
689
|
};
|
|
687
690
|
type BigIntValidator<M> = M extends NotNull
|
|
688
691
|
? {
|
|
689
|
-
validate(validator: (value: bigint, meta
|
|
692
|
+
validate(validator: (value: bigint, meta?: ValidationMeta) => void): BigIntColumnTypeDef<M>;
|
|
690
693
|
}
|
|
691
694
|
: {
|
|
692
695
|
validate(
|
|
693
|
-
validator: (value?: bigint | null, meta
|
|
696
|
+
validator: (value?: bigint | null, meta?: ValidationMeta) => void
|
|
694
697
|
): BigIntColumnTypeDef<M>;
|
|
695
698
|
};
|
|
696
699
|
type BinaryValidator<M> = M extends NotNull
|
|
697
700
|
? {
|
|
698
|
-
validate(validator: (value: string, meta
|
|
701
|
+
validate(validator: (value: string, meta?: ValidationMeta) => void): BinaryColumnTypeDef<M>;
|
|
699
702
|
}
|
|
700
703
|
: {
|
|
701
704
|
validate(
|
|
702
|
-
validator: (value?: string | null, meta
|
|
705
|
+
validator: (value?: string | null, meta?: ValidationMeta) => void
|
|
703
706
|
): BinaryColumnTypeDef<M>;
|
|
704
707
|
};
|
|
705
708
|
type BooleanValidator<M> = M extends NotNull
|
|
706
709
|
? {
|
|
707
|
-
validate(validator: (value: boolean, meta
|
|
710
|
+
validate(validator: (value: boolean, meta?: ValidationMeta) => void): BooleanColumnTypeDef<M>;
|
|
708
711
|
}
|
|
709
712
|
: {
|
|
710
713
|
validate(
|
|
711
|
-
validator: (value?: boolean | null, meta
|
|
714
|
+
validator: (value?: boolean | null, meta?: ValidationMeta) => void
|
|
712
715
|
): BooleanColumnTypeDef<M>;
|
|
713
716
|
};
|
|
714
717
|
type JSONValidator<M> = M extends NotNull
|
|
715
718
|
? {
|
|
716
719
|
validate(
|
|
717
|
-
validator: (value: ToJsonType<M>, meta
|
|
720
|
+
validator: (value: ToJsonType<M>, meta?: ValidationMeta) => void
|
|
718
721
|
): JSONColumnTypeDef<M>;
|
|
719
722
|
}
|
|
720
723
|
: {
|
|
721
724
|
validate(
|
|
722
|
-
validator: (value?: ToJsonType<M> | null, meta
|
|
725
|
+
validator: (value?: ToJsonType<M> | null, meta?: ValidationMeta) => void
|
|
723
726
|
): JSONColumnTypeDef<M>;
|
|
724
727
|
};
|
|
725
728
|
type DateValidator<M> = M extends NotNull
|
|
726
729
|
? {
|
|
727
730
|
validate(
|
|
728
|
-
validator: (value: string | Date, meta
|
|
731
|
+
validator: (value: string | Date, meta?: ValidationMeta) => void
|
|
729
732
|
): DateColumnTypeDef<M>;
|
|
730
733
|
}
|
|
731
734
|
: {
|
|
732
735
|
validate(
|
|
733
|
-
validator: (value?: string | Date | null, meta
|
|
736
|
+
validator: (value?: string | Date | null, meta?: ValidationMeta) => void
|
|
734
737
|
): DateColumnTypeDef<M>;
|
|
735
738
|
};
|
|
736
739
|
|
|
737
740
|
type DateWithTimeZoneValidator<M> = M extends NotNull
|
|
738
741
|
? {
|
|
739
742
|
validate(
|
|
740
|
-
validator: (value: string | Date, meta
|
|
743
|
+
validator: (value: string | Date, meta?: ValidationMeta) => void
|
|
741
744
|
): DateWithTimeZoneColumnTypeDef<M>;
|
|
742
745
|
}
|
|
743
746
|
: {
|
|
744
747
|
validate(
|
|
745
|
-
validator: (value?: string | Date | null, meta
|
|
748
|
+
validator: (value?: string | Date | null, meta?: ValidationMeta) => void
|
|
746
749
|
): DateWithTimeZoneColumnTypeDef<M>;
|
|
747
750
|
};
|
|
748
751
|
|
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);
|