@@ -279,6 +279,50 @@ export function processSharedOptions<
279
279
280
280
export type Releasers = Array < ( ) => void | Promise < void > > ;
281
281
282
+ export async function assertPool (
283
+ compiledSharedOptions : CompiledSharedOptions ,
284
+ releasers : Releasers ,
285
+ ) : Promise < Pool > {
286
+ const {
287
+ resolvedPreset : {
288
+ worker : { maxPoolSize, connectionString } ,
289
+ } ,
290
+ _rawOptions,
291
+ } = compiledSharedOptions ;
292
+ assert . ok (
293
+ // NOTE: we explicitly want `_rawOptions.connectionString` here - we don't
294
+ // mind if `connectionString` is set as part of the preset.
295
+ ! _rawOptions . pgPool || ! _rawOptions . connectionString ,
296
+ "Both `pgPool` and `connectionString` are set, at most one of these options should be provided" ,
297
+ ) ;
298
+ let pgPool : Pool ;
299
+ if ( _rawOptions . pgPool ) {
300
+ pgPool = _rawOptions . pgPool ;
301
+ if ( pgPool . listeners ( "error" ) . length === 0 ) {
302
+ console . warn (
303
+ `Your pool doesn't have error handlers! See: https://err.red/wpeh` ,
304
+ ) ;
305
+ installErrorHandlers ( compiledSharedOptions , releasers , pgPool ) ;
306
+ }
307
+ } else if ( connectionString ) {
308
+ pgPool = makeNewPool ( compiledSharedOptions , releasers , {
309
+ connectionString,
310
+ max : maxPoolSize ,
311
+ } ) ;
312
+ } else if ( process . env . PGDATABASE ) {
313
+ pgPool = makeNewPool ( compiledSharedOptions , releasers , {
314
+ /* Pool automatically pulls settings from envvars */
315
+ max : maxPoolSize ,
316
+ } ) ;
317
+ } else {
318
+ throw new Error (
319
+ "You must either specify `pgPool` or `connectionString`, or you must make the `DATABASE_URL` or `PG*` environmental variables available." ,
320
+ ) ;
321
+ }
322
+
323
+ return pgPool ;
324
+ }
325
+
282
326
function makeNewPool (
283
327
compiledSharedOptions : CompiledSharedOptions ,
284
328
releasers : Releasers ,
@@ -340,50 +384,6 @@ function installErrorHandlers(
340
384
return pgPool ;
341
385
}
342
386
343
- export async function assertPool (
344
- compiledSharedOptions : CompiledSharedOptions ,
345
- releasers : Releasers ,
346
- ) : Promise < Pool > {
347
- const {
348
- resolvedPreset : {
349
- worker : { maxPoolSize, connectionString } ,
350
- } ,
351
- _rawOptions,
352
- } = compiledSharedOptions ;
353
- assert . ok (
354
- // NOTE: we explicitly want `_rawOptions.connectionString` here - we don't
355
- // mind if `connectionString` is set as part of the preset.
356
- ! _rawOptions . pgPool || ! _rawOptions . connectionString ,
357
- "Both `pgPool` and `connectionString` are set, at most one of these options should be provided" ,
358
- ) ;
359
- let pgPool : Pool ;
360
- if ( _rawOptions . pgPool ) {
361
- pgPool = _rawOptions . pgPool ;
362
- if ( pgPool . listeners ( "error" ) . length === 0 ) {
363
- console . warn (
364
- `Your pool doesn't have error handlers! See: https://err.red/wpeh` ,
365
- ) ;
366
- installErrorHandlers ( compiledSharedOptions , releasers , pgPool ) ;
367
- }
368
- } else if ( connectionString ) {
369
- pgPool = makeNewPool ( compiledSharedOptions , releasers , {
370
- connectionString,
371
- max : maxPoolSize ,
372
- } ) ;
373
- } else if ( process . env . PGDATABASE ) {
374
- pgPool = makeNewPool ( compiledSharedOptions , releasers , {
375
- /* Pool automatically pulls settings from envvars */
376
- max : maxPoolSize ,
377
- } ) ;
378
- } else {
379
- throw new Error (
380
- "You must either specify `pgPool` or `connectionString`, or you must make the `DATABASE_URL` or `PG*` environmental variables available." ,
381
- ) ;
382
- }
383
-
384
- return pgPool ;
385
- }
386
-
387
387
export type Release = ( ) => PromiseOrDirect < void > ;
388
388
389
389
export async function withReleasers < T > (
0 commit comments