cctools
Functions
nvpair_database.h File Reference

An nvpair database maintains a list of name-value pair objects (see nvpair.h), each identified by a unique integer key. More...

#include "nvpair.h"
#include "int_sizes.h"

Go to the source code of this file.

Functions

struct nvpair_database * nvpair_database_open (const char *filename)
 Open or create a new database at the given filename.
void nvpair_database_close (struct nvpair_database *db)
 Close an open database.
int nvpair_database_insert (struct nvpair_database *db, UINT64_T *key, struct nvpair *nv)
 Insert a new object into the database.
struct nvpair * nvpair_database_remove (struct nvpair_database *db, UINT64_T key)
 Remove an object from the database.
struct nvpair * nvpair_database_lookup (struct nvpair_database *db, UINT64_T key)
 Look up an object in the database.
int nvpair_database_update_string (struct nvpair_database *db, UINT64_T key, const char *name, const char *value)
 Update a string property of one object in the database.
int nvpair_database_update_integer (struct nvpair_database *db, UINT64_T key, const char *name, INT64_T value)
 Update an integer property of one object in the database.
const char * nvpair_database_lookup_string (struct nvpair_database *db, UINT64_T key, const char *name)
 Look up a string property of one object in the database.
INT64_T nvpair_database_lookup_integer (struct nvpair_database *db, UINT64_T key, const char *name)
 Look up an integer property of one object in the database.
void nvpair_database_firstkey (struct nvpair_database *db)
 Begin iterating over the database.
int nvpair_database_nextkey (struct nvpair_database *db, UINT64_T *key, struct nvpair **nv)
 Continue iterating over the database.

Detailed Description

An nvpair database maintains a list of name-value pair objects (see nvpair.h), each identified by a unique integer key.

The database is stored in a single file and uses logging to implement atomic transactions and crash recovery. This module is appropriate to use in situations where a relational database is not appropriate because the data is small and schema-free. In the even of a write error, the current process will be aborted, but the database will remain in a consistent state.


Function Documentation

struct nvpair_database* nvpair_database_open ( const char *  filename) [read]

Open or create a new database at the given filename.

Parameters:
filenameThe name of the file to use.
Returns:
A pointer to an open database on success, null on failure.
void nvpair_database_close ( struct nvpair_database *  db)

Close an open database.

Parameters:
dbAn open database pointer.
int nvpair_database_insert ( struct nvpair_database *  db,
UINT64_T *  key,
struct nvpair *  nv 
)

Insert a new object into the database.

Parameters:
dbAn open database pointer.
keyA pointer to the key of the newly inserted object.
nvA pointer to the object to be inserted.
struct nvpair* nvpair_database_remove ( struct nvpair_database *  db,
UINT64_T  key 
) [read]

Remove an object from the database.

Parameters:
dbAn open database pointer.
keyThe unique key of the object.
Returns:
The object corresponding to the key, or null if none exists.
struct nvpair* nvpair_database_lookup ( struct nvpair_database *  db,
UINT64_T  key 
) [read]

Look up an object in the database.

Parameters:
dbAn open database pointer.
keyThe unique key of the object.
Returns:
The object corresponding to the key, or null if none exists.
int nvpair_database_update_string ( struct nvpair_database *  db,
UINT64_T  key,
const char *  name,
const char *  value 
)

Update a string property of one object in the database.

Parameters:
dbAn open database pointer.
keyThe key of the object to update.
nameThe name of the property to update.
valueThe value of the property to update.
Returns:
True if the object exists and the update was carried out, false otherwise.
int nvpair_database_update_integer ( struct nvpair_database *  db,
UINT64_T  key,
const char *  name,
INT64_T  value 
)

Update an integer property of one object in the database.

Parameters:
dbAn open database pointer.
keyThe key of the object to update.
nameThe name of the property to update.
valueThe value of the property to update.
Returns:
True if the object exists and the update was carried out, false otherwise.
const char* nvpair_database_lookup_string ( struct nvpair_database *  db,
UINT64_T  key,
const char *  name 
)

Look up a string property of one object in the database.

Parameters:
dbAn open database pointer.
keyThe key of the object to look up.
nameThe name of the property to look up.
Returns:
A pointer to the string value, if it exists, or zero otherwise.
INT64_T nvpair_database_lookup_integer ( struct nvpair_database *  db,
UINT64_T  key,
const char *  name 
)

Look up an integer property of one object in the database.

Parameters:
dbAn open database pointer.
keyThe key of the object to look up.
nameThe name of the property to look up.
Returns:
The value in integer form, or zero if not found.
void nvpair_database_firstkey ( struct nvpair_database *  db)

Begin iterating over the database.

Parameters:
dbAn open database pointer.
int nvpair_database_nextkey ( struct nvpair_database *  db,
UINT64_T *  key,
struct nvpair **  nv 
)

Continue iterating over the database.

Parameters:
dbAn open database pointer.
keyA pointer to the next key.
nvA pointer to the next object.
Returns:
True if an object and key were returned, false if the iteration is complete.