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.
Add aero-aerospike
to dependencies
in your package.json
:
"dependencies": {
"aero-aerospike": "*"
}
npm install
Add the database configuration to your config.json
:
"database": {
"namespace": "test"
}
You can also specify "host": "127.0.0.1:3000"
if needed.
Now you can subscribe to the event database ready
:
app.on('database ready', db => {
db.get('Users', 'test').then(console.log)
})
let aerospike = require('aero-aerospike')
let db = aerospike.client({
host: '127.0.0.1:3000',
namespace: 'Test'
})
db.connect()
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 official 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.
db.get('Users', 'key')
db.set('Users', 'key', {
name: 'Will Smith'
})
Does not delete existing properties if the record already exists. Only updates the name
property.
db.remove('Users', 'key')
db.forEach('Users', user => console.log(user.name))
db.filter('Users', user => user.isAdmin)
db.all('Users')
db.getMany('Users', ['key 1', 'key 2', 'key 3'])
db.ready.then(() => 'Connected to database!')
db.connect() === db.ready
db.connect().then(() => 'Connected to database!')