To get started with IsaDB2, first and foremost, you need to initialize (create an instance) to begin using it correctly.
The IsaDB2
library primarily uses asynchronous functions for its projects, always returning <Promises>
.
I will also use CommonJS
, but it's important to remember that IsaDB2
supports EcmaScript
.
const IsaDB2 = require('isadb2')
/*
In this example, I will use FUNCTIONS to initiate all the steps
*/
async function main() { //creating a function `main`
await IsaDB2.create() //creating the IsaDB2 instance
}
main() //executing the function
In IsaDB2, the main focus is on handling local databases. In this case, .set
and .get
are the main references.
const IsaDB2 = require('isadb2')
async function main() {
await IsaDB2.create()
await IsaDB2.set('foo', 'bar') //returns -> true
await IsaDB2.set('object', {name: 'Lucas', surname: 'Gomes'}) //returns -> true
//getting using method 1
console.log(await IsaDB2.get('foo')) //returns -> bar
//getting using method 2
IsaDB2.get('object').then(data => {
console.log(data) //returns -> {name: 'Lucas', surname: 'Gomes'}
})
}
main()
If you want to delete data from the database, the Delete
function can come to the rescue.
const IsaDB2 = require('isadb2')
async function main() {
await IsaDB2.create()
await IsaDB2.set('foo', 'bar')
await IsaDB2.set('object', {name: 'Lucas', surname: 'Gomes'})
console.log(await IsaDB2.get('foo'))
IsaDB2.get('object').then(data => {
console.log(data)
})
await IsaDB2.delete('foo') //returns -> true
console.log(await IsaDB2.get('foo')) //returns -> null
}
main()
IsaDB2 also works with notation within its strings to facilitate handling Objects within the database.
const IsaDB2 = require('isadb2')
async function main() {
await IsaDB2.create()
await IsaDB2.set('foo', 'bar')
await IsaDB2.set('object', {name: 'Lucas', surname: 'Gomes'})
console.log(await IsaDB2.get('foo'))
IsaDB2.get('object').then(data => {
console.log(data)
})
await IsaDB2.delete('foo')
console.log(await IsaDB2.get('foo'))
console.log(await IsaDB2.get('object.name')) //returns "Lucas"
}
main()