<-- Back to Andy Balaam Home

NNDB's Not a Database

Home | Download | Examples | Discussion | Code | Links | Contact

Introduction

NNDB is my playground for understanding databases.

It is a C++ library that provides in-memory data storage and retrieval using syntax that is intended to feel natural for C++/STL, but which also might feel slightly like SQL if you squint and pound the top of your head with a seminal programming textbook.

As part of NNBD I developed the ForEachType class template and contributed it to Loki. Follow the links to find out more.

Column types are fixed at compile-time and checked by the compiler.

Download

You can download it from the NNDB download page.

Examples

Example syntax:

 nndb::Table<std::string, int> my_table;

 my_table.Insert( nndb::Values<std::string, int>(
     "NNDB first row", 47 ) );

 nndb::ResultSet<std::string, int> result_set =
     nndb::Select<std::string, int>( nndb::select_star, my_table );

This does something sort of similar to the following SQL:

 CREATE TABLE my_table (
     col0 VARCHAR( ... ),
     col1 INT
 );

 INSERT INTO my_table( col0, col1 ) VALUES ( "NNDB first row", 47 );

 SELECT * FROM my_table;

You can use the results of your select like this:

 nndb::ResultSet<std::string, int>::const_iterator begin_it =
     result_set.begin();

 const nndb::Values<std::string, int>& first_row = *begin_it;

 assert( nndb::Field<0>( first_row ) == "NNDB first row" );
 assert( nndb::Field<1>( first_row ) == 47 );

To see all the current features in action, read the complete example.

(Lack of) features

Here are some useful features of databases that NNDB actually has (analogues of) now:

Here are some useful features of databases that NNDB might one day have:

Here are some useful features of databases that NNDB will never have:

Discussion

The database definition is almost always known at compile time - so why not use the compiler to enforce type correctness?

Note there is no need for anything like a BLOB column type or similar in NNDB - any type that is a value type (i.e. may be copied, assigned and compared in the normal way) and is default-constructible can be stored in a table.

Code

Check it out from git:

 git clone https://codeberg.org/andybalaam/nndb.git

Build it like this:

 sudo apt-get install libboost-all-dev libloki-dev scons

 cd nndb
 scons

Links

Contact

Please contact the NNDB developers by creating an issue.

Home | Download | Examples | Discussion | Code | Links | Contact

Edit | History | Print | Recent Changes | Search | Admin Page last modified on November 04, 2022, at 07:27 PM