npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

better-sqlite-pool

v0.3.2

Published

A connection pool for better-sqlite3.

Downloads

1,582

Readme

Better-SQLite-Pool

A connection pool for the module better-sqlite3.

Using this module to open pools and acquire connections, and release the connection once it has done its work.

NOTE: Since v0.3.1, this package no longer includes better-sqlite3 by default, you have to install it explicitly.

Install

npm i better-sqlite3 better-sqlite-pool

Example

const { Pool } = require("better-sqlite-pool");

// Create a new pool:
var pool = new Pool("./example.db");

// use Promise:
pool.acquire().then(db => {
    var res = db.prepare("select * from users where id = 1").get();
    console.log(res);
    db.release();
});

// use async/await:
(async function() {
    var db = await pool.acquire();
    var res = db.prepare("select * from users where id = 2").get();
    console.log(res);
    db.release();
})();


setImmediate(() => {
    console.log(pool);
});

API

new Pool(path: string, options:? object|boolean|number)

Creates a new pool to store database connections.

  • path A SQLite database file path, can be set to :memory to open a memory based database.
  • [options] May contain any of these:
    • readonly Default is false.
    • memory Default is false.
    • fileMustExist Default is false.
    • max Max connections in the pool, default is 5.
    • timeout The number of milliseconds to wait when executing queries on a locked database, before throwing a SQLITE_BUSY error. Also, this option is used to determine how long it'd be waited before throwing timeout error when acquiring the connection. (default: 5000).
    • verbose A function that gets called with every SQL string executed by the database connection (default: null).
    If this argument is set to a boolean, it's equivalent to readonly, if set to a number, it's equivalent to max.

pool.acquire(): Promise<BetterSqlite3.Database>

Acquires a connection from the pool.

pool.close()

Closes all connections in the pool.

Potential Issues

node-gyp error

If you have any problem of downloading and installing this module, it's most likely that you're running an old version Node.js which doesn't include prebuilt better-sqlite3 binary files, and don't have a node-gyp installed, which is used to compile better-sqlite3. so please install node-gyp first if this situation occurs to you.

VCBulid.exe error

Another problem you may face is your computer throwing an error that tells you the VCBulid.exe file is missing. This is probably you don't have a Visual Studio installed, install one with VC++ support, that will fix the problem.

statement may fall through errors

These error may happen when compiling better-sqlite3 (version under v7.0) with GCC 7+, which is issued in Many "statement may fall through" while installing #3 and Ignore compilation warnings from SQLite3 itself #239, you can still run the driver though, if it's not so much important, just leave the error alone.