Deal with database objects

Before we start doing anything with the db, it is important to get the reference to db objects first and then using these objects perform various activities

In this document, we will discuss the various objects available to us required for buiding apps

database

The first step towards working with BangDB is to get the databas object. The database is a class and we need to create an object of database

API

database(const char *dbName, const char *configPath = NULL, db_transaction_type tranType = DB_TRANSACTION_NONE, const char *dbpath = NULL, const char *dblogpath = NULL);

To create database;

	//create db with default values, which is to get the db path (server_dir) 
	//from config file, bangdb.config in local dir, transaction is not enabled
	
	database *db = new database("mydb");
		
	//with transaction enabled, db path (server_dir) from config file, bangdb.config 
	//in local dir (NULL for second param means that)
	
	database *db = new database("mydb", NULL, DB_OPTIMISTIC_TRANSACTION);
		
	//with transaction enabled and db path (where to store db files) specified, 
	//bangdb.config still in local dir
	
	database *db = new database("mydb", NULL, DB_OPTIMISTIC_TRANSACTION, dbpath);
	
	//with logpath defined as well
	
	database *db = new database("mydb", NULL, DB_TRANSACTION_NONE, dbpath, logpath);
		
	//finally with config file path provided as well
	
	database *db = new database("mydb", config_file_path, DB_TRANSACTION_NONE, dbpath, logpath);
	
	//etc...
	

To close database

	db->closedatabase();
	delete db;
	

API

Database(string dbName, string configpath, TransactionType transaction_type = TransactionType.DBTransactionNone, string dbpath = null, string logpath = null)

To create database;

	//create db with default values, config_path is the loc where bangdb.config is kept 
	//rest params are default. dbpath is (SERVER_DIR) where db files will be kept (read from config file if null)
	
	Database db = new Database("mydb", config_path);
		
	//with transaction enabled, db path (server_dir) from config file
	
	Database db = new Database("mydb", config_path, TransactionType.DBOptimisticTransaction);
		
	//with transaction enabled and db path (where to store db files) specified
	
	Database db = new Database("mydb", config_path, TransactionType.DBTransactionNone, dbpath, dblogpath);
		
	//etc...
	

To close database

	db.CloseDatabase();
	

API

DatabaseImpl(String dbName, String configPath, TransactionType transactionType, String dbPath, String dblogPath)

To create database;

	
	//create db with default values, 
	//note that the configPath and dbPath can be null which means pick the config file 
	//from local dir and dbPath value as defined in config file (for SERVER_DIR)
	
	Database db = new DatabaseImpl("mydb", null, TransactionType.DB_MULTIOPS_TRANSACTION_NONE, null, null);
		
	//with transaction enabled, db path (server_dir) from config file
	
	Database db = new DatabaseImpl("mydb", null, TransactionType.DB_OPTIMISTIC_TRANSACTION, null, null);
		
	//with transaction enabled and db path (where to store db files) specified
	
	Database db = new Database("mydb", null, TransactionType.DBOptimisticTransaction, dbPath);
	
	//with transaction disabled and db path and log path(where to store log files) specified
	
	Database db = new Database("mydb", null, TransactionType.DB_MULTIOPS_TRANSACTION_NONE, dbPath, dblogPath);
		
	//etc...
	

To close database

	db.closeDatabase(DBClose.DEFAULT);