From 08973c58f56a8b70b87772dbface4f956b2862e0 Mon Sep 17 00:00:00 2001 From: Kyriakos Barbounakis Date: Tue, 6 Oct 2020 06:01:42 +0000 Subject: [PATCH] migrate from version 2.2 --- README.md | 29 +++++++++++++++++++++++------ index.js | 8 ++++++++ spec/GenericPoolAdapter.spec.js | 6 +++++- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d9f971b..3c1614e 100644 --- a/README.md +++ b/README.md @@ -33,11 +33,28 @@ Register Generic Pool Adapter on app.json as follows: The generic pool adapter will try to instantiate the adapter defined in options.adapter property. # Options + ### adapter: The name of the data adapter to be linked with this pool adapter. -### size: -The number of the data adapters that are going to be pooled for new connections. The default value is 25. -### timeout: -A number of milliseconds to wait for getting a new data adapter. If this timeout exceeds, a timeout error will occured. The default value is 30000. -### lifetime -A number of milliseconds which indicates whether or not a pooled data adapter will be automatically ejected from data adapters' collection. The default value is 1200000. + +`@themost/pool` adapter uses [generic-pool](https://github.com/coopernurse/node-pool#documentation). +Read more about `generic-pool` [here](https://github.com/coopernurse/node-pool#documentation) + +Important Note: Upgrade from 2.2.x to 2.5.x + +Replace `@themost/pool@2.2.x` configuration: + + { + "adapter": "development", + "size": 25, + "timeout": 30000, + "lifetime": 1200000 + } + +with: + + { + "adapter": "development", + "max": 25, + "acquireTimeoutMillis": 30000 + } diff --git a/index.js b/index.js index 78b6c06..3d59e9b 100644 --- a/index.js +++ b/index.js @@ -358,6 +358,14 @@ function createInstance(options) { /** * @type {*} */ + // upgrade from 2.2.x + if (typeof options.size === 'number') { + options.max = options.size + } + if (typeof options.timeout === 'number') { + options.acquireTimeoutMillis = options.timeout + } + let pool = GenericPoolAdapter[pools][name]; if (pool == null) { //create new pool with the name specified in options diff --git a/spec/GenericPoolAdapter.spec.js b/spec/GenericPoolAdapter.spec.js index 7d65beb..bab71ff 100644 --- a/spec/GenericPoolAdapter.spec.js +++ b/spec/GenericPoolAdapter.spec.js @@ -46,12 +46,16 @@ describe('PoolAdapter', () => { it('should create instance', () => { const adapter = createInstance( { - "adapter": "test" + "adapter": "test", + "size": 20 }); adapter.hasConfiguration(() => { return configuration; }); expect(adapter).toBeTruthy(); + const pool = GenericPoolAdapter.pool('test'); + expect(pool).toBeTruthy(); + expect(pool.max).toBe(20); }); it('should open and close', async () => {