LibreFrame

LibreDatabase

What is LibreDatabase ?

Standard Practices

The standard paradigm for general-purpose databases is the relational model with the SQL query language. Nothing is really well defined in SQL, and the standard (not even freely available) is betrayed in every implementation. Without a truly standardized implementation, the cost of an SQL interpreter—with its impedance, slowness, inefficiency, and inaccuracies—must be called into question.

Standard Practices

Given today’s available RAM and modern persistence technologies (NVMe), it may be worth rethinking the architecture of current databases, which are primarily disk-based and use memory as a cache.

A reversal of resource allocation appears to be beneficial: use RAM as the database’s primary working resource and the disk solely as a means of persistence.
This proposal is called LibreDatabase.

Design

General information

LibreDatabase is an ACID-compliant database that supports versioning and automatic version upgrades.

LibreDatabase directly supports and handles Ada types. Much to the delight of developers, there is no impedance mismatch between the language and the database. This design improves development speed and data security, since the very concept of an SQL injection vulnerability is obsolete.

LibreDatabase is embedded within the application. It requires no network interface to communicate with the application code. This approach greatly improves performance and security.

Model mapping

The data model consists, on the one hand, of a document describing the database schema and, on the other hand, of a code generator of standard operations for accessing and manipulating data.

Data handling

Data is manipulated directly using the language, and in `for .. loop` iterations, even the `reverse` keyword is supported.

The schema for defining a LibreDatabase has a syntax and semantics that are user-friendly for developers using the LibreFrame language.

This schema is a text file with the .lds extension (LibreDatabase Specification). A GNAT Studio plugin allows these .lds files to be integrated into the IDE.

Index

Indexes are sorted in ascending order by default. Descending order can be achieved by using the Ada keyword `reverse`.

Indexes can be simple or composite. In the case of composite indexes, a formatting function can be applied to them.

Indexes use ascending order by default. Descending order can be achieved by using the Ada keyword `reverse`. Indexes can be simple or composite. In the case of composite indexes, a formatting function can be attached to them.

LibreDatabase uses Ada containers, so the sorting implementation is based on Red-Black Trees.

Relations

The relational model is based primarily on:

  • Relations: Data is represented by relations, typically implemented as tables.
  • Columns: Each relation has columns associated with values.
  • Rows: Each relation contains a set of rows.
  • Integrity constraints: These define the valid states of the data. Integrity constraints are managed through ACID properties and foreign keys.
  • Relational algebra: This allows relations to be manipulated using mathematical operations (selection, join, etc.).

LibreDatabase directly meets the first four criteria but does not directly incorporate full relational algebra, like join operations. This last point is easily up to the developer, with a view to optimizing performance.

We fully embrace this approach in order to adhere to the KISS principle and ensure predictable processing times.

Persistence

To be persistent…

Persistence is ensured by calling the Open procedure at the beginning of the program. All operations on LibreDatabase are recorded in a WAL (Write-Ahead Log file).

The next time the program starts, the WAL file is read, the data is loaded and the indexes are recreated into memory, the WAL file is then compacted into a new file, and the old file is finally deleted atomically.

An interesting secondary feature of this organization is database backup, which is performed by simply copying the WAL file using the operating system’s `copy` command, possibly in conjunction with a compression utility for efficiency. Example under Linux:

user@system : cp database.ldb /dev/stdout | zstd -c > database.ldb.zst

Being able to do without a specific backup tool by relying on proven tools ensures simplicity and efficiency.

…or not to be persistent

Persistence is optional. If the Open procedure is not called at the beginning of the program, LibreDatabase remains functional within the program, but the data will be lost when the program ends.

This last point is not just a quirk but a useful feature for many applications that do not require persistence.

Security and data privacy

Application level

The SQL interface, which consistently deviates from standards, poses a major obstacle to developers’ productivity and portability.

The presence of an SQL interpreter prevents the creation of real-time applications and also poses a major security risk, particularly in the context of SQL injection attacks.

Removing the interpreter by embedding the LibreDatabase code allows for the creation of real-time applications without the security risk posed by malicious command injection.

Network level 

The client-server architecture presents an inherent vulnerability due to the existence of an entry point on the database server.

LibreDatabase’s hyper-converged approach, combined with the embeding of LibreDatabase code into the program, ensures protection by design.

System level

Data confidentiality is ensured at the system level through standard mechanisms in both RAM and mass storage.

Conclusion

LibreDatabase, with its code-embedded, hyper-converged, NoSQL approach, offers greater security potential than mainstream databases.

In any case, the best safeguard is always to physically restrict access to the server hosting a sensitive application.

Performance