Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jarvis394/jsdb-simple
Just a Simple DataBase
https://github.com/jarvis394/jsdb-simple
Last synced: about 14 hours ago
JSON representation
Just a Simple DataBase
- Host: GitHub
- URL: https://github.com/jarvis394/jsdb-simple
- Owner: jarvis394
- Created: 2019-07-18T19:09:00.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T04:46:59.000Z (almost 2 years ago)
- Last Synced: 2023-03-02T21:35:50.876Z (almost 2 years ago)
- Language: JavaScript
- Size: 1010 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# jsdb-simple
#### Just a simple key-value database on `better-sqlite3`
# Example
```js
const { Database } = require('jsdb-simple')
const db = new Database()/* Setting any data */
db.set('foo', 'bar')
db.set('user', {
name: 'John',
age: 21,
gender: 'male'
})/* Getting data from DB */
console.log(db.get('foo'))
// > baz (String)console.log(db.get('user').age)
// > 21 (Number)/* Deleting data */
db.delete('foo')
console.log(db.get('foo'))
// > null// Delete DB file, default is `data/main.sqlite`
db.unlink()
```# API
## Database
**Kind**: global class
- [Database](#Database)
- [new Database(name, options)](#new_Database_new)
- [.set(id, value)](#Database+set) ⇒ [Database
](#Database)
- [.setMany(records)](#Database+setMany) ⇒ [Database
](#Database)
- [.get(id)](#Database+get) ⇒Any
- [.getAll()](#Database+getAll) ⇒Object
- [.find(query)](#Database+find) ⇒Object
- [.has(id)](#Database+has) ⇒Boolean
- [.delete(id)](#Database+delete) ⇒Boolean
- [.deleteMany(records)](#Database+deleteMany) ⇒ [Database
](#Database)
- [.deleteAll()](#Database+deleteAll) ⇒ [Database
](#Database)
- [.unlink()](#Database+unlink) ⇒Boolean
### new Database(name, options)
Database class
| Param | Type | Description |
| ------- | ------------------- | --------------------- |
| name |String
| Table's name |
| options |Object
| Database init options |### database.set(id, value) ⇒ [
Database
](#Database)Set record by given ID
**Kind**: instance method of [
Database
](#Database)| Param | Type | Description |
| ----- | ------------------- | ------------ |
| id |String
| Record ID |
| value |Any
| Value to set |### database.setMany(records) ⇒ [
Database
](#Database)Set many records to the table
**Kind**: instance method of [
Database
](#Database)| Param | Type | Description |
| ------- | ------------------ | -------------- |
| records |Array
| Set of records |### database.get(id) ⇒
Any
Get record by ID
**Kind**: instance method of [
Database
](#Database)| Param | Type | Description |
| ----- | ------------------- | ------------ |
| id |String
| Records's ID |### database.getAll() ⇒
Object
Get all records
**Kind**: instance method of [
Database
](#Database)### database.find(query) ⇒
Object
Find record by ID using query
**Kind**: instance method of [
Database
](#Database)| Param | Type | Description |
| ----- | ------------------- | ------------------------------ |
| query |String
| Query that is used to find IDs |### database.has(id) ⇒
Boolean
Check if table has a record
**Kind**: instance method of [
Database
](#Database)| Param | Type | Description |
| ----- | ------------------- | ----------- |
| id |String
| Record's ID |### database.delete(id) ⇒
Boolean
Delete record by ID
**Kind**: instance method of [
Database
](#Database)| Param | Type | Description |
| ----- | ------------------- | ----------- |
| id |String
| Record's ID |### database.deleteMany(records) ⇒ [
Database
](#Database)Delete many records from the table
**Kind**: instance method of [
Database
](#Database)| Param | Type | Description |
| ------- | ------------------ | -------------- |
| records |Array
| Set of records |### database.deleteAll() ⇒ [
Database
](#Database)Deletes every record in table
**Kind**: instance method of [
Database
](#Database)### database.unlink() ⇒
Boolean
Deletes table's file
**Kind**: instance method of [
Database
](#Database)