Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fibjs/fib-pool
Generic resource pooling for fibjs
https://github.com/fibjs/fib-pool
database pool
Last synced: 2 months ago
JSON representation
Generic resource pooling for fibjs
- Host: GitHub
- URL: https://github.com/fibjs/fib-pool
- Owner: fibjs
- License: mit
- Created: 2017-01-23T07:46:39.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-06-10T14:01:34.000Z (over 4 years ago)
- Last Synced: 2024-10-07T23:36:08.164Z (4 months ago)
- Topics: database, pool
- Language: JavaScript
- Size: 46.9 KB
- Stars: 2
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
- Changelog: CHANGELOG.md
- License: License
Awesome Lists containing this project
- awesome - fib-pool - Generic resource pooling for fibjs. (Packages / Server App)
README
## Generic resource pooling for fibjs
[![NPM version](https://img.shields.io/npm/v/fib-pool.svg)](https://www.npmjs.org/package/fib-pool)
[![Build Status](https://travis-ci.org/fibjs/fib-pool.svg)](https://travis-ci.org/fibjs/fib-pool)
[![Build status](https://ci.appveyor.com/api/projects/status/p662f7ulpc4asu8s?svg=true)](https://ci.appveyor.com/project/richardo2016/fib-pool)## Install
```sh
npm install fib-pool [--save]
```## Test
```sh
npm run ci
```## Creating a pool
Simple example.
```js
var db = require("db");
var Pool = require("fib-pool");var p = Pool(() => {
return db.open("sqlite:test.db");
});
```Specify maxsize and timeout.
```js
var db = require("db");
var Pool = require("fib-pool");var p = Pool(() => {
return db.open("sqlite:test.db");
}, 10, 30 * 1000);
```Specify custom destroy function.
```js
var db = require("db");
var Pool = require("fib-pool");var p = Pool({
create: () => {
return db.open("sqlite:test.db");
},
destroy: (o) => {
o.close()
},
timeout: 30 * 1000,
retry: 3
});
```## Using the pool
```js
var db = require("db");
var Pool = require("fib-pool");var p = Pool({
create: () => {
return db.open("sqlite:test.db");
},
destroy: (o) => {
o.close()
},
timeout: 30 * 1000,
retry: 3
});var res = p((conn) => {
conn.execute("select * from test");
});```
## Using the pool with name
```js
var db = require("db");
var Pool = require("fib-pool");var p = Pool({
create: (name) => {
return db.open("sqlite:" + name + ".db");
},
destroy: (o) => {
o.close()
},
timeout: 30 * 1000
});var res = p("test", (conn) => {
conn.execute("select * from test");
});```
## Clear a pool
Simple example.
```js
var db = require("db");
var Pool = require("fib-pool");var p = Pool(() => {
return db.open("sqlite:test.db");
});p.clear();
```