orange-orm 4.7.0-beta.2 → 4.7.0-beta.3

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 CHANGED
@@ -286,6 +286,10 @@ npm install sqlite3
286
286
  ```javascript
287
287
  import map from './map';
288
288
  const db = map.sqlite('demo.db');
289
+ // … use the database …
290
+
291
+ // IMPORTANT for serverless functions:
292
+ await db.close(); // closes the client connection
289
293
  ```
290
294
  __With connection pool__
291
295
  ```bash
@@ -294,7 +298,14 @@ npm install sqlite3
294
298
  ```javascript
295
299
  import map from './map';
296
300
  const db = map.sqlite('demo.db', { size: 10 });
301
+ // … use the pool …
302
+
303
+ // IMPORTANT for serverless functions:
304
+ await pool.close(); // closes all pooled connections
297
305
  ```
306
+ __Why close ?__
307
+ In serverless environments (e.g. AWS Lambda, Vercel, Cloudflare Workers) execution contexts are frequently frozen and resumed. Explicitly closing the client or pool ensures that file handles are released promptly and prevents “database locked” errors between invocations.
308
+
298
309
  __From the browser__
299
310
  You can securely use Orange from the browser by utilizing the Express plugin, which serves to safeguard sensitive database credentials from exposure at the client level. This technique bypasses the need to transmit raw SQL queries directly from the client to the server. Instead, it logs method calls initiated by the client, which are later replayed and authenticated on the server. This not only reinforces security by preventing the disclosure of raw SQL queries on the client side but also facilitates a smoother operation. Essentially, this method mirrors a traditional REST API, augmented with advanced TypeScript tooling for enhanced functionality. You can read more about it in the section called [In the browser](#user-content-in-the-browser)
300
311
  <sub>📄 server.ts</sub>
@@ -2727,6 +2727,11 @@ function requireClient () {
2727
2727
  client.http = onProvider.bind(null, 'http');//todo
2728
2728
  client.mysql = onProvider.bind(null, 'mysql');
2729
2729
  client.express = express;
2730
+ client.close = close;
2731
+
2732
+ function close() {
2733
+ return client.db.end ? client.db.end() : Promise.resolve();
2734
+ }
2730
2735
 
2731
2736
  function onProvider(name, ...args) {
2732
2737
  let db = providers[name].apply(null, args);
@@ -13919,6 +13924,7 @@ function requireNewGenericPool () {
13919
13924
  poolOptions = poolOptions || {};
13920
13925
  // @ts-ignore
13921
13926
  var pool = genericPool.Pool({
13927
+ min: poolOptions.min || 0,
13922
13928
  max: 1,
13923
13929
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
13924
13930
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -14003,11 +14009,8 @@ function requireNewDatabase$1 () {
14003
14009
  function newDatabase(d1Database, poolOptions) {
14004
14010
  if (!d1Database)
14005
14011
  throw new Error('Missing d1Database');
14006
- var pool;
14007
- if (!poolOptions)
14008
- pool = newPool.bind(null,d1Database, poolOptions);
14009
- else
14010
- pool = newPool(d1Database, poolOptions);
14012
+ poolOptions = poolOptions || { min: 1 };
14013
+ var pool = newPool(d1Database, poolOptions);
14011
14014
 
14012
14015
  let c = {poolFactory: pool, hostLocal, express};
14013
14016
 
@@ -14455,10 +14458,8 @@ function requireNewTransaction () {
14455
14458
 
14456
14459
  function newResolveTransaction(domain, pool, { readonly = false } = {}) {
14457
14460
  var rdb = { poolFactory: pool };
14458
- if (!pool.connect) {
14461
+ if (!pool.connect)
14459
14462
  pool = pool();
14460
- rdb.pool = pool;
14461
- }
14462
14463
 
14463
14464
  rdb.engine = 'pg';
14464
14465
  rdb.encodeDate = encodeDate;
@@ -14570,6 +14571,7 @@ function requireNewPgPool () {
14570
14571
 
14571
14572
  //@ts-ignore
14572
14573
  const pool = genericPool.Pool({
14574
+ min: poolOptions.min || 0,
14573
14575
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
14574
14576
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
14575
14577
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -14705,11 +14707,8 @@ function requireNewDatabase () {
14705
14707
  let setSessionSingleton = requireSetSessionSingleton();
14706
14708
 
14707
14709
  function newDatabase(connectionString, poolOptions) {
14708
- var pool;
14709
- if (!poolOptions)
14710
- pool = newPool.bind(null, connectionString, poolOptions);
14711
- else
14712
- pool = newPool(connectionString, poolOptions);
14710
+ poolOptions = poolOptions || { min: 1 };
14711
+ var pool = newPool(connectionString, poolOptions);
14713
14712
 
14714
14713
  let c = { poolFactory: pool, hostLocal, express };
14715
14714
 
package/dist/index.mjs CHANGED
@@ -2729,6 +2729,11 @@ function requireClient () {
2729
2729
  client.http = onProvider.bind(null, 'http');//todo
2730
2730
  client.mysql = onProvider.bind(null, 'mysql');
2731
2731
  client.express = express;
2732
+ client.close = close;
2733
+
2734
+ function close() {
2735
+ return client.db.end ? client.db.end() : Promise.resolve();
2736
+ }
2732
2737
 
2733
2738
  function onProvider(name, ...args) {
2734
2739
  let db = providers[name].apply(null, args);
@@ -13945,6 +13950,7 @@ function requireNewGenericPool$7 () {
13945
13950
  connectionString.dateStrings = true;
13946
13951
  poolOptions = poolOptions || {};
13947
13952
  var pool = genericPool.Pool({
13953
+ min: poolOptions.min || 0,
13948
13954
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
13949
13955
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
13950
13956
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -14047,11 +14053,8 @@ function requireNewDatabase$b () {
14047
14053
  function newDatabase(connectionString, poolOptions) {
14048
14054
  if (!connectionString)
14049
14055
  throw new Error('Connection string cannot be empty');
14050
- var pool;
14051
- if (!poolOptions)
14052
- pool = newPool.bind(null, connectionString, poolOptions);
14053
- else
14054
- pool = newPool(connectionString, poolOptions);
14056
+ poolOptions = poolOptions || { min: 1 };
14057
+ var pool = newPool(connectionString, poolOptions);
14055
14058
 
14056
14059
  let c = { poolFactory: pool, hostLocal, express };
14057
14060
 
@@ -14497,10 +14500,8 @@ function requireNewTransaction$a () {
14497
14500
 
14498
14501
  function newResolveTransaction(domain, pool, { readonly = false } = {}) {
14499
14502
  var rdb = { poolFactory: pool };
14500
- if (!pool.connect) {
14503
+ if (!pool.connect)
14501
14504
  pool = pool();
14502
- rdb.pool = pool;
14503
- }
14504
14505
 
14505
14506
  rdb.engine = 'pg';
14506
14507
  rdb.encodeDate = encodeDate;
@@ -14612,6 +14613,7 @@ function requireNewPgPool$2 () {
14612
14613
 
14613
14614
  //@ts-ignore
14614
14615
  const pool = genericPool.Pool({
14616
+ min: poolOptions.min || 0,
14615
14617
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
14616
14618
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
14617
14619
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -14747,11 +14749,8 @@ function requireNewDatabase$a () {
14747
14749
  let setSessionSingleton = requireSetSessionSingleton();
14748
14750
 
14749
14751
  function newDatabase(connectionString, poolOptions) {
14750
- var pool;
14751
- if (!poolOptions)
14752
- pool = newPool.bind(null, connectionString, poolOptions);
14753
- else
14754
- pool = newPool(connectionString, poolOptions);
14752
+ poolOptions = poolOptions || { min: 1 };
14753
+ var pool = newPool(connectionString, poolOptions);
14755
14754
 
14756
14755
  let c = { poolFactory: pool, hostLocal, express };
14757
14756
 
@@ -15156,6 +15155,7 @@ function requireNewPgPool$1 () {
15156
15155
 
15157
15156
  //@ts-ignore
15158
15157
  const pool = genericPool.Pool({
15158
+ min: poolOptions.min || 0,
15159
15159
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
15160
15160
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
15161
15161
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -15256,11 +15256,8 @@ function requireNewDatabase$9 () {
15256
15256
  function newDatabase(connectionString, poolOptions) {
15257
15257
  if (!connectionString)
15258
15258
  throw new Error('Connection string cannot be empty');
15259
- var pool;
15260
- if (!poolOptions)
15261
- pool = newPool.bind(null, connectionString, poolOptions);
15262
- else
15263
- pool = newPool(connectionString, poolOptions);
15259
+ poolOptions = poolOptions || { min: 1 };
15260
+ var pool = newPool(connectionString, poolOptions);
15264
15261
 
15265
15262
  let c = { poolFactory: pool, hostLocal, express };
15266
15263
 
@@ -15589,6 +15586,7 @@ function requireNewPgPool () {
15589
15586
 
15590
15587
  // @ts-ignore
15591
15588
  var pool = genericPool.Pool({
15589
+ min: poolOptions.min || 0,
15592
15590
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
15593
15591
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
15594
15592
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -15730,11 +15728,8 @@ function requireNewDatabase$8 () {
15730
15728
  function newDatabase(connectionString, poolOptions) {
15731
15729
  if (!connectionString)
15732
15730
  throw new Error('Connection string cannot be empty');
15733
- var pool;
15734
- if (!poolOptions)
15735
- pool = newPool.bind(null, connectionString, poolOptions);
15736
- else
15737
- pool = newPool(connectionString, poolOptions);
15731
+ poolOptions = poolOptions || { min: 1 };
15732
+ var pool = newPool(connectionString, poolOptions);
15738
15733
 
15739
15734
  let c = { poolFactory: pool, hostLocal, express };
15740
15735
 
@@ -16234,6 +16229,7 @@ function requireNewGenericPool$6 () {
16234
16229
 
16235
16230
  poolOptions = poolOptions || {};
16236
16231
  var pool = genericPool.Pool({
16232
+ min: poolOptions.min || 0,
16237
16233
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
16238
16234
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
16239
16235
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -16326,11 +16322,8 @@ function requireNewDatabase$7 () {
16326
16322
  function newDatabase(connectionString, poolOptions) {
16327
16323
  if (!connectionString)
16328
16324
  throw new Error('Connection string cannot be empty');
16329
- var pool;
16330
- if (!poolOptions)
16331
- pool = newPool.bind(null,connectionString, poolOptions);
16332
- else
16333
- pool = newPool(connectionString, poolOptions);
16325
+ poolOptions = poolOptions || { min: 1 };
16326
+ var pool = newPool(connectionString, poolOptions);
16334
16327
 
16335
16328
  let c = {poolFactory: pool, hostLocal, express};
16336
16329
 
@@ -16575,6 +16568,7 @@ function requireNewGenericPool$5 () {
16575
16568
  function newGenericPool(connectionString, poolOptions) {
16576
16569
  poolOptions = poolOptions || {};
16577
16570
  var pool = genericPool.Pool({
16571
+ min: poolOptions.min || 0,
16578
16572
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
16579
16573
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
16580
16574
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -16673,11 +16667,8 @@ function requireNewDatabase$6 () {
16673
16667
  function newDatabase(connectionString, poolOptions) {
16674
16668
  if (!connectionString)
16675
16669
  throw new Error('Connection string cannot be empty');
16676
- var pool;
16677
- if (!poolOptions)
16678
- pool = newPool.bind(null,connectionString, poolOptions);
16679
- else
16680
- pool = newPool(connectionString, poolOptions);
16670
+ poolOptions = poolOptions || { min: 1 };
16671
+ var pool = newPool(connectionString, poolOptions);
16681
16672
 
16682
16673
  let c = {poolFactory: pool, hostLocal, express};
16683
16674
 
@@ -16941,6 +16932,7 @@ function requireNewGenericPool$4 () {
16941
16932
  function newGenericPool(connectionString, poolOptions) {
16942
16933
  poolOptions = poolOptions || {};
16943
16934
  var pool = genericPool.Pool({
16935
+ min: poolOptions.min || 0,
16944
16936
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
16945
16937
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
16946
16938
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -17039,11 +17031,8 @@ function requireNewDatabase$5 () {
17039
17031
  function newDatabase(connectionString, poolOptions) {
17040
17032
  if (!connectionString)
17041
17033
  throw new Error('Connection string cannot be empty');
17042
- var pool;
17043
- if (!poolOptions)
17044
- pool = newPool.bind(null,connectionString, poolOptions);
17045
- else
17046
- pool = newPool(connectionString, poolOptions);
17034
+ poolOptions = poolOptions || { min: 1 };
17035
+ var pool = newPool(connectionString, poolOptions);
17047
17036
 
17048
17037
  let c = {poolFactory: pool, hostLocal, express};
17049
17038
 
@@ -17304,6 +17293,7 @@ function requireNewGenericPool$3 () {
17304
17293
  poolOptions = poolOptions || {};
17305
17294
  // @ts-ignore
17306
17295
  var pool = genericPool.Pool({
17296
+ min: poolOptions.min || 0,
17307
17297
  max: 1,
17308
17298
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
17309
17299
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -17388,11 +17378,8 @@ function requireNewDatabase$4 () {
17388
17378
  function newDatabase(d1Database, poolOptions) {
17389
17379
  if (!d1Database)
17390
17380
  throw new Error('Missing d1Database');
17391
- var pool;
17392
- if (!poolOptions)
17393
- pool = newPool.bind(null,d1Database, poolOptions);
17394
- else
17395
- pool = newPool(d1Database, poolOptions);
17381
+ poolOptions = poolOptions || { min: 1 };
17382
+ var pool = newPool(d1Database, poolOptions);
17396
17383
 
17397
17384
  let c = {poolFactory: pool, hostLocal, express};
17398
17385
 
@@ -18004,6 +17991,7 @@ function requireNewGenericPool$2 () {
18004
17991
  function newGenericPool(connectionString, poolOptions) {
18005
17992
  poolOptions = poolOptions || {};
18006
17993
  var pool = genericPool.Pool({
17994
+ min: poolOptions.min || 0,
18007
17995
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
18008
17996
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
18009
17997
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -18104,11 +18092,8 @@ function requireNewDatabase$3 () {
18104
18092
  function newDatabase(connectionString, poolOptions) {
18105
18093
  if (!connectionString)
18106
18094
  throw new Error('Connection string cannot be empty');
18107
- var pool;
18108
- if (!poolOptions)
18109
- pool = newPool.bind(null, connectionString, poolOptions);
18110
- else
18111
- pool = newPool(connectionString, poolOptions);
18095
+ poolOptions = poolOptions || { min: 1 };
18096
+ var pool = newPool(connectionString, poolOptions);
18112
18097
 
18113
18098
  let c = { poolFactory: pool, hostLocal, express };
18114
18099
 
@@ -18830,6 +18815,7 @@ function requireNewGenericPool$1 () {
18830
18815
  connectionString.options = { ...connectionString.options, ...{ useColumnNames: true } };
18831
18816
  poolOptions = poolOptions || {};
18832
18817
  var pool = genericPool.Pool({
18818
+ min: poolOptions.min || 0,
18833
18819
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
18834
18820
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
18835
18821
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -18932,11 +18918,8 @@ function requireNewDatabase$2 () {
18932
18918
  function newDatabase(connectionString, poolOptions) {
18933
18919
  if (!connectionString)
18934
18920
  throw new Error('Connection string cannot be empty');
18935
- var pool;
18936
- if (!poolOptions)
18937
- pool = newPool.bind(null, connectionString, poolOptions);
18938
- else
18939
- pool = newPool(connectionString, poolOptions);
18921
+ poolOptions = poolOptions || { min: 1 };
18922
+ var pool = newPool(connectionString, poolOptions);
18940
18923
 
18941
18924
  let c = { poolFactory: pool, hostLocal, express };
18942
18925
 
@@ -19527,11 +19510,8 @@ function requireNewDatabase$1 () {
19527
19510
  function newDatabase(connectionString, poolOptions) {
19528
19511
  if (!connectionString)
19529
19512
  throw new Error('Connection string cannot be empty');
19530
- var pool;
19531
- if (!poolOptions)
19532
- pool = newPool.bind(null,connectionString, poolOptions);
19533
- else
19534
- pool = newPool(connectionString, poolOptions);
19513
+ poolOptions = poolOptions || { min: 1 };
19514
+ var pool = newPool(connectionString, poolOptions);
19535
19515
 
19536
19516
  let c = {poolFactory: pool, hostLocal, express};
19537
19517
 
@@ -20211,6 +20191,7 @@ function requireNewGenericPool () {
20211
20191
  function newGenericPool(connectionString, poolOptions) {
20212
20192
  poolOptions = poolOptions || {};
20213
20193
  var pool = genericPool.Pool({
20194
+ min: poolOptions.min || 0,
20214
20195
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
20215
20196
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
20216
20197
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -20313,11 +20294,8 @@ function requireNewDatabase () {
20313
20294
  function newDatabase(connectionString, poolOptions) {
20314
20295
  if (!connectionString)
20315
20296
  throw new Error('Connection string cannot be empty');
20316
- var pool;
20317
- if (!poolOptions)
20318
- pool = newPool.bind(null, connectionString, poolOptions);
20319
- else
20320
- pool = newPool(connectionString, poolOptions);
20297
+ poolOptions = poolOptions || { min: 1 };
20298
+ var pool = newPool(connectionString, poolOptions);
20321
20299
 
20322
20300
  let c = { poolFactory: pool, hostLocal, express };
20323
20301
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orange-orm",
3
- "version": "4.7.0-beta.2",
3
+ "version": "4.7.0-beta.3",
4
4
  "main": "./src/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "browser": "./dist/index.browser.mjs",
@@ -15,11 +15,8 @@ let setSessionSingleton = require('../table/setSessionSingleton');
15
15
  function newDatabase(connectionString, poolOptions) {
16
16
  if (!connectionString)
17
17
  throw new Error('Connection string cannot be empty');
18
- var pool;
19
- if (!poolOptions)
20
- pool = newPool.bind(null, connectionString, poolOptions);
21
- else
22
- pool = newPool(connectionString, poolOptions);
18
+ poolOptions = poolOptions || { min: 1 };
19
+ var pool = newPool(connectionString, poolOptions);
23
20
 
24
21
  let c = { poolFactory: pool, hostLocal, express };
25
22
 
@@ -29,6 +29,7 @@ function newPgPool(connectionString, poolOptions = {}) {
29
29
 
30
30
  //@ts-ignore
31
31
  const pool = genericPool.Pool({
32
+ min: poolOptions.min || 0,
32
33
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
33
34
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
34
35
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -13,11 +13,8 @@ let setSessionSingleton = require('../table/setSessionSingleton');
13
13
  function newDatabase(connectionString, poolOptions) {
14
14
  if (!connectionString)
15
15
  throw new Error('Connection string cannot be empty');
16
- var pool;
17
- if (!poolOptions)
18
- pool = newPool.bind(null,connectionString, poolOptions);
19
- else
20
- pool = newPool(connectionString, poolOptions);
16
+ poolOptions = poolOptions || { min: 1 };
17
+ var pool = newPool(connectionString, poolOptions);
21
18
 
22
19
  let c = {poolFactory: pool, hostLocal, express};
23
20
 
@@ -7,6 +7,7 @@ var Database;
7
7
  function newGenericPool(connectionString, poolOptions) {
8
8
  poolOptions = poolOptions || {};
9
9
  var pool = genericPool.Pool({
10
+ min: poolOptions.min || 0,
10
11
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
11
12
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
12
13
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -65,6 +65,11 @@ function rdbClient(options = {}) {
65
65
  client.http = onProvider.bind(null, 'http');//todo
66
66
  client.mysql = onProvider.bind(null, 'mysql');
67
67
  client.express = express;
68
+ client.close = close;
69
+
70
+ function close() {
71
+ return client.db.end ? client.db.end() : Promise.resolve();
72
+ }
68
73
 
69
74
  function onProvider(name, ...args) {
70
75
  let db = providers[name].apply(null, args);
@@ -13,11 +13,8 @@ let setSessionSingleton = require('../table/setSessionSingleton');
13
13
  function newDatabase(d1Database, poolOptions) {
14
14
  if (!d1Database)
15
15
  throw new Error('Missing d1Database');
16
- var pool;
17
- if (!poolOptions)
18
- pool = newPool.bind(null,d1Database, poolOptions);
19
- else
20
- pool = newPool(d1Database, poolOptions);
16
+ poolOptions = poolOptions || { min: 1 };
17
+ var pool = newPool(d1Database, poolOptions);
21
18
 
22
19
  let c = {poolFactory: pool, hostLocal, express};
23
20
 
@@ -6,6 +6,7 @@ function newGenericPool(d1Database, poolOptions) {
6
6
  poolOptions = poolOptions || {};
7
7
  // @ts-ignore
8
8
  var pool = genericPool.Pool({
9
+ min: poolOptions.min || 0,
9
10
  max: 1,
10
11
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
11
12
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
package/src/index.d.ts CHANGED
@@ -11,7 +11,7 @@ declare function r(config: r.Config): unknown;
11
11
  declare namespace r {
12
12
 
13
13
  function table(name: string): Table;
14
- function end(): Promise<void>;
14
+ function close(): Promise<void>;
15
15
  function d1(database: D1Database, options?: PoolOptions): Pool;
16
16
  function postgres(connectionString: string, options?: PoolOptions): Pool;
17
17
  function pglite(config?: PGliteOptions | string | undefined, options?: PoolOptions): Pool;
package/src/map.d.ts CHANGED
@@ -86,6 +86,7 @@ type MappedDbInstance<T> = {
86
86
  ? MappedTable<T[K]>
87
87
  : never;
88
88
  } & {
89
+ close(): Promise<void>;
89
90
  filter: Filter;
90
91
  and(filter: Filter | RawFilter[], ...filters: RawFilter[]): Filter;
91
92
  or(filter: Filter | RawFilter[], ...filters: RawFilter[]): Filter;
@@ -13,11 +13,8 @@ let setSessionSingleton = require('../table/setSessionSingleton');
13
13
  function newDatabase(connectionString, poolOptions) {
14
14
  if (!connectionString)
15
15
  throw new Error('Connection string cannot be empty');
16
- var pool;
17
- if (!poolOptions)
18
- pool = newPool.bind(null, connectionString, poolOptions);
19
- else
20
- pool = newPool(connectionString, poolOptions);
16
+ poolOptions = poolOptions || { min: 1 };
17
+ var pool = newPool(connectionString, poolOptions);
21
18
 
22
19
  let c = { poolFactory: pool, hostLocal, express };
23
20
 
@@ -8,6 +8,7 @@ var mssql;
8
8
  function newGenericPool(connectionString, poolOptions) {
9
9
  poolOptions = poolOptions || {};
10
10
  var pool = genericPool.Pool({
11
+ min: poolOptions.min || 0,
11
12
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
12
13
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
13
14
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -13,11 +13,8 @@ let setSessionSingleton = require('../table/setSessionSingleton');
13
13
  function newDatabase(connectionString, poolOptions) {
14
14
  if (!connectionString)
15
15
  throw new Error('Connection string cannot be empty');
16
- var pool;
17
- if (!poolOptions)
18
- pool = newPool.bind(null, connectionString, poolOptions);
19
- else
20
- pool = newPool(connectionString, poolOptions);
16
+ poolOptions = poolOptions || { min: 1 };
17
+ var pool = newPool(connectionString, poolOptions);
21
18
 
22
19
  let c = { poolFactory: pool, hostLocal, express };
23
20
 
@@ -11,6 +11,7 @@ function newGenericPool(connectionString, poolOptions) {
11
11
  connectionString.dateStrings = true;
12
12
  poolOptions = poolOptions || {};
13
13
  var pool = genericPool.Pool({
14
+ min: poolOptions.min || 0,
14
15
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
15
16
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
16
17
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -13,11 +13,8 @@ let setSessionSingleton = require('../table/setSessionSingleton');
13
13
  function newDatabase(connectionString, poolOptions) {
14
14
  if (!connectionString)
15
15
  throw new Error('Connection string cannot be empty');
16
- var pool;
17
- if (!poolOptions)
18
- pool = newPool.bind(null,connectionString, poolOptions);
19
- else
20
- pool = newPool(connectionString, poolOptions);
16
+ poolOptions = poolOptions || { min: 1 };
17
+ var pool = newPool(connectionString, poolOptions);
21
18
 
22
19
  let c = {poolFactory: pool, hostLocal, express};
23
20
 
@@ -8,6 +8,7 @@ function newGenericPool(connectionString, poolOptions) {
8
8
 
9
9
  poolOptions = poolOptions || {};
10
10
  var pool = genericPool.Pool({
11
+ min: poolOptions.min || 0,
11
12
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
12
13
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
13
14
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -13,11 +13,8 @@ let setSessionSingleton = require('../table/setSessionSingleton');
13
13
  function newDatabase(connectionString, poolOptions) {
14
14
  if (!connectionString)
15
15
  throw new Error('Connection string cannot be empty');
16
- var pool;
17
- if (!poolOptions)
18
- pool = newPool.bind(null, connectionString, poolOptions);
19
- else
20
- pool = newPool(connectionString, poolOptions);
16
+ poolOptions = poolOptions || { min: 1 };
17
+ var pool = newPool(connectionString, poolOptions);
21
18
 
22
19
  let c = { poolFactory: pool, hostLocal, express };
23
20
 
@@ -8,6 +8,7 @@ var oracle;
8
8
  function newGenericPool(connectionString, poolOptions) {
9
9
  poolOptions = poolOptions || {};
10
10
  var pool = genericPool.Pool({
11
+ min: poolOptions.min || 0,
11
12
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
12
13
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
13
14
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -15,11 +15,8 @@ let setSessionSingleton = require('../table/setSessionSingleton');
15
15
  function newDatabase(connectionString, poolOptions) {
16
16
  if (!connectionString)
17
17
  throw new Error('Connection string cannot be empty');
18
- var pool;
19
- if (!poolOptions)
20
- pool = newPool.bind(null, connectionString, poolOptions);
21
- else
22
- pool = newPool(connectionString, poolOptions);
18
+ poolOptions = poolOptions || { min: 1 };
19
+ var pool = newPool(connectionString, poolOptions);
23
20
 
24
21
  let c = { poolFactory: pool, hostLocal, express };
25
22
 
@@ -12,6 +12,7 @@ function newPgPool(connectionString, poolOptions) {
12
12
 
13
13
  // @ts-ignore
14
14
  var pool = genericPool.Pool({
15
+ min: poolOptions.min || 0,
15
16
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
16
17
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
17
18
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -13,11 +13,8 @@ let releaseDbClient = require('../table/releaseDbClient');
13
13
  let setSessionSingleton = require('../table/setSessionSingleton');
14
14
 
15
15
  function newDatabase(connectionString, poolOptions) {
16
- var pool;
17
- if (!poolOptions)
18
- pool = newPool.bind(null, connectionString, poolOptions);
19
- else
20
- pool = newPool(connectionString, poolOptions);
16
+ poolOptions = poolOptions || { min: 1 };
17
+ var pool = newPool(connectionString, poolOptions);
21
18
 
22
19
  let c = { poolFactory: pool, hostLocal, express };
23
20
 
@@ -12,10 +12,8 @@ var quote = require('../pg/quote');
12
12
 
13
13
  function newResolveTransaction(domain, pool, { readonly = false } = {}) {
14
14
  var rdb = { poolFactory: pool };
15
- if (!pool.connect) {
15
+ if (!pool.connect)
16
16
  pool = pool();
17
- rdb.pool = pool;
18
- }
19
17
 
20
18
  rdb.engine = 'pg';
21
19
  rdb.encodeDate = encodeDate;
@@ -11,6 +11,7 @@ function newPgPool(connectionString, poolOptions = {}) {
11
11
 
12
12
  //@ts-ignore
13
13
  const pool = genericPool.Pool({
14
+ min: poolOptions.min || 0,
14
15
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
15
16
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
16
17
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -13,11 +13,8 @@ let setSessionSingleton = require('../table/setSessionSingleton');
13
13
  function newDatabase(connectionString, poolOptions) {
14
14
  if (!connectionString)
15
15
  throw new Error('Connection string cannot be empty');
16
- var pool;
17
- if (!poolOptions)
18
- pool = newPool.bind(null,connectionString, poolOptions);
19
- else
20
- pool = newPool(connectionString, poolOptions);
16
+ poolOptions = poolOptions || { min: 1 };
17
+ var pool = newPool(connectionString, poolOptions);
21
18
 
22
19
  let c = {poolFactory: pool, hostLocal, express};
23
20
 
@@ -13,11 +13,8 @@ let setSessionSingleton = require('../table/setSessionSingleton');
13
13
  function newDatabase(connectionString, poolOptions) {
14
14
  if (!connectionString)
15
15
  throw new Error('Connection string cannot be empty');
16
- var pool;
17
- if (!poolOptions)
18
- pool = newPool.bind(null,connectionString, poolOptions);
19
- else
20
- pool = newPool(connectionString, poolOptions);
16
+ poolOptions = poolOptions || { min: 1 };
17
+ var pool = newPool(connectionString, poolOptions);
21
18
 
22
19
  let c = {poolFactory: pool, hostLocal, express};
23
20
 
@@ -7,6 +7,7 @@ var sqlite;
7
7
  function newGenericPool(connectionString, poolOptions) {
8
8
  poolOptions = poolOptions || {};
9
9
  var pool = genericPool.Pool({
10
+ min: poolOptions.min || 0,
10
11
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
11
12
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
12
13
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
@@ -13,11 +13,8 @@ let setSessionSingleton = require('../table/setSessionSingleton');
13
13
  function newDatabase(connectionString, poolOptions) {
14
14
  if (!connectionString)
15
15
  throw new Error('Connection string cannot be empty');
16
- var pool;
17
- if (!poolOptions)
18
- pool = newPool.bind(null, connectionString, poolOptions);
19
- else
20
- pool = newPool(connectionString, poolOptions);
16
+ poolOptions = poolOptions || { min: 1 };
17
+ var pool = newPool(connectionString, poolOptions);
21
18
 
22
19
  let c = { poolFactory: pool, hostLocal, express };
23
20
 
@@ -13,6 +13,7 @@ function newGenericPool(connectionString, poolOptions) {
13
13
  connectionString.options = { ...connectionString.options, ...{ useColumnNames: true } };
14
14
  poolOptions = poolOptions || {};
15
15
  var pool = genericPool.Pool({
16
+ min: poolOptions.min || 0,
16
17
  max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
17
18
  idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
18
19
  reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,