sqlite3-promisify
Version:
Promisify all node-sqlite3 functions
85 lines (58 loc) • 2.26 kB
Markdown
[](https://api.travis-ci.com/arshadkazmi42/sqlite3-promisify)
Promisifying node-sqlite3 functions
```
npm i sqlite3-promisify
```
```javascript
const SQLiteCrud = require('sqlite3-promisify');
const DB_PATH = __dirname + '/sqlite3.db';
const DB_NAME = 'sqlite3_test';
(async () => {
const Db = new SQLiteCrud(DB_PATH);
const rows = await Db.all(`SELECT * FROM ${DB_NAME};`);
console.log(rows);
////////// OUTPUT ////////////
// [
// { id: 1, name: 'Arshad', email: 'arshadkazmi42@gmail.com' },
// { id: 2, name: 'Sqlite3', email: 'sqlite3@db.com' }
// ]
const row = await Db.get(`SELECT * FROM ${DB_NAME} WHERE id = ?;`, [1]);
console.log(row);
////////// OUTPUT ////////////
// { id: 1, name: 'Arshad', email: 'arshadkazmi42@gmail.com' }
})();
```
-
Takes SQLite `DB path` as input and returns sqlite3 object.
- **Params**
- path (string) - Database absolute path
-
Serialize consecutive db calls.
-
Executes select queries and returns only first result row.
- **Params**
- query (string) - SQL query
- values (array) - Values for the query
-
Executes any query and returns all the result rows
- **Params**
- query (string) - SQL query
- values (array) - Values for the query
-
Executes query which does not returns any results
- **Params**
- query (string) - SQL query
- values (array) - Values for the query
-
Closes the db connection
Interested in contributing to this project?
You can log any issues or suggestion related to this library [here](https://github.com/arshadkazmi42/sqlite3-promisify/issues/new)
Read our contributing [guide](CONTRIBUTING.md) on getting started with contributing to the codebase
Thank you to all the contributors who have helped us in making this project better :raised_hands:
<a href="https://github.com/arshadkazmi42"><img src="https://github.com/arshadkazmi42.png" width="30" /></a>