kiran-db
v1.3.1
Published
This is how javascript managa json data as the database
Downloads
14
Maintainers
Readme
KIRAN-DB
It's implements how no-sql database works
install
npm i kiran-db
File: dbs/User.js
const DB = require('kiran-db')
class User extends DB {
constructor (name) {
super(name)
}
}
module.exports = new User('users')
// Do the same thing to File: dbs/Post.js
File: index.js
const User = require('./dbs/User')
const Post = require('./dbs/Post')
WHERE
We can use where() to specified data to be selected
Model.where(data => data.id == 1).read()
CREATE
We don't need to defined the id of each data. it will created automatically when db.create() runs
const singleuser = { username: 'kiran' }
const multipleposts = [
{ ownerid: 1, title: 'Lorem ipsum' },
{ ownerid: 1, title: 'Dolor sit amet' },
{ ownerid: 2, title: 'Consectetur adipiscing' },
]
const usercreated = User.create(singleuser)
const multipleposts = Post.create(multipleposts)
console.log({usercreated, multipleposts})
READ
const users = User.read()
console.log({users})
UPDATE
const newpostdata = {
ownerid: 1,
}
const updated = Post.where(post => post.id == 3).update(newpostdata)
console.log({updated})
DELETE
const deleted = Post.where(post => post.id == 3).delete()
console.log({deleted})
JOIN
const userposts = User.where(user => user.id = 1).join('posts', 'ownerid')
console.log({userposts})