+TITLE: FurDB

[[#api-branch][https://img.shields.io/badge/api-master-yellow.svg]] [[#rust-version-requirements][https://img.shields.io/badge/rustc-1.58+-lightgray.svg]]

A small and space-efficient Database Management System that allows you to allocate the size of individual data types in bits (not bytes).

+BEGIN_SRC

10011100 01010000 ⎾⎺⎺⎺⎺⎺⏋⎾⎺⎺⎺⎺⎺⎺⏋⎾⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⏋ ^ ^ ^ d1 d2 d3

+END_SRC

+BEGIN_SRC sh

git clone https://github.com/madhavan-raja/furdb.git

+END_SRC

and use the directory as an external crate.

Alternatively, you can directly use this repository as a git dependency by adding the following in your project's =Cargo.toml=:

+BEGIN_SRC toml

[dependencies] furdb = { git = "https://github.com/madhavan-raja/furdb" }

+END_SRC

Additionally, you will need a conversion server such as [[https://github.com/madhavan-raja/fur-converter][Fur Converter]] for the data conversion. The server should be running at the time of all data operations.

Import the crate using

+BEGIN_SRC rust

use furdb::{Converter, FurColumn, FurDB, FurDBInfo, FurDataType, FurTable, FurTableInfo};

+END_SRC

** Creating a new database =FurDB::new()= takes two parameters. - =dbpath= of type =PathBuf=, which contains the directory to create the database. - =dbinfo= of type =Option=, which contains the database information.

If the database already exists, the information provided as part of =db_info= is ignored. Otherwise, a new database is created with the information present in that.

+BEGIN_SRC rust

let dbpath = PathBuf::from("~/FurDB/SampleDB"); let dbinfo = FurDBInfo::new("Sample Database"); let db = FurDB::new(dbpath, Some(dbinfo))?;

+END_SRC

** Creating a new table =db::gettable()= takes two parameters. - =tableid= of type =&str=, which has the ID of the table---or the name of the directory representing the table. - =table_info= of type =FurTableInfo=, which contains the table information.

If the table already exists, the information provided as part of the =table_info= is ingored. Otherwise, a new table is created with the informatino present in that. Tables are always created within the database directory.

+BEGIN_SRC rust

let tableid = "SampleTable"; let tableinfo = FurTableInfo::new("Sample Table", None)?; let tb = db.gettable(tableid, Some(table_info))?;

+END_SRC

** Creating the columns A column in a Fur Tables consists of: - =id= of type =&str=, which should be the key of the value in the =HashMap= of the data. - =description= of type =&str=. - =size= of type =u128=, which should specify the number of bits that the data should use. - =data_type= of type =FurDataType=, which contains the name and =converter= of the said type.

Create a column with

+BEGIN_SRC rust

let samplecolumn = FurColumn::new( "samplecolumn", Some("Sample Column"), 11, integerdatatype, );

+END_SRC

** Adding data to the table The data for a row is stored in a =HashMap=, with the key corresponding to the =id= of the column and the =value= corresponding to the data.

Add the data using with

+BEGIN_SRC rust

let sampledata = [ HashMap::from([("samplecolumn", "7")]), HashMap::from([("sample_column", "6")]), ];

tb.add(&sample_data)?;

+END_SRC

** Getting the data The data is returned in a =HashMap=.

+BEGIN_SRC rust

let result = tb.get()?;

for row in result { println!("{:?}", row); }

+END_SRC