1.0.1 • Published 9 years ago

sequoiadb v1.0.1

Weekly downloads
6
License
Apache-2.0
Repository
github
Last release
9 years ago

Node Sequoiadb

Node.js Driver for SequoiaDB

Installation

$ npm install sequoiadb --save

API

Client

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.

User

Create a user:

client.createUser('user', 'pass', function (err) {
  // TODO
});

Remove a user:

client.removeUser('user', 'pass', function (err) {
  // TODO
});

CollectionSpace

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
});

Cursor

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
});

Collection

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
});

Document

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
});

Index

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
});

Lob

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
});

License

The Apache License 2.0

1.0.1

9 years ago

1.0.0

9 years ago

0.0.1

9 years ago