jsdb-simple
v1.4.3
Published
Just a Simple DataBase
Downloads
2
Maintainers
Readme
jsdb-simple
Just a simple key-value database on better-sqlite3
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.set(id, value) ⇒ Database
Set record by given ID
Kind: instance method of Database
| Param | Type | Description | | --- | --- | --- | | id | String | Record ID | | value | Any | Value to set |
database.setMany(records) ⇒ Database
Set many records to the table
Kind: instance method of Database
| Param | Type | Description | | --- | --- | --- | | records | Array | Set of records |
database.get(id) ⇒ Any
Get record by ID
Kind: instance method of Database
| Param | Type | Description | | --- | --- | --- | | id | String | Records's ID |
database.getAll() ⇒ Object
Get all records
Kind: instance method of Database
database.find(query) ⇒ Object
Find record by ID using query
Kind: instance method of 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
| Param | Type | Description | | --- | --- | --- | | id | String | Record's ID |
database.delete(id) ⇒ Boolean
Delete record by ID
Kind: instance method of Database
| Param | Type | Description | | --- | --- | --- | | id | String | Record's ID |
database.deleteMany(records) ⇒ Database
Delete many records from the table
Kind: instance method of Database
| Param | Type | Description | | --- | --- | --- | | records | Array | Set of records |
database.deleteAll() ⇒ Database
Deletes every record in table
Kind: instance method of Database
database.unlink() ⇒ Boolean
Deletes table's file
Kind: instance method of Database