Akiban REST Client for Node.js
A minimalistic Akiban client for node.js inspired by the nano driver for couchdb.
Installation
- install npm
npm install ak-rest
Getting Started
To connect to Akiban:
var akiban = 'http://localhost:8091/v1';
In node-rest-akiban
the callback function receives always three arguments:
err
- the error, if anybody
- 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 = 'http://localhost:8091/v1';// create a new model based on a JSON docmodel_doc = "name" : "padraig"akibanmodel;
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] } } }
Model Functions
model.create(name, json_doc, [callback])
Create a model called name
from a JSON document and instantiate it.
json_doc = "id": 657 "value": "this is some data"akibanmode;
Entity Functions
entity.create(name, json_doc, [callback])
Create a new instance of the name
entity from json_doc
.
entity_json = "id": 54 "value": "this is some data"akibanentity;
entity.get(name, id, [callback])
Retrieve a single instance of the entity called name
whose identifier
is id
.
akibanentity;
entity.destroy(name, id, [callback])
Destroy a single instance of the entity called name
whose identifier
is id
. Successful response has an empty body.
akibanentity;
entity.replace(name, id, [callback])
Replace the entire instance of the entity called name
whose identifier
is id
.
akibanentity;
SQL Functions
sql.execute(query, [callback])
Execute a single SQL query.
akibansql;
sql.explain(query, [callback])
Generate an execution plan for a single SQL query.
akibansql;
sql.multi(queries, [callback])
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;';akibansql;
Full Text Functions
ft.search(entity_name, index_name, query, [callback])
Perform a full text search on the specified index.
akibanft;
ft.rebuild(entity_name, index_name, [callback])
Rebuild the given index.
akibanft;