Module communautaire génial

Mise en commun générique des ressources pour fibjs

Statut de la construction

Installer

1
npm install fib-pool [--save]

Tester

1
npm run ci

Création d'un pool

Exemple simple.

1 2 3 4 5 6
var db = require("db"); var Pool = require("fib-pool"); var p = Pool(() => { return db.open("sqlite:test.db"); });

Spécifiez maxsize et timeout.

1 2 3 4 5 6
var db = require("db"); var Pool = require("fib-pool"); var p = Pool(() => { return db.open("sqlite:test.db"); }, 10, 30 * 1000);

Spécifiez la fonction de destruction personnalisée.

1 2 3 4 5 6 7 8 9 10 11 12 13
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 });

Utiliser la piscine

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
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"); });

Utilisation du pool avec le nom

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
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"); });

Vider une piscine

Exemple simple.

1 2 3 4 5 6 7 8
var db = require("db"); var Pool = require("fib-pool"); var p = Pool(() => { return db.open("sqlite:test.db"); }); p.clear();