new SQLitePool(urlOrPath, optsopt, numReadersopt)
SQLite connection pool (1 writer + N readers)
Example
var { SQLitePool } = require("sigma/sqlite");
var pool = new SQLitePool("./pool.db", { readers: 2, wal: true });
pool.withWriter(db => db.run("INSERT INTO t(name) VALUES(?)", ["pool"]));
var rows = pool.withReader(db => db.all("SELECT * FROM t"));
print(JSON.stringify(rows));
pool.close();
Parameters:
| string | urlOrPath |
Database path or JDBC/URI |
|||||||||||
| Object | opts |
<optional> |
Properties
|
||||||||||
| number | numReaders |
<optional> |
(Deprecated) use opts.readers instead |
close() → {void}
Close all pooled connections.
Example
var pool = new SQLitePool("./pool.db", { readers: 1 });
// ... use pool ...
pool.close();
Returns:
| void |
| function | fn |
Function to execute with reader. |
||
| number | lockMs |
<optional> |
15000 | Lock wait timeout ms. |
Returns:
| * |
Function result. |
| function | fn |
Function to execute with writer. |
||
| number | lockMs |
<optional> |
30000 | Lock wait timeout ms. |
Throws:
| Error |
On writer lock timeout. |
| * |
Function result. |