tacodb
reusable leveldb server
Synopsis
tacodb wraps leveldbs in a server such that it would be possible to create a hosted service with it, that can be connected to via http and WebSockets.
You database is configured by writing a .js file, which is then bundled (a la browserify) and sent to the tacodb server via http.
Getting Started
start by installing tacodb
npm install -g tacodb
Then, create an customization file
//db.js//creat a static http style interface to leveldb.var static =module {db}
start the server locally.
tacodb local dbjs --port 8080
echo hello | curl -sSNT -X PUT http://localhost:8080/greetingcurl http://localhost:8080/greeting
connecting to tacodb/level via http
Create a database customization file... This will expose an http interface, that can store files inside leveldb.
simple http access
//examples/http/index.jsvar static =module {db}
>tacodb local static.js --name static
listening on 8000
This starts a tacodb server running around your db.js
file.
#http PUT hi = HELLOecho 'HELLO!' | curl -sSNT . localhost:8000/hi#http GET hicurl localhost:8000/hiHELLO!
Add real time logging
level-static
extend the simple http example,
so that we can track changes as they occur.
changes http with changes feed.
//examples/changes/index.jsvar static =var through =var route =var live =var stack =module {//level-static creates a http handling middleware around leveldb.db}
start the server...
tacodb local ./index.js --name changes
Then, connect and stream changes like this:
curl localhost:8000/_changes
Then in another terminal:
echo 'Hi!' | curl -sSNT . localhost:8000/hiecho 'whats up?' | curl -sSNT . localhost:8000/wazzupecho 'Good Bye!' | curl -sSNT . localhost:8000/bye
connect to tacodb/level over websockets
Create a streaming connection with websockets!
server with websockets & multilevel:
//examples/ws/server.jsvar multilevel =var fs =var indextryindex = fscatch errconsolethrow errmodule {dbdb}
brower/node client with websockets
//examples/ws/client.jsvar multilevel =var reconnect =//This client works from both the browser and in node!//WebSockets everywhere!//use `npm run build` to generate the index.html file.var node = processtitle != 'browser'var log = node ? consolelog :{var data = slicevar pre = documentpreinnerText = datadocumentbody}//^ on the browser, this assumes you are on the same host as window.location...
this client can be used from both the browser and node.js!
running the server & client
start the server
tacodb local server.js --name ws
connect from node:
node client.js
or from the browser
License
MIT