1.0.1 • Published 8 years ago
aero-aerospike v1.0.1
aero-aerospike
This client can be used as a standalone package (without using Aero). It is a lightweight wrapper built on top of the official node.js client. All API calls return bluebird promises.
Installation
Add aero-aerospike
to dependencies
in your package.json
:
"dependencies": {
"aero-aerospike": "*"
}
npm install
Usage with Aero
Add the database configuration to your config.json
:
"database": {
"host": "127.0.0.1:3000",
"namespace": "test"
}
Now you can subscribe to the event database ready
:
app.on('database ready', db => {
db.get('Users', 'test').then(console.log)
})
API
Creating a client
let aerospike = require('aero-aerospike')
let db = aerospike.client({
host: '127.0.0.1:3000',
namespace: 'Test'
})
db.connect()
aerospike.client
let db = aerospike.client({
host: '127.0.0.1:3000',
namespace: 'Test'
})
The configuration parameters are directly handed over to the Aerospike.client
constructor of the officia aerospike node library. Therefore you can also specify hosts
, log
, policies
and so on. host
is a shortcut notation added by this library. namespace
specifies the namespace you want to operate on.
get
db.get('Users', 'key')
set
db.set('Users', 'key', {
name: 'Will Smith'
})
Does not delete existing properties if the record already exists. Only updates the name
property.
remove
db.remove('Users', 'key')
forEach
db.forEach('Users', user => console.log(user.name))
filter
db.filter('Users', user => user.isAdmin)
getMany
db.getMany('Users', ['key 1', 'key 2', 'key 3'])
ready
db.ready.then(() => 'Connected to database!')
connect
db.connect() === db.ready
db.connect().then(() => 'Connected to database!')