DEV Community

Cover image for Full-blown Database Management Software written completely in Javascirpt ✨
Keerthi Vasan
Keerthi Vasan

Posted on

Full-blown Database Management Software written completely in Javascirpt ✨

This is not just a fancy client, it's a complete DBMS which is completely written in NodeJS with type declarations and documentation to ease developer's introduction to the amazing world of SavanahDB

It is a NoSQL meaning you can store data flexibly in the JSON format but it can also be used to establish deep relations between tables, have groups in the filter, join data from different tables!

Let's create a Social Network with this Database :

First, let's start a server to receive and process requests via various clients

import { Server } from 'savanahdb' 

let server = new Server({
  path: '/var/db/', 
  masterKey: 'ksKkharaudjwnwbduxnsn5yahahhwwsmma' // 64-bit key to encrypt important configurations
}) 
Enter fullscreen mode Exit fullscreen mode

And that's it! Run it with pm2
You have your own server running now!

We connect to it using a client :

import { Client } from 'savanahdb';

let client = new Client({
   user : "randomusr",
   pass : "fdASDFajd9awjef98awjefioawjeasdf"
})

let db = client.db('network')
let users = db.table('users')
let posts = db.table('posts')  
Enter fullscreen mode Exit fullscreen mode

First, you store the User Document when they sign up:

users.insert({
    name : 'John Adam',
    city : 'New York',
    tier : 'Silver',
    prem : true,
    id : 'usrOw9a0eif0923aewf'
})
Enter fullscreen mode Exit fullscreen mode

Next you store two Posts they posted with reference to their id essentially establishing a relationship between the tables:

posts.insert({
    usr : 'usrOw9a0eif0923aewf',
    content : 'I love this network.'
})
// A Few Moments Later..
posts.insert({
    usr : 'usrOw9a0eif0923aewf',
    content : "Nvm, I don't know anymore"
})
Enter fullscreen mode Exit fullscreen mode

Now when someone visits the Orginal User's Profile to list the posts they have posted, you create a search like this :

let usr = await users.search('id == "usrOw9a0eif0923aewf"', {
    join : {
      posts : 'that.usr == this.id' 
    }
}
Enter fullscreen mode Exit fullscreen mode

In this case the usr Document will be :

[{
   name : 'John Adam',
    city : 'New York',
    tier : 'Silver',
    prem : true,
    id : 'usrOw9a0eif0923aewf',
    posts : [{
    usr : 'usrOw9a0eif0923aewf',
    content : 'I love this network.'
  },{
    usr : 'usrOw9a0eif0923aewf',
    content : "Nvm, I don't know anymore"
  }]
}] 
Enter fullscreen mode Exit fullscreen mode

Extremely capable Software do check it out!!

It is available to check out for free here : https://www.npmjs.com/package/savanahdb

If you are interested in the development or would like to receive updates for the package, you can join the official Discord Server here : https://www.discord.com/invite/GBmMQd2xtB

Top comments (9)

Collapse
 
hanna profile image
Hanna Rose

Are there any benchmarks?

Collapse
 
nectres profile image
Keerthi Vasan

I will be updating the README of the npm package with benchmarks quite soon.

Collapse
 
nectres profile image
Keerthi Vasan

I have already benchmarked it against Mongodb what else should I add to the comparison?

Collapse
 
hanna profile image
Hanna Rose

Postgres or mariadb perhaps

Collapse
 
harshvats2000 profile image
HARSH VATS

Your npm link is broken!

Collapse
 
nectres profile image
Keerthi Vasan

Sorry! Fixed now. Thanks for pointing out

Collapse
 
crimsonmed profile image
Médéric Burlet

The syntax reminds me of prisma.
Keep up the good work!

Collapse
 
fullrx profile image
Dmitry Maltsev • Edited

What about BigData support?

Collapse
 
nectres profile image
Keerthi Vasan • Edited

Yes. With sharding and the concept of connecting multiple servers as a hive it should be able to process terabytes of data, be highly available and fast

I am working on a gitbook documentation to explain advanced concepts like sharding, hive, scaling and security with SavanahDB whenever it's ready it will linked in the readme. Future versions will be able to scale diagonally ( horizontally and vertically) on demand