Node.js Driver for SequoiaDB
$ npm install sequoiadb --save
Create a client to sequoiadb server:
var Client = require('sequoiadb').Client;
var client = new Client(11810, "ip", {
user: "",
pass: ""
});
Disconnect with sequoiadb server:
client.disconnect([callback]);
Wait for client ready:
client.ready(function () {
// TODO
});
All operation must be after db ready.
Create a user:
client.createUser('user', 'pass', function (err) {
// TODO
});
Remove a user:
client.removeUser('user', 'pass', function (err) {
// TODO
});
Create CollectionSpace in sequoiadb:
client.createCollectionSpace("space_name", function (err, space) {
// TODO
});
Get CollectionSpace in sequoiadb by name:
client.getCollectionSpace("space_name", function (err, space) {
// TODO
});
Check given space name whether exist:
client.isCollectionSpaceExist("space_name", function (err, exist) {
// TODO
});
Drop CollectionSpace:
client.dropCollectionSpace("space_name", function (err) {
// TODO
});
Get all CollectionSpaces:
client.getCollectionSpaces(function (err, cursor) {
// TODO
});
Get current item:
cursor.current(function (err, item) {
// TODO
});
Get next item:
cursor.next(function (err, item) {
// TODO
});
Close cursor:
cursor.close(function (err) {
// TODO
});
Create a Collection in CollectionSpace:
space.createCollection('collection_name', function (err, collection) {
// TODO
});
Get a Collection from CollectionSpace by given name:
space.getCollection('collection_name', function (err, collection) {
// TODO
});
Check a Collection whether exist:
space.isCollectionExist('collection_name', function (err, exist) {
// TODO
});
Drop a Collection from a CollectionSpace:
space.dropCollection('collection_name', function (err) {
// TODO
});
Insert a document into Collection:
collection.insert({"name":"sequoiadb"}, function (err) {
// TODO
});
Upsert a document into Collection:
collection.upsert({name: "sequoiadb"}, {'$set': {age: 26}}, {}, function (err) {
// TODO
});
Bulk insert documents into Collection:
var insertors = [
{name: "hi"},
{name: "jack"}
];
collection.bulkInsert(insertors, 0, function (err) {
// TODO
});
Query all document of Collection:
collection.query(function (err, cursor) {
// TODO
});
Delete document:
collection.delete({name: "sequoiadb"}, 0, function (err) {
// TODO
});
Delete all documents:
collection.delete(function (err) {
// TODO
});
Aggregate:
var insertors = [
{$match:{status:"A"}},
{$group:{ _id: "$cust_id", total: {$sum: "$amount"}}}
];
collection.aggregate(insertors, function (err) {
// TODO
});
Create Index for collection:
var key = {
"Last Name": 1,
"First Name": 1
};
collection.createIndex("index_name", key, false, false, function (err) {
// TODO
});
Get index with given name:
collection.getIndex("index_name", function (err, cursor) {
// TODO
});
Get all indexes:
collection.getIndex(function (err, cursor) {
// TODO
});
Or:
collection.getIndexes(function (err, cursor) {
// TODO
});
Drop index:
collection.dropIndex('index_name', function (err) {
// TODO
});
Get Lobs:
collection.getLobs(function (err, cursor) {
// TODO
});
Create Lob:
var lob = collection.createLob(function (err) {
// TODO
});
Open Lob:
var lob = collection.openLob(oid, function (err) {
// TODO
});
Write data into lob:
lob.write(buff, function (err) {
// TODO
});
Read data from lob:
lob.read(16, function (err, buff) {
// TODO
});
Seek the position:
var Lob = require('sequoiadb').Lob;
lob.seek(pos, Lob.SDB_LOB_SEEK_SET); // 0 + pos
lob.seek(pos, Lob.SDB_LOB_SEEK_CUR); // current + pos
lob.seek(pos, Lob.SDB_LOB_SEEK_END); // total - pos
Close lob:
lob.close(function (err) {
// TODO
});