ak-rest

minimalistic Akiban REST driver for node.js

Akiban REST Client for Node.js

A minimalistic Akiban client for node.js inspired by the nano driver for couchdb.

  1. install npm
  2. npm install ak-rest

To connect to Akiban:

var akiban = require('ak-rest')('http://localhost:8091/v1');

In node-rest-akiban the callback function receives always three arguments:

  • err - the error, if any
  • body - the http response body from Akiban, if no error.
  • header - the http response header from Akiban, if no error

A simple but complete example using callbacks is:

var akiban = require('ak-rest')('http://localhost:8091/v1');
 
// create a new model based on a JSON doc 
model_doc = { "name" : "padraig" }
akiban.model.create('padraig', model_doc, function(errheaderbody) {
  if (err) {
    console.log(err);
  } else {
    console.log(header);
    console.log(body);
  }
});

If you run this example(after starting Akiban) you will see:

{ 'content-type': 'application/json',
  'transfer-encoding': 'chunked',
  'status-code': 200,
  uri: 'http://localhost:8091/v1/model/parse/test.padraig?create=true' }
{ entities: 
   { padraig: 
      { entity: 'd6928c9b-168c-46df-ba3e-2a466acac221',
        attributes: [Object] } } }

Create a model called name from a JSON document and instantiate it.

json_doc = { "id": 657, "value": "this is some data" }
akiban.mode.create('t1', json_doc, function(errbody) {
  if (!err) {
    console.log(body);
  }
});

Create a new instance of the name entity from json_doc.

entity_json = { "id": 54, "value": "this is some data" }
akiban.entity.create('t1', entity_json, function(errbody) {
  if (!err) {
    console.log(body);
  }
});

Retrieve a single instance of the entity called name whose identifier is id.

akiban.entity.get('t1', 54, function(errbody) {
  if (!err) {
    console.log(body);
  }
});

Destroy a single instance of the entity called name whose identifier is id. Successful response has an empty body.

akiban.entity.destroy('t1', 54, function(errheaders) {
  if (!err) {
    console.log(headers);
  }
});

Replace the entire instance of the entity called name whose identifier is id.

akiban.entity.replace('t1', 54, function(errbody) {
  if (!err) {
    console.log(body);
  }
});

Execute a single SQL query.

akiban.sql.execute('select * from  t1', function(errbody) {
  if (!err) {
    console.log(body);
  }
});

Generate an execution plan for a single SQL query.

akiban.sql.explain('select * from  t1', function(errbody) {
  if (!err) {
    console.log(body);
  }
});

Execute multiple SQL statements within a single transaction. Individual statements can be free-form and must be separated by semicolons (;).

queries = 'select * from t1; select max(id) from t1;';
akiban.sql.multi(queries, function(errbody) {
  if (!err) {
    console.log(body);
  }
});

Perform a full text search on the specified index.

akiban.ft.search('t1', 'ft_idx', 'value:dream', function(errbody) {
  if (!err) {
    console.log(body);
  }
});

Rebuild the given index.

akiban.ft.rebuild('t1', 'ft_idx', function(errbody) {
  if (!err) {
    console.log(body);
  }
});