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

Large Table – Embedded C++

chevron

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;
	dp.setTransactionType(DB_TRANSACTION_NONE);
	bangdb_database *bdb = bangdb_database::getInstance("mydb", &dp);
	if(!bdb)
	{
		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;
	te.set_table_type(LARGE_TABLE);
	// large table must have composite primary key, else db will throw error
	te.set_key_type(COMPOSITE_KEY);
	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);
	if(!large_tbl)
	{
		printf("we could not create the table my_large_tbl\n");
		flag = false;
		// handle error
	}

	// let's load large file
	const char *file_path = "libbangdb.so.2.0";
	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 = "linbangdb.so.2.0_new_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;

	bdb->closeDatabase(DEFAULT);
	delete bdb;