Firebase charge me 27 usd after my database run out of free tier. Now I made alternative firebase.
waterDB is lowdb-realtime-wrapper using socket.io
Simple start waterDB
Server-side
git clone https://github.com/msp5382/waterDB.git
cd waterDB*
yarn dev
waterDB will start with port 5500, You can change in ./src/index.js file
Client-side
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io('http://localhost:5500/');
var path = "/" some path to listen
socket.emit('listen',{ // listen to change in path
path:path
})
socket.on(path,(d) => {
console.log(d) // do with change in path
})
</script>
'/' mean root, You can't push to this.
'foo.bar' is nasted json,
'foo.bar' = 'baz' is like this
{
"foo":{
"bar":"baz"
}
}
note: all route is POST method Content-Type:application/json
Set is for set a value in database
Assume we have blank database
{}
request body
{
"path":"foo.bar",
"content":"baz"
}
POST to /set/
database will like
{
"foo":{
"bar":"baz"
}
}
Push value to array.
Assume we have blank database
{}
request body
{
"path":"foo.bar",
"content":"baz"
}
POST to /push/ 2 times
database will like
{
"foo":{
"bar":["baz","baz"]
}
}
Increse or Decrese number in database
Assume we have blank database
{}
request body
{
"path":"foo",
"value": 1 //can be any int, to decrese just use negative number like -1
}
POST to /increse/
database will like
// if "foo" exist the value will add to "foo" value
{
"foo": 1
}
Read value once.
Assume we have database
{
"foo":{
"bar":"baz"
}
}
request body
{
"path":"foo"
}
POST to /read/
response be like
{ "bar":"baz" }
Find in list.
Assume we have database
{
"foo":{
"bar":[
{"id":1,"name":"somchai"},
{"id":2,"name":"sommai"},
{"id":3,"name":"somsan"}
]
}
}
request body
{
"path":"foo.bar",
"selector":{"id":2}
}
POST to /select/
response be like
{"id":2,"name":"sommai"}
Assume we have database
{
"foo":{
"bar":"baz"
}
}
request body
{
"path":"foo.bar",
"content":null
}
POST to /set/
database will like
{
"foo":{}
}
You can add "auth" key to request body and validate it in validate function in ./src/index.js
View raw database at ./src/database/db.json ;)
Accept all. Thanks.