bg
bangdb_database – Embedded C++ – BangDB = NoSQL + AI + Stream

bangdb_database – Embedded C++

chevron

bangdb_database

Embedded, C++

static bangdb_database *getInstance(const char *dbName, db_param *dbParam = NULL);
To get the instance of bangdb_database, 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.
db_param defines the db environment. However, for embedded BangDB, only few parameters need to be set as opposed to for server BangDB. Pls see db_param below for more details
If successful, this will return pointer to bangdb_database 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.
bangdb_table *getTable(const char *tblName, table_env *tblenv = NULL, bangdb_open_type openflag = OPENCREATE);
To get a table (create or open), we may call this function.
table_env describes the details of table to be opened. When passed NULL, db uses default table_env setting which is explained in the table_env section below.
Openflag would tell whether to create or open a table. Following are different values for the bangdb_open_type
enum bangdb_open_type { 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. Note opening an existing table with different table_env may result in error
int dropTable(bangdb_table **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(bangdb_close_type dbclose = DEFAULT);
This will close the database. The dbclose dictates how to close the db. Values of bangdb_close_type are as follows;
enum bangdb_close_type { 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(bangdb_txn *txn); long commitTransaction(bangdb_txn *txn); void abortTransaction(bangdb_txn *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
db_param *getParamRef();
This returns the reference to the db_param 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 strcture, 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
bangdb_table_type getTableType(const char *tblName, long tblId = 0);
This return the type of the table for the given table name. bangdb_table_type is defined below in the table_env type discussion.
table_env *getTableEnv(const char *tblName, long tblId = 0);
This return the table_env of the table for the given table name if tableid is 0, else it used tableid
virtual ~bangdb_database();
It deletes the bangdb_database object