Pyr8 User's Manual

« The Utils API | Control Groups API »

The Database API

Databases are an important part of most many applications and pyr8 offers a high-performance, reliable, transactional key/value store as part of its core APIs. Pyr8 uses a memory-mapped database called LightningDB, which offers b-tree indexing of arbitrary key/value data. The Pyr8 API wraps this low-level database as a JavaScript Map object that application developers can use to provide very fast local persistence for application data.

Databases are accessed by calling the openDatabase() method on Directory objects.

The Database Class

Databases in Pyr8 are used to store string-valued key/value pairs through a Map interface. The maps themselves are pyr8 capabilities, but the individual entries are simply strings or ArrayBuffers.


cap(): capability<utils>
Returns a C++-backed capability object for this database object.
clear(): void
Clears all values from the Database.
drop(): void
Drop the current Map completely.
delete(key: string):
Delete key and its value from the Database.
Returns a new Iterator object that contains the [key, value] pairs for each element in the Map object in key order.
Executes a provided function once per key/value pair in the Database in key order.
get(key: string): string
Returns a specified element from the Database or undefined if the key is not found.
has(key: string): bool
Returns true if the key is in the Database.
keys(): list<string>
Returns a list of keys in the database.
set(key: string, value: string):
Database Sets the specified key to the given value.
set(key: string, value: ArrayBuffer): Database
Sets the specified key to the given value.
values(): list<ArrayBuffer><>dt>
Returns a list of ArrayBuffers containing the values in the database.

The above interface is a simplified version of the low-level LMDB API, which is also available to programmers through the standard library.

« The Utils API | Control Groups API »