BangDB Command Tool

NOTE: This is being updated for more supported features. The new command line tool is coming shortly

This section discuss about the command line tool which can be used to connect to the BangDB server and perform various operations

With 0.9 version of server, command tool is not a requirement to work with server. Earlier user could only do DDL operations like db creation, table creation etc using command tool and not through programmatically. But with 0.9 user can now do all admin level operations like DDL through program also. Please see Admin vs Non Admin user for detail discussion on how to work as admin and non admin

This feature makes the overall process simple as user can have the admin program to control various things and have non admin program for typical operations. The reliance on command tool only for admin level jobs was restrictive and we needed to remove the restriction

Note that for table creation and drop, user can only do these with the command line tool as well. Currently BangDB server can work on single database (unlike embedded version where user can simultaneously open and work with multiple dbs) but there can be many tables within the database. The reason for restriction is simply because of not including the feature in the current release and it is only for the time being and in coming weeks the option will be enabled and user should be able to deal with multiple dbs at a time

Run the command line tool

We just need to run the install.sh file to put the files in proper places to be able access the server both programatically or through the bangdb-cmd tool

To install the client, go to the client folder and run the install.sh file

	> cd client
	> bash instal.sh

Now ensure that the server is running (please see Install Server to know how to run the server)

To run the command line tool simply do following;

	> bangdb-cmd 127.0.0.1:8000
	
	# please replace 127.0.0.1:8000 with value applicaple in your context.
	# it is basically ip:port combination, for example here ip is 127.0.0.1 and port is 8000

It will look something like this when you run the tool

	# to see the help, just type help
	> help

Supported Commands

The command line tool currently supports simple SQL like queries. Here are the detail information on the supported commands

Set up the database and tables

For BangDB server all the DDL/DML operations can be done through command line tool only. The clients can only do read and write operations (get, put, update, delete). In the section we will create tables

Note that BangDB currently works on the single database and database name has to be defined before server is run. There are two ways for defining the database name

  • bangdb.config file - edit the BANGDB_DATABASE_NAME config value
  • pass the -d command line value while starting the server

When client connects to the server (programatically), it should use the same name as defined by the server to connect to it

Now when we run following command it will show out put like this

	bangdb-server>: describe database;
	
	database name = mydb
	no tables found at the server

This means that we have not yet created any table at this point in time

Create Table


	bangdb-server>: create table 'mytable';
	# this will trigger tool to ask few questions on options. The deafult value will be the one defined in the
	# bangdb.config file
	Persist Type [INMEM_ONLY (1) | INMEM_PERSIST (2)],  Or Enter for default:
	Index Type [EHASH (1) | BTREE (2)],  Or Enter for default:
	Key Size in bytes (at least 8 bytes, as low as possible),  Or Enter for default:
	Write ahead log [Disabled (1) | Enabled (2)],  Or Enter for default:
	
	# if you had simply entered (default) for all options here is the what you will see
	Entered values: 
	----------------
	Table Name = mytable,
	Persist Type = Default,
	Index Type = Default,
	Key Size = Default bytes,
	Log State = Default,
	Log Type = N/A,
	Log Size = N/A MB
	Please type 'a' for abort or 'c' for commit [ a | c ]:
	c
	Creating table......
	table mytable created successfully
	
	# now if you run the describe table it would look like following;
	bangdb-server>:describe table 'mytable';

	Persist Type	: INMEM_PERSIST
	Index Type	: BTREE
	Key Size	: 24 Bytes
	Log State	: ENABLED
	Log Type	: SHARED
	Table is in 'Open' state at the Server
	

In similar fashion, we can create as many tables as we may wish

Operations on table

	# insert a key and value
	bangdb-server>:insert into 'mytable' values 'key1' 'value1';
	insert successful!
	
	# get the key
	bangdb-server>:select * from 'mytable';

	key1,	value1

	1 rows retrieved successfully
	
	# or you can
	bangdb-server>:select * from 'mytable' where key = 'key1';    

	key1,	value1

	1 rows retrieved successfully
	
	# update key
	bangdb-server>:update 'mytable' set val = 'value2' where key = 'key1';

	1 rows updated successfully
	
	bangdb-server>:select * from 'mytable' where key = 'key1';

	key1,	value2

	1 rows retrieved successfully
	
	# delete the key
	bangdb-server>:delete from 'mytable' where key = 'key1';

	1 rows deleted successfully
	
	# you can close the table, note closing is not dropping the table
	# we close table when we know that table is not being used and consuming resources
	# dropping would mean deletion of files as well
	
	bangdb-server>:close table 'mytable'
	table mytable closed successfully
	
	# now describe the table and note the state of the table in the last line
	bangdb-server>:describe table 'mytable';

	Persist Type	: INMEM_PERSIST
	Index Type	: BTREE
	Key Size	: 24 Bytes
	Log State	: ENABLED
	Log Type	: SHARED
	Table is in 'Closed' state at the Server
	
	# similarly open the table
	bangdb-server>:open table 'mytable';
	table mytable opened successfully
	
	# dump the data in the table
	bangdb-server>:dump table 'mytable';
	table mytable dumped successfully
	
	# drop the table
	bangdb-server>:drop table 'mytable';

	your are going to permanently drop and delete the table files
	you may close the table and move the table files as archive instead
	
	do you still wish to drop the table...?  yes/no [y | n]
	y
	dropping table mytable ...
	table mytable dropped successfully
	
	# sign off
	bangdb-server>:exit
	exiting... Bye!
	

Note

Before clients can start doing anything, we need to create tables in the database