File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change 1
1
import { Submittable , Connection , QueryResult } from 'pg'
2
2
const Result = require ( 'pg/lib/result.js' )
3
- const EventEmitter = require ( 'events' ) . EventEmitter
4
-
3
+ const utils = require ( 'pg/lib/utils.js' )
5
4
let nextUniqueID = 1 // concept borrowed from org.postgresql.core.v3.QueryExecutorImpl
6
5
7
6
interface BatchQueryConfig {
8
7
name ?: string
9
8
text : string
10
- values ?: string [ ] [ ]
9
+ values ?: any [ ] [ ]
11
10
}
12
11
13
12
class BatchQuery implements Submittable {
@@ -58,7 +57,8 @@ class BatchQuery implements Submittable {
58
57
this . connection . bind ( {
59
58
statement : this . name ,
60
59
values : val ,
61
- portal : this . _portal
60
+ portal : this . _portal ,
61
+ valueMapper : utils . prepareValue ,
62
62
} , true )
63
63
64
64
// maybe we could avoid this for non-select queries
Original file line number Diff line number Diff line change 1
1
import assert from 'assert'
2
- import BatchQuery from '../'
2
+ import BatchQuery from '../src '
3
3
import pg from 'pg'
4
4
5
5
describe ( 'batch query' , function ( ) {
@@ -54,4 +54,20 @@ describe('batch query', function () {
54
54
const resp = await this . client . query ( 'SELECT SUM(value) from bar' )
55
55
assert . strictEqual ( resp . rows [ 0 ] [ 'sum' ] , '3' )
56
56
} )
57
+
58
+ it ( 'If query is for an array' , async function ( ) {
59
+ await this . client . query ( 'INSERT INTO foo (name) VALUES ($1)' , [ 'first' ] )
60
+ await this . client . query ( 'INSERT INTO foo (name) VALUES ($1)' , [ 'second' ] )
61
+ const responses = await this . client . query ( new BatchQuery ( {
62
+ text : `SELECT * from foo where name = ANY($1)` ,
63
+ values : [
64
+ [ [ 'first' , 'third' ] ] ,
65
+ [ [ 'second' , 'fourth' ] ]
66
+ ] ,
67
+ name : 'optional'
68
+ } ) ) . execute ( )
69
+ assert . equal ( responses . length , 2 )
70
+ for ( const response of responses ) {
71
+ assert . strictEqual ( response . rowCount , 1 )
72
+ } } )
57
73
} )
You can’t perform that action at this time.
0 commit comments