Database Type (Embedded)
BangDBDatabase(const char *dbName, DBParam *dbParam = NULL);
To get the instance of BangDBDatabase, user may call this. Pls note, user will get same reference for a db if called multiple times with the same dbName. DB does reference counting hence user may call close() as many times of force close as well. DBParam defines the db environment. However, for embedded BangDB, only few parameters need to be set as opposed to for server BangDB. Please see DBParam below for more details.
If successful, this will return pointer to BangDBDatabase else NULL. Calling bangdb_print_last_error()
may help see the actual reason for the failure, however it's not guaranteed that error will be printed after calling this method, for details, you should always see the db activity log. Please read more db log here.
BangDBTable *getTable(const char *tblName, TableEnv *tblenv = NULL, OpenType openflag = OPENCREATE);
To get a table (create or open), we may call this function. TableEnv describes the details of table to be opened. When passed NULL, db uses default TableEnv setting which is explained in the TableEnv section below.
Openflag would tell whether to create or open a table. Following are different values for the OpenType:
enum OpenType {
OPENCREATE, //If existing then open else create
TRUNCOPEN, //If exiting then truncate data and open
JUSTOPEN, //If existing then open else fail
}
Open create is good most of the time if you wish to open if existing and create if not.
int dropTable(BangDBTable **tbl);
Drop table would permanently delete the table and all its data. It returns -1 for error or 0 for success.
int dumpData();
Dump data would force the db to sync data with the file system It returns -1 for error or 0 for success.
void closeDatabase(CloseType dbclose = DEFAULT);
This will close the database. The dbclose dictates how to close the db. Values of CloseType are as follows:
enum CloseType {
DEFAULT, //Simple close the db with syncing all data subsequently
CONSERVATIVE, //It will force sync data first. This may take time to close OPTIMISTIC, Similar to default, but ensures faster close
CLEANCLOSE, //It will clean all the data, delete everything before close
SIMPLECLOSE, //It will not iterate over every element
}
To put operations within transaction boundary, use these functons.
void beginTransaction(Transaction *txn);
long commitTransaction(Transaction *txn);
void abortTransaction(Transaction *txn);
Begin transaction starts the transaction commit would allow to commit every operations done after begin transaction and abort will simply cancel everything done within the transaction boundary. Commit transaction returns transaction number for success else -1 for error
long getTableId(const char *tblName);
This will return table id for the given table name
bool doesTableExist(const char *tblName, long tblId = 0);
To check if table exists or not. If tableid is 0 then db will use tableName else tableid. Returns true if existing else false
long getNumTables(int flag = 1);
To know how many tables are there in the database.
flag = 1 means, return count for open tables
flag = 2 means, return count for closed tables
flag = 3 means, return overall count
it returns -1 for error
const char *getTableList();
This returns list of all tables as a json string or NULL for error
const char *getStats(bool verbose = true);
This returns json string for database stats. Verbose = true will return lots of details and false will return less information
const char *getTableStats(const char *tblName, bool verbose);
This returns json string for stats for the given table name or NULL for error. Verbose = true will return lots of details and false will return less information
DBParam *getParamRef();
This returns the reference to the DBParam supplied during getInstance call. Please note it's reference therefore it should never be deleted by the user. DB should only clean it.
const char *getNameRef();
This returns the reference to the name of the db supplied during getInstance call. Please note it's reference therefore it should never be deleted by the user. DB should only clean it.
void *getDatabaseRef();
This returns the reference to the db itself, internal data structure, only useful in some advanced use cases. Please note it's reference therefore it should never be deleted by the user. DB should only clean it.
TableType getTableType(const char *tblName, long tblId = 0);
This return the type of the table for the given table name. TableType is defined below in the TableEnv type discussion.
TableEnv *getTableEnv(const char *tblName, long tblId = 0);
This return the TableEnv of the table for the given table name if tableid is 0, else it used tableid.
virtual ~BangDBDatabase();
It deletes the BangDBDatabase object.