151
• Line 108: Not every engine provides implementations of all the
available API methods. In this example, we used the cmap engine,
which is unordered engine type. This is why cmap does not
support the get_above() function (and similarly: get_below(),
get_between(), count_above(), count_below(), count_between()).
Calling these functions will return status::NOT_SUPPORTED.
• Line 114: Finally, we are calling the close() method to close
database. Calling this function is optional because kv was
allocated on the stack and all necessary destructors will be called
automatically, just like for the other variables residing on stack.
Bringing Persistent Memory Closer to the Cloud
We will rewrite the phonebook example using the JavaScript language bindings. There
are several language bindings available for pmemkv – JavaScript, Java, Ruby, and Python.
However, not all provide the same API functionally equivalent to the native C and C++
counterparts. Listing 9-3 shows an implementation of the phonebook application
written using JavaScript language bindings API.
Listing 9-3. A simple phonebook example written using the JavaScript bindings
for pmemkv v0.8
1
const Database = require('./lib/all');
2
3
function assert(condition) {
4
if (!condition) throw new Error('Assert failed');
5
}
6
7
console.log('Create a key-value store using the "cmap" engine');
8
const db = new Database('cmap', '{"path":"/daxfs/
kvfile","size":1073741824, "force_create":1}');
9
10
console.log('Add 2 entries with name and phone number');
11
db.put('John', '123-456-789');
12
db.put('Kate', '987-654-321');
13
Chapter 9 pmemkv: a persistent in- memory key-value store
• Line 108: Not every engine provides implementations of all the
available API methods. In this example, we used the cmap engine,
which is unordered engine type. This is why cmap does not
support the get_above() function (and similarly: get_below(),
get_between(), count_above(), count_below(), count_between()).
Calling these functions will return status::NOT_SUPPORTED.
• Line 114: Finally, we are calling the close() method to close
database. Calling this function is optional because kv was
allocated on the stack and all necessary destructors will be called
automatically, just like for the other variables residing on stack.
Bringing Persistent Memory Closer to the Cloud
We will rewrite the phonebook example using the JavaScript language bindings. There
are several language bindings available for pmemkv – JavaScript, Java, Ruby, and Python.
However, not all provide the same API functionally equivalent to the native C and C++
counterparts. Listing 9-3 shows an implementation of the phonebook application
written using JavaScript language bindings API.
Listing 9-3. A simple phonebook example written using the JavaScript bindings
for pmemkv v0.8
1
const Database = require('./lib/all');
2
3
function assert(condition) {
4
if (!condition) throw new Error('Assert failed');
5
}
6
7
console.log('Create a key-value store using the "cmap" engine');
8
const db = new Database('cmap', '{"path":"/daxfs/
kvfile","size":1073741824, "force_create":1}');
9
10
console.log('Add 2 entries with name and phone number');
11
db.put('John', '123-456-789');
12
db.put('Kate', '987-654-321');
13
Chapter 9 pmemkv: a persistent in- memory key-value store
