A simple local database using the Node.js file system module.
const Sydb = require('sydb')
const db = new Sydb(options)
Parameter | Type | Optional | Default | Descrirption |
---|---|---|---|---|
options.path | string |
false |
./sydb.json |
Database File Path |
options.split | string |
true |
/ |
Separator for dividing to reference properties |
options.autoSave | boolean |
true |
false |
Automatically save when you hear a change |
options.spaceJson | number |
true |
4 |
Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. |
Json File
{
"users": {
"002": {
"name": "Pinho",
"username": "jvopinho",
"skills": [
"JavaScript",
"TypeScript",
"NodeJS",
"ReactJS",
"NextJS"
]
}
}
}
const Sydb = require('sydb')
const db = Sydb(__dirname + '/sydb.json')
db.ref('reference')
// Example
db.ref('users/001')
The val method returns the value of the path determined by the reference
db.ref(reference).val()
db.ref('users/002').val() // -> { name: 'Pinho', username: 'jvopinho', skills: [...] }
The val method returns the value of the path determined by the reference in map form
db.ref('users/').val({ type: 'map' }) // -> Map(1) { '002': [Object] }
The set method changes the value of the path determined by the reference.
db.ref(reference).set(value)
db.ref('users/002').set({
name: 'John Pinho',
}) // -> { users: { '002': { name: 'John Pinho' } } }
The update method changes the desired values of a path determined by the reference.
Note: value must be an object.
db.ref(reference).update(value)
db.ref('users/002').update({
username: 'JPinho'
}) // -> { users: { '002': { name: 'Pinho', username: 'JPinho', skills: [...] } } }
The delete method deletes the desired values from a path determined by the reference.
db.ref('reference').delete()
db.ref('users/002').delete() // -> { users: {} }