# asynqlite

> Async / await wrapper for sqlite3

Latest version **0.1.0** (published 2023-03-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install asynqlite
pnpm add asynqlite
yarn add asynqlite
bun add asynqlite
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2023-03-21 |
| First published | 2023-03-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Anders Brownworth |
| Maintainers | anders94 |
| Keywords | sqlite, sqlite3, async |

## Links

- npm: https://www.npmjs.com/package/asynqlite
- Repository: https://github.com/anders94/asynqlite
- Homepage: https://github.com/anders94/asynqlite#readme
- Issues: https://github.com/anders94/asynqlite/issues
- npm.io page: https://npm.io/package/asynqlite

## Dependencies (1)

- [sqlite3](https://npm.io/package/sqlite3.md) ^5.1.6

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2023-03-21
- 0.0.1 — 2023-03-21

## README

# asynqlite

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

## Install

```bash
npm install asynqlite
```

## Examples
`SELECT` some data:

```js
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:

```js
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`
    ```js
    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`:
    ```js
    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:
    ```js
    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](examples/) directory for more.

## License

MIT

---
_Source: https://npm.io/package/asynqlite · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
