Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arshadkazmi42/sqlite3-promisify
Promisifying sqlite3 functions
https://github.com/arshadkazmi42/sqlite3-promisify
db node npm promise sqlite sqlite3 sqlite3-promisify
Last synced: 3 months ago
JSON representation
Promisifying sqlite3 functions
- Host: GitHub
- URL: https://github.com/arshadkazmi42/sqlite3-promisify
- Owner: arshadkazmi42
- License: mit
- Created: 2019-07-28T18:09:20.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-07-08T07:58:43.000Z (over 2 years ago)
- Last Synced: 2024-10-07T06:41:53.513Z (4 months ago)
- Topics: db, node, npm, promise, sqlite, sqlite3, sqlite3-promisify
- Language: JavaScript
- Size: 146 KB
- Stars: 4
- Watchers: 2
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# sqlite3-promisify
[![Build Status](https://api.travis-ci.com/arshadkazmi42/sqlite3-promisify.svg?branch=master)](https://api.travis-ci.com/arshadkazmi42/sqlite3-promisify)
Promisifying node-sqlite3 functions
## Install
```
npm i sqlite3-promisify
```## Usage
```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: '[email protected]' },
// { id: 2, name: 'Sqlite3', email: '[email protected]' }
// ]const row = await Db.get(`SELECT * FROM ${DB_NAME} WHERE id = ?;`, [1]);
console.log(row);////////// OUTPUT ////////////
// { id: 1, name: 'Arshad', email: '[email protected]' }
})();
```## API
- #### `connect(path)`
Takes SQLite `DB path` as input and returns sqlite3 object.
- **Params**
- path (string) - Database absolute path- #### `serialize()`
Serialize consecutive db calls.- #### `get(query, values={Optional})`
Executes select queries and returns only first result row.
- **Params**
- query (string) - SQL query
- values (array) - Values for the query- #### `all(query, values={Optional})`
Executes any query and returns all the result rows
- **Params**
- query (string) - SQL query
- values (array) - Values for the query- #### `run(query, values={Optional})`
Executes query which does not returns any results
- **Params**
- query (string) - SQL query
- values (array) - Values for the query- #### `close()`
Closes the db connection## Contributing
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