Regroupement de ressources génériques pour fibjs
Installer
1npm install fib-pool [--save]
Test
1npm run ci
Création d'une piscine
Exemple simple.
1
2
3
4
5
6var db = require("db");
var Pool = require("fib-pool");
var p = Pool(() => {
return db.open("sqlite:test.db");
});
Spécifiez la taille maximale et le délai d'attente.
1
2
3
4
5
6var db = require("db");
var Pool = require("fib-pool");
var p = Pool(() => {
return db.open("sqlite:test.db");
}, 10, 30 * 1000);
Spécifiez une fonction de destruction personnalisée.
1
2
3
4
5
6
7
8
9
10
11
12
13var 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
});
Utiliser la piscine
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17var 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");
});
Utiliser la piscine avec le nom
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16var 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");
});
Vider une piscine
Exemple simple.
1
2
3
4
5
6
7
8var db = require("db");
var Pool = require("fib-pool");
var p = Pool(() => {
return db.open("sqlite:test.db");
});
p.clear();