BangDB - Embeddable Flavor

API - Bangdb Embedded

Here is the list of some of the most useful APIs, for the detail API list, please get it from Bangdb Resources

API Description

Exposed by: database type

Usage: to get an object of table type

Arguments: table name and open flag. Open flag are as follows;

  • OPENCREATE to open if existing or create if not
  • TRUNCOPEN truncate and then open afresh
  • JUSTOPEN open if existing else fail

Returns: reference to table type

Error: Null, sets the errno


Exposed by: database type

Usage: to close the database. Note that this is all what's needed to close a database, there is nothing else that user required to do. It closes all open connections as well no matter who opened them. It does various things behind the scene, from closing all open connections, closing table, flushing log, flushing data, shutting down workers, undoing any incomplete operation, storing various metadata, ensuring sanity, unmapping memories, collecting stats etc... Hence it's important to close the database using the API in order to ensure sanity of the db

Arguments:dbclose optional flag which is defined in the closetable API

Returns: Nothing

Error: sets the errno


Exposed by: table type

Usage: to get a connection for a table


Returns: reference to connection type

Error: NULL, sets the errno


Exposed by: connection type

Usage: to get the value for a given key

Arguments: Takes the key as parameter. The key could be in simple character string with null terminated or defined as FDT data type which takes the key (in any format, string, binary etc...) and its length. When dealing with FDT, user has the responsibility of freeing the memory as required

Returns: The value either as char* (in case char* was used as parameter or as FDT*)

Error: returns Null and sets the errno


Exposed by: connection type

Usage: to store the value for a given key

Arguments: Takes key, value and a flag as parameter. The key and value can again be character strings or of FDT types. The flag has following different values;

  • INSERT_UNIQUE if non-existing then insert else return
  • UPDATE_EXISTING if existing then update else return
  • INSERT_UPDATE insert if non-existing else update

Returns: 0 for success, 1 if key already exists and flag was INSERT_UNIQUE, 1 if key does not exits and flag was UPDATE_EXISTING

Error: -1


Exposed by: connection type

Usage: to delete the value for a given key

Arguments: Takes key as an argument for deletion. Note that the bangdb db doesn't delete and value from the file or compact it then and there, but it just marks it for deletion

Returns: 0 for success, 1 if key does not exist

Error: -1


Exposed by: connection type

Usage: to get the set of records for given start and end keys

Arguments: Takes start and end keys as paramters. It is supported for Btree type only

Returns:reference to resultset type. The result set is like cursor where user can iterrate over records. It has methods like hasnext(), movenext() etc...

Error: NULL

With transaction, the get, put, del, scan API takes void* txn parameter as the last argument. For ex; the get would become get(k, txn); where txn is void *. For detail info please see the API doc in the resource section