Permalink
Fetching contributors…
Cannot retrieve contributors at this time
140 lines (104 sloc) 4.46 KB

This document covers the 1.x version of the Aerospike Node.js client. For newer client versions, please refer to the API documentation available at http://www.aerospike.com/apidocs/nodejs/.


Data Model

Record

A record is how the data is represented and stored in the database. A record represented as an object. The keys of the object are the names of the fields (bins) of a record. The values for each field can either be Number, String, Array, Buffer or an Object itself. Aerospike supports integer, double, string, bytes, array and map datatypes. All the decimal values with valid fractions (123.45, 123.4) will be stored as double in aerospike. To store decimal values with 0 fraction as double, aerospike.Double().

Note: Array can contain an array or an object as a value in it. Similarly the object can contain an array or an object as a value in it. Essentially nesting of arrays in an object, and nesting of objects in an array is allowed.

Example of a record with 5 fields:

var record = {
  int_bin: 123,
  str_bin: 'xyz',
  buff_bin: new Buffer('hello world!'),
  arr_bin: [1, 2, 3],
  obj_bin: {num: 123, str: 'abc', buff: new Buffer([0xa, 0xb, 0xc])}
}

Unsupported Data Types

Aerospike does currently not support a boolean data type. To store boolean values in the database the application needs to convert them to a supported data type as the client does not do any automatica data type conversions. Attempting to store a boolean value in a record bin will lead to a parameter error being returned by the client.

Metadata

Some operations allow you to provide metadata with a record, including:

  • gen – (optional) The generation (version) of the record. Must be an Integer.
  • ttl – (optional) The time-to-live in seconds (expiration) of the record. Must be an Integer.

Example:

var metadata = {
  gen: 1,
  ttl: 6000
}

Key

A record is addressable via its key. A key is an object containing:

  • ns — The namespace of the key. Must be a String.
  • set – (optional) The set of the key. Must be a String.
  • key – (optional) The value of the key. May be either Integer, String or Buffer.
  • digest – (optional) The digest value of the current key. Must be a Buffer.

A key can be defined as an object or using aerospike.key(): For each operation, either a key value or a digest value must be present.

Example:

var key = {
  ns: 'test',
  set: 'demo',
  key: 123
}

Alternatively:

aerospike.key('test', 'demo', 123)

UDFArgs

Arguments to execute a UDF in the database.

  • module – The UDF module name to be invoked in the database.
  • funcname – The UDF function to be invoked in the database.
  • args - (optional) The arguments to be passed to the UDF function. Example:
var udfArgs = {
  module: udf_module,
  funcname: udf_funcname,
  args: [123, 'str']
}

Error

Error is an object which is populated with the status of client operations. The code attribute is set for all operations. On success, it will be AEROSPIKE_OK. On failure, the code will not be AEROSPIKE_OK and the other attributes will be populated.

Attributes:

  • code – Is a constant of type Status, it is the return status of any database operation.
  • file – The file in which the error occured.
  • func – The function in which the error occured.
  • line – The line number in which the error occured.