ak-rest
v0.0.1
Published
minimalistic Akiban REST driver for node.js
Downloads
3
Readme
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 = require('ak-rest')('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 = 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(err, header, body) {
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] } } }
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" }
akiban.mode.create('t1', json_doc, function(err, body) {
if (!err) {
console.log(body);
}
});
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" }
akiban.entity.create('t1', entity_json, function(err, body) {
if (!err) {
console.log(body);
}
});
entity.get(name, id, [callback])
Retrieve a single instance of the entity called name
whose identifier
is id
.
akiban.entity.get('t1', 54, function(err, body) {
if (!err) {
console.log(body);
}
});
entity.destroy(name, id, [callback])
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(err, headers) {
if (!err) {
console.log(headers);
}
});
entity.replace(name, id, [callback])
Replace the entire instance of the entity called name
whose identifier
is id
.
akiban.entity.replace('t1', 54, function(err, body) {
if (!err) {
console.log(body);
}
});
SQL Functions
sql.execute(query, [callback])
Execute a single SQL query.
akiban.sql.execute('select * from t1', function(err, body) {
if (!err) {
console.log(body);
}
});
sql.explain(query, [callback])
Generate an execution plan for a single SQL query.
akiban.sql.explain('select * from t1', function(err, body) {
if (!err) {
console.log(body);
}
});
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;';
akiban.sql.multi(queries, function(err, body) {
if (!err) {
console.log(body);
}
});
Full Text Functions
ft.search(entity_name, index_name, query, [callback])
Perform a full text search on the specified index.
akiban.ft.search('t1', 'ft_idx', 'value:dream', function(err, body) {
if (!err) {
console.log(body);
}
});
ft.rebuild(entity_name, index_name, [callback])
Rebuild the given index.
akiban.ft.rebuild('t1', 'ft_idx', function(err, body) {
if (!err) {
console.log(body);
}
});