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

asynqlite

v0.1.0

Published

Async / await wrapper for sqlite3

Downloads

24

Readme

asynqlite

Simple async/await wrapper for SQLite. Uses sqlite3 behind the scenes and greatly simplifies the the API.

Install

npm install asynqlite

Examples

SELECT some data:

const db = require('asynqlite');

(async () => {
    await db.open(':memory:');

    const res = await db.run('SELECT datetime() AS foo');
    console.log(res[0].foo);

    db.close();
})();

Use a prepared statement:

const db = require('asynqlite');

(async () => {
    db.open(':memory:');

    await db.run('CREATE TABLE foo (bar TEXT)');

    const stmt = await db.prepare('INSERT INTO foo VALUES (?)');
    for (let i = 0; i < 10; i++) {
        stmt.run('test ' + i);
    }
    await db.finalize(stmt);

    const res = await db.run('SELECT rowid AS id, bar FROM foo');
    console.log(res);

    await db.close();
})();

API

  • db.open(path, options)
    • path is a local path and filename for persistant storage, :memory: for a memory based non persistant database or undefined for a filesystem based non-persistant storage.
    • options are one or more pipe delineated db.OPEN_READONLY, db.OPEN_READWRITE, db.OPEN_CREATE, db.OPEN_FULLMUTEX, db.OPEN_URI, db.OPEN_SHAREDCACHE, db.OPEN_PRIVATECACHE. The default is OPEN_READWRITE | OPEN_CREATE | OPEN_FULLMUTEX.
  • db.run(sql (, [param, ...])) - returns an array of results (if any)
    • sql is the SQL statement in text to be executed.
    • Optional array of param values which will be substituted for ? in the SQL. Example: set bar equal to a where baz is b in the table foo
      await db.run('UPDATE foo SET bar = ? WHERE baz = ?', [ 'a', 'b' ]);
    • Returns an array of results. (if any) Example: SELECT all the rows from the table foo:
      const res = await db.run('SELECT * FROM foo');
      console.log(res);
  • db.prepare(sql) - returns a statement object
    • sql is the SQL statement in text to be executed. Parameter substitution (values of which are to be supplied later by using the returned statement object) are designated with ? in the SQL statement. Example: Prepare an INSERT statement and execute it with three different sets of values:
      const stmt = await db.prepare('INSERT INTO foo (a, b) VALUES (?, ?)');
      stmt.run('x', 1);
      stmt.run('y', 2);
      stmt.run('z', 3);
      await db.finalize(stmt);

      Note: You don't have to await each stmt.run() because the await finalize() effectivly does this.

  • db.close()
    • Closes the database handle. (happens automatically if you don't do it explicitly)

More Info

See the examples directory for more.

License

MIT