jsdb-simple
better-sqlite3
Just a simple key-value database on Example
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
- new Database(name, options)
-
.set(id, value) ⇒
Database
-
.setMany(records) ⇒
Database
-
.get(id) ⇒
Any
-
.getAll() ⇒
Object
-
.find(query) ⇒
Object
-
.has(id) ⇒
Boolean
-
.delete(id) ⇒
Boolean
-
.deleteMany(records) ⇒
Database
-
.deleteAll() ⇒
Database
-
.unlink() ⇒
Boolean
new Database(name, options)
Database class
Param | Type | Description |
---|---|---|
name | String |
Table's name |
options | Object |
Database init options |
Database
database.set(id, value) ⇒ Set record by given ID
Kind: instance method of Database
Param | Type | Description |
---|---|---|
id | String |
Record ID |
value | Any |
Value to set |
Database
database.setMany(records) ⇒ Set many records to the table
Kind: instance method of Database
Param | Type | Description |
---|---|---|
records | Array |
Set of records |
Any
database.get(id) ⇒ Get record by ID
Kind: instance method of Database
Param | Type | Description |
---|---|---|
id | String |
Records's ID |
Object
database.getAll() ⇒ Get all records
Kind: instance method of Database
Object
database.find(query) ⇒ Find record by ID using query
Kind: instance method of Database
Param | Type | Description |
---|---|---|
query | String |
Query that is used to find IDs |
Boolean
database.has(id) ⇒ Check if table has a record
Kind: instance method of Database
Param | Type | Description |
---|---|---|
id | String |
Record's ID |
Boolean
database.delete(id) ⇒ Delete record by ID
Kind: instance method of Database
Param | Type | Description |
---|---|---|
id | String |
Record's ID |
Database
database.deleteMany(records) ⇒ Delete many records from the table
Kind: instance method of Database
Param | Type | Description |
---|---|---|
records | Array |
Set of records |
Database
database.deleteAll() ⇒ Deletes every record in table
Kind: instance method of Database
Boolean
database.unlink() ⇒ Deletes table's file
Kind: instance method of Database