node-beryl, a Node.js driver for BerylDB.
If you want to learn more about BerylDB and how to install it, feel free to check our
documentation at docs.beryl.dev.
Follow us on Twitter.
QuickStart
The quick start guide will show you how to set up a simple application using BerylDB's Node.js driver.
It scope is only how to set up the driver and perform the simple operations. For more advanced coverage, we encourage reading our tutorial.
Installation
The recommended way to get started using the Node.js 4.x driver is by using the npm (Node Package Manager) to install node-beryl in your project.
First, you need to create your own project:
$ mkdir new-project
$ npm init
After you've created your own project, you can either download this driver or use npm:
$ npm i beryldb
Connecting to BerylDB
Let's create a new connection.js file that we will be using to show basic operations. First, we need to add code to conenct to the remote server:
var Connection = require("./lib/server").Server;
var assert = require("assert");
var Link = new Connection({
host : "127.0.0.1",
port : 6378,
login : "root",
password: "default"
}).connect({
connected : function()
{
console.log("Connected to BerylDB server.");
},
disconnected : function()
{
console.error("Disconnected from BerylDB.");
},
timeout : function()
{
console.error("Connection link has timed out.");
},
retrying : function()
{
console.error("Trying to reconnect to BerylDB server.");
},
error : function(error)
{
console.error("Unable to connect to server:", error);
}
});
If you are familiar with BerylDB, you will soon learn that most functions from this driver have the same name as its underlying function.
Check BerylDB's full list of commands
Querying
Let's look at an example exercising all the different available operations
We define a key hello
with value world
Link.set("hello", "world").then(function(data)
{
console.log(data);
})
.catch(function(error)
{
console.log("error: " + error.code);
});
We set a map a
with value b
Link.hset("a", "b", "c").then(function(data)
{
console.log(data);
})
.catch(function(error)
{
console.log("error: " + error.code);
});
These two code will have the following output (assuming that neither 'hello' or 'a' are defined):
OK
Querying for lists
You can use forEach in order to iterate a result that contains more than one item:
Link.keys("*").then(function(data)
{
data.forEach(function(item)
{
console.log(item);
})
})
.catch(function(error)
{
console.log("error: " + error.message);
});
Contributing
We are always welcoming new members. If you wish to start contributing code to the Beryl project in any form, such as in the form of pull requests via Github, a code snippet, or a patch, you will need to agree to release your work under the terms of the BSD license.