What is Knarvik?
Knarvik is a table-oriented framework for C++. Knarvik generates source code for an in-memory database of your design.
What Knarvik is NOT?
- Knarvik is a relational database yet it is not SQL-based. Knarvik is extremely lightweight and fast: data is accessed through C pointers without any intermediary layers.
- Knarvik is not an object-relational mapping tool. Knarvik helps the developer to model the program using the relational paradigm and generates an API that implements the routine data-manipulation functions.
- Knarvik is not a library for database access. With Knarvik, all data remains in RAM, no external database is needed. However, Knarvik does provide automatic serialization of your in-memory data if needed.
How does Knarvik work?
Knarvik reads the database schema in XML format and produces human-readable C++ source code.
An example database schema:
<Base Name="Staff" Namespace="GoodCompany" Asserts="yes">
<Field Name="FirstName" Type="string"/>
<Field Name="SecondName" Type="string"/>
<Field Name="Salary" Type="int"/>
<Field Name="MyDepartment" Type="link" Target="Department.Employees"/>
<Field Name="DeptId" Type="int"/>
<Field Name="Employees" Type="link" Target="Employee.MyDepartment"/>
<Index Name="DepartmentById" Record="Department">
<IndexField Field="DeptId" />
Code that uses the database generated from this schema:
// Insert a row into the Department table
Department* d10 = Department::Create(10);
// Insert new rows into the Employee table
// and link them to the d10 department row.
Employee::Create(Utf16("John"), Utf16("Smith"), 2000, d10);
Employee::Create(Utf16("Joe"), Utf16("Black"), 2500, d10);
// Lookup the Department row using the hash-based index.
Department* dept = DepartmentById::Find(10);
// Read-only access to the indexed field.
cout << "The actual department id is: " << dept->GetDeptId() << endl;
// Iterate over linked Employee rows.
// Note: no need for a traditional database join.
for (int i = 0; i < dept->GetEmployeesCount(); i++)
Employee* person = dept->GetEmployees(i);
// Fast access to the field.
cout << "salary: " << person->Salary << endl;
Download the full example: Example.zip
The author can be reached by email:
stipan.mitkin gmail com