Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CONJS-41] cluster promise implementation - part 2
- implementation of PoolCluster.of - failover handling
- Loading branch information
Showing
6 changed files
with
629 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Similar to pool cluster with pre-set pattern and selector. | ||
* Additional method query | ||
* | ||
* @param poolCluster cluster | ||
* @param patternArg pre-set pattern | ||
* @param selectorArg pre-set selector | ||
* @constructor | ||
*/ | ||
function FilteredPoolCluster(poolCluster, patternArg, selectorArg) { | ||
const cluster = poolCluster; | ||
const pattern = patternArg; | ||
const selector = selectorArg; | ||
|
||
/** | ||
* Get a connection according to previously indicated pattern and selector. | ||
* | ||
* @return {Promise} | ||
*/ | ||
this.getConnection = () => { | ||
return cluster.getConnection(pattern, selector); | ||
}; | ||
|
||
/** | ||
* Execute a query on one connection from available pools matching pattern | ||
* in cluster. | ||
* | ||
* @param sql sql command | ||
* @param value parameter value of sql command (not mandatory) | ||
* @return {Promise} | ||
*/ | ||
this.query = function(sql, value) { | ||
return cluster | ||
.getConnection(pattern, selector) | ||
.then(conn => { | ||
return conn | ||
.query(sql, value) | ||
.then(res => { | ||
conn.end(); | ||
return res; | ||
}) | ||
.catch(err => { | ||
conn.end(); | ||
return err; | ||
}); | ||
}) | ||
.catch(err => { | ||
return err; | ||
}); | ||
}; | ||
} | ||
|
||
module.exports = FilteredPoolCluster; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.