@@ -104,15 +104,13 @@ export class DuckDBDataSource extends DataSource<any, DuckDBOptions> {
104
104
// create new connection for each query
105
105
const parameters = Array . from ( bindParams . values ( ) ) ;
106
106
this . logRequest ( firstDataSQL , parameters , options ) ;
107
- const connection = db . connect ( ) ;
108
- await this . loadExtensions ( connection , configurationParameters ) ;
109
- await this . setExecConfig ( connection ) ;
110
107
if ( restDataSQL ) this . logRequest ( restDataSQL , parameters , options ) ;
111
108
const [ firstData , restDataStream ] = await this . acquireData (
112
109
firstDataSQL ,
113
110
restDataSQL ,
114
111
parameters ,
115
- db
112
+ db ,
113
+ configurationParameters
116
114
) ;
117
115
const readable = this . createReadableStream ( firstData , restDataStream ) ;
118
116
return {
@@ -168,15 +166,24 @@ export class DuckDBDataSource extends DataSource<any, DuckDBOptions> {
168
166
firstDataSql : string ,
169
167
restDataSql : string | undefined ,
170
168
parameters : any [ ] ,
171
- db : duckdb . Database
169
+ db : duckdb . Database ,
170
+ configurationParameters : ConfigurationParameters
172
171
) {
173
172
// conn.all() is faster then stream.checkChunk().
174
173
// For the small size data we use conn.all() to get the data at once
175
174
// To limit memory use and prevent server crashes, we will use conn.all() to acquire the initial chunk of data, then conn.stream() to receive the remainder of the data.
175
+ const c1 = db . connect ( ) ;
176
+ const c2 = db . connect ( ) ;
177
+ await Promise . all ( [
178
+ await this . loadExtensions ( c1 , configurationParameters ) ,
179
+ await this . setExecConfig ( c1 ) ,
180
+ await this . loadExtensions ( c2 , configurationParameters ) ,
181
+ await this . setExecConfig ( c2 ) ,
182
+ ] ) ;
183
+
176
184
return await Promise . all ( [
177
185
new Promise < duckdb . TableData > ( ( resolve , reject ) => {
178
- const c = db . connect ( ) ;
179
- c . all (
186
+ c1 . all (
180
187
firstDataSql ,
181
188
...parameters ,
182
189
( err : duckdb . DuckDbError | null , res : duckdb . TableData ) => {
@@ -190,8 +197,7 @@ export class DuckDBDataSource extends DataSource<any, DuckDBOptions> {
190
197
new Promise < duckdb . QueryResult | undefined > ( ( resolve , reject ) => {
191
198
if ( ! restDataSql ) resolve ( undefined ) ;
192
199
try {
193
- const c = db . connect ( ) ;
194
- const result = c . stream ( restDataSql , ...parameters ) ;
200
+ const result = c2 . stream ( restDataSql , ...parameters ) ;
195
201
resolve ( result ) ;
196
202
} catch ( err : any ) {
197
203
reject ( err ) ;
0 commit comments