TinyDB Julia

Posted in category Software on
839 Words ~5 Minute Reading Time • Subscribe to receive updates on Software
Eric David Smith
Software Engineer / Musician / Entrepreneur
TinyDB Julia by Eric David Smith
Click image to view on GitHub

TinyDB Julia

An extremely simple database written in the Julia Programming Language. This is a very rudimentary database and lacks many features you would expect in a production-ready system, such as indexing for fast lookups, transactions, concurrency control, error handling, data integrity checks, and more. It is intended to be used for small projects where you need a database but don't want to deal with the overhead of setting up a full-fledged database.

Why?

I've been learning Julia and this seemed like a fun project to create.

Julia Highlights

Fast

Julia was designed from the beginning for high performance. Julia programs compile to efficient native code for multiple platforms via LLVM.

Dynamic

Julia is dynamically typed, feels like a scripting language, and has good support for interactive use.

Reproducible

Reproducible environments make it possible to recreate the same Julia environment every time, across platforms, with pre-built binaries.

Composable

Julia uses multiple dispatch as a paradigm, making it easy to express many object-oriented and functional programming patterns. The talk on the Unreasonable Effectiveness of Multiple Dispatch explains why it works so well.

General

Julia provides asynchronous I/O, metaprogramming, debugging, logging, profiling, a package manager, and more. One can build entire Applications and Microservices in Julia.

Open source

Julia is an open source project with over 1,000 contributors. It is made available under the MIT license. The source code is available on GitHub.

Requirements

Instal Julia

brew install --cask julia

or

Download and install from julialang.org

TinyDB Julia - Installation

Since this is a simple project, there is no installation process per se. You just need to clone the repository and ensure you have Julia installed on your system.

git clone https://github.com/erictherobot/tinydb-julia.git

Usage

This project provides a TinyDB struct that represents the database and store and retrieve functions to interact with the database.

Here is a basic example:

include("src/TinyDB.jl")

# create a new database
db = TinyDB("mydb.txt")

# store a key-value pair in the database
store(db, "Hello", "World")

# retrieve the value for a given key
println(retrieve(db, "Hello"))  # prints "World"

The database is stored in a text file. The file format is very simple: each line contains a key-value pair separated by a colon. For example, the following file contains two key-value pairs:

Running the Example

To run the example, use the following command:

julia example.jl

This will create a database file called mydb.txt and store the key-value pair "Hello": "World" in the database. It will then retrieve the value for the key "Hello" and print it to the console.

Tests

This project includes a small set of tests. You can run the tests with the following command:

julia test/runtests.jl

which should produce the following output:

Test Summary: | Pass  Total  Time
TinyDB Tests  |    3      3  0.1s

These tests verify basic functionality such as storing and retrieving key-value pairs, and overwriting existing keys with new values. They also test that the database file is created if it does not already exist.

Future Work

While this project is intentionally simple, there are many ways it will be extended:

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

If you find this useful as is please let me know. If you find any bugs, please feel free to submit a pull request or open an issue. If you have any questions, you can contact me.

Supporting My Work

Please consider Buying Me A Coffee. I work hard to bring you my best content and any support would be greatly appreciated. Thank you for your support!

Contact


Eric David Smith
Software Engineer / Musician / Entrepreneur
Software

Related Blog Posts

👈 Scroll 👉

Blog Post Tags