Large Table – Embedded C++ – BangDB = NoSQL + AI + Stream

Large Table – Embedded C++


Large table operations

Embedded C++

Here is a sample program which does most of the operations to help you understand the apis and their usage.

	bool flag = true;

	db_param dp;
	bangdb_database *bdb = bangdb_database::getInstance("mydb", &dp);
		printf("db could not be created, quitting\n");
		//return or handle error
	// db_param sets the db environment, see the section to know more about it

	// create a large table
	table_env te;
	// large table must have composite primary key, else db will throw error
	te.set_key_size_byte(64);	// set key size keeping ~32 bytes for system to add/consume
	bangdb_table *large_tbl = bdb->getTable("my_large_tbl", &te, OPENCREATE);
		printf("we could not create the table my_large_tbl\n");
		flag = false;
		// handle error

	// let's load large file
	const char *file_path = "";
	const char *fkey = "bangdb_2_0_binary";
	FDT fk;
	bangdb_table::add_string_to_fdt(fkey, &fk, false);
	if(large_tbl->put_file(&fk, file_path, INSERT_UNIQUE) < 0)
		printf("error in putting large file\n");
		flag = false;
		// handle error
	const char *file_name = "";
	const char *download_fpath = "/tmp";
	if(large_tbl->get_file(&fk, file_name, download_fpath) < 0)
		printf("get file error\n");
		flag = false;
		// handle error

	int nslices = large_tbl->count_slice_large_data(&fk);
	printf("num of slices for the file = %d\n", nslices);

	const char *finfo = large_tbl->list_large_data_keys(fkey);
	printf("the file info = %s\n", finfo);
	delete[] finfo;

	delete bdb;