1.0.8 • Published 5 years ago
leandb v1.0.8
Lean indexedDB library
Want to use indexedDB in browser but the API seems too hard to manage ?
LeanDB will help you here, it provides easy to use API, small JavaScript footprint and is fully dependency free.
Add database to your project
npm install leandb --save
or in modern browsers
import Database from "https://unpkg.com/leandb@latest/build/leandb.esm.js"
Initialize
Store properties
++
: Auto incrementation&
: Must be unique value
const stores = {
friends: "id++,name&,age",
notebooks: "id,name,content"
}
const db = new Database("test")
db.init(1, stores)
Add data
db.friends.add({ "name": "Steve", age: 5, id: 1 })
db.friends.add({ "name": "Roger", age: 2, id: 2 })
Update data with new value where query matches
db.friends.update({name:"Steve"}).value({age:7}).then(result => {
console.log(result)
})
Delete data where query matches
db.friends.delete({name: "Roger"})
Find data where query matches
db.friends.search({name:"Roger", age:5}).then(result => {
console.log(result)
})
const data = await db.friends.find({name:"Steve"})
console.log(data)
Query data
Add query to library requirements
import Database, { query } from "https://unpkg.com/leandb@latest/build/leandb.esm.js"
const params = query`age > ${3}`
db.friends.search(params).then(result => {
console.log("Age bigger than", result)
})