C++
Java
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.

public BangDBDatabase(String dbName, DBParam dbparam)

Given a dbname and dbparam, this will create the BangDBDatabase object. DBParam is defined below for reference.

public BangDBTable getTable(String tableName, TableEnv tenv, OpenType openType)

Returns BangDBTable object for given tableName, tenv. OpenType when null, then OPENCREATE is used as default.

public void beginTransaction(Transaction txn) 

To begin transaction, pass the Transaction object. Txn cannot be null.

public long commitTransaction(Transaction txn)

To commit transaction, pass the Transaction object. Txn cannot be null. It returns txn number for success or -1 for error.

public void abortTransaction(Transaction txn)

To abort transaction, pass the Transaction object. Txn cannot be null.

public int dumpData()

To dump data on the file system, syncing all data from memory to filesystem, this api can be called. It returns 0 for success else -1 for error.

public int dropTable(BangDBTable tbl)

Given a BangDBTable, this api will drop the table from the database, which would erase all data and other information for the given table. It returns 0 for success else -1 for error.

public boolean doesTableExist(String tblName, long tblId)

Given tblName or tblId, this can check if the table is existing. If tblId is less than 0 then tblName would be used, else tblId is used. It returns true if exists else false.

// flag = 1 for open, 2 for closed, 3 for all
public int getNumTables(int flag)

This will return number of tables in the database. Flag set as 1 would return count for open tables only, whereas if set to 2 then it will return count for closed tables only. Flag set as 3 would return for both open and close. For error it returns -1.

public String getTableList()

This will return list of table in json format, else null for error.public String getStats(boolean verbose) This API would return json string containing the statistics of the database. If verbose then it will returns lots of details. It may return null for error.

public String getTableStats(String tblName, boolean verbose)

This API would return json string containing the statistics of the given table. If verbose then it will returns lots of details. It may return null for error.

public String describeDatabase()

This api would return json string describing the database. It may return null for error.

public DBParam getParam()

This returns dbParam used to create the DB object.

public String getName()

This returns name of the database or null for error.

public TableType getTableType(String tblName, long tblId)

This returns table type for the given tblName or tblId. IftblId is positive then it will be used else for negative value tblName will be used.

public TableEnv getTableEnv(String tblName, long tblId)

This returns table environment for the given tblName or tblId. If tblId is positive then it will be used else for negative value tblName will be used. For error, null may be returned.

public long getTableId(String tblName)

Given a tblName, this will return table id, else -1 for error.

public String add_udf(String udf_json)

This will add udf to the database which could be later used for computation. Here is the format of the udf_json.

{"name":"mylib", "base_class":"baseclass", "create_func":"maker","type":1, "src":"src_loc", "srctype":1, "bucket_info":{}}

It will return json string containing errcode, 0 for success and -1 for error.

public String del_udf(String udf_name)

Given a udf_name this API will delete the udf from the database. It will return json string containing errcode, 0 for success and -1 for error.

public String exec_udf(String req_json)

This will allow user to execute udf given the request json. req_json looks like following:

{"name":, "id", "argv":["a", 1, 0.3], "exp-type"}

and the return value is also a json and it looks like:

{"ret-val":"abc"}
public void closeDatabase(CloseType dbclose)

To close database, call this function. Dbclose when null, Default option is used.