File tree Expand file tree Collapse file tree 3 files changed +82
-0
lines changed
Expand file tree Collapse file tree 3 files changed +82
-0
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,7 @@ exports.createConnection = function (args) {
108108 connectTimeout : args && args . connectTimeout ,
109109 nestTables : args && args . nestTables ,
110110 ssl : ( args && args . ssl ) ?? config . ssl ,
111+ jsonStrings : args && args . jsonStrings ,
111112 } ;
112113
113114 const conn = driver . createConnection ( params ) ;
@@ -137,6 +138,7 @@ exports.getConfig = function (input) {
137138 connectionLimit : args && args . connectionLimit ,
138139 maxIdle : args && args . maxIdle ,
139140 idleTimeout : args && args . idleTimeout ,
141+ jsonStrings : args && args . jsonStrings ,
140142 } ;
141143 return params ;
142144} ;
Original file line number Diff line number Diff line change 1+ import { test , describe , assert } from 'poku' ;
2+ import { createRequire } from 'node:module' ;
3+
4+ const require = createRequire ( import . meta. url ) ;
5+ const {
6+ createConnection,
7+ describeOptions,
8+ } = require ( '../../../common.test.cjs' ) ;
9+
10+ describe ( 'JSON Parser' , describeOptions ) ;
11+
12+ const connection = createConnection ( ) . promise ( ) ;
13+
14+ Promise . all ( [
15+ test ( async ( ) => {
16+ const [ result ] = await connection . query (
17+ `SELECT CAST('{"test": true}' AS JSON) AS json_result` ,
18+ ) ;
19+
20+ assert . deepStrictEqual (
21+ result [ 0 ] . json_result ,
22+ { test : true } ,
23+ 'Ensure JSON return parsed (query)' ,
24+ ) ;
25+ } ) ,
26+ test ( async ( ) => {
27+ const [ result ] = await connection . execute (
28+ `SELECT CAST('{"test": true}' AS JSON) AS json_result` ,
29+ ) ;
30+
31+ assert . deepStrictEqual (
32+ result [ 0 ] . json_result ,
33+ { test : true } ,
34+ 'Ensure JSON return parsed (execute)' ,
35+ ) ;
36+ } ) ,
37+ ] ) . then ( async ( ) => {
38+ await connection . end ( ) ;
39+ } ) ;
Original file line number Diff line number Diff line change 1+ import { test , describe , assert } from 'poku' ;
2+ import { createRequire } from 'node:module' ;
3+
4+ const require = createRequire ( import . meta. url ) ;
5+ const {
6+ createConnection,
7+ describeOptions,
8+ } = require ( '../../../common.test.cjs' ) ;
9+
10+ describe ( 'JSON String' , describeOptions ) ;
11+
12+ const connection = createConnection ( {
13+ jsonStrings : true ,
14+ } ) . promise ( ) ;
15+
16+ Promise . all ( [
17+ test ( async ( ) => {
18+ const [ result ] = await connection . query (
19+ `SELECT CAST('{"test": true}' AS JSON) AS json_result` ,
20+ ) ;
21+
22+ assert . deepStrictEqual (
23+ result [ 0 ] . json_result ,
24+ '{"test": true}' ,
25+ 'Ensure JSON return as string (query)' ,
26+ ) ;
27+ } ) ,
28+ test ( async ( ) => {
29+ const [ result ] = await connection . execute (
30+ `SELECT CAST('{"test": true}' AS JSON) AS json_result` ,
31+ ) ;
32+
33+ assert . deepStrictEqual (
34+ result [ 0 ] . json_result ,
35+ '{"test": true}' ,
36+ 'Ensure JSON return as string (execute)' ,
37+ ) ;
38+ } ) ,
39+ ] ) . then ( async ( ) => {
40+ await connection . end ( ) ;
41+ } ) ;
You can’t perform that action at this time.
0 commit comments