2019 iT 邦幫忙鐵人賽

Software Development

Let's build a DBMS: StellarSQL -- a minimal SQL DBMS written in Rust系列 第 2

StellarSQL 1: Preparation & Basic Infrastructure

1: Preparation & Basic Infrastructure


It's recommened to read on gitbook for better Rust syntax highlihgt support and layout.

Introduction to DBMS

A database management system (DBMS) is a software run on server, which controls many databases. MongoDB, MySQL, Oracle, PostgreSQL, etc., all are DBMS.

A DBMS verifies authenticity of connections. It schedules tasks of requests, including inserting, deleting, or searching in a DB. It enforces rules, which defined by the users, for each transactions, such as specified types of data.

There are some materials good to read: "Database Management System – Introduction" on GeeksforGeeks, or "Database — Introduction" by Omar El Gabry on Medium. There are also many good articles that introduce to DBMS on the Internet, so I would not talk too much about it.

Once you know what is a DBMS, you would have an overview about what we are going to implement on StellarSQL. DBMS is a server service. It should be able to do any things on databases. It should be able to parse SQL languages. It needs a storage systems. It might have good algorithms for searching DB, storing data, or scheduling tasks. There might be much more functions for a DBMS, and I would finish them one by one.

Setup Environment

Ok, we are ready to program the StellarSQL!

First of all, we need to setup our programming environment.

Since StellarSQL is written in Rust language, you must install Rust via Rustup. Rustup is a version manager of Rust.

Enter the command in terminal to install Rust:

curl -sSf | sh

Once installing Rust, it will also installed Cargo for you. Cargo is a tool for running Rust and installing packages. It's recommended to read the Rust book if you have not learned Rust before. It's fine if you just read the rust code directly, because you still can understand the logic of the code in StellarSQL.


StellarSQL is on Github. You could get the source code of StellarSQL

git clone

The series is based on the project. I would only select the vital part of function ins articles while explaining a certain concept. You might want to know the full code, and you could browser the source code.

Build and Run

You could build and run the program simply run:

cargo run

With the progress of developing, it might be more steps to build and run, but all information would update on README.


I use travis as CI. CI will check the code can build and run, and check the format of code is OK.

Basic Infrastructure

The StellarSQL program might have some configuration and arguments.

If the user doesn't give arguments to run the program, the program should adopt the default value from configuration.

There are some settings would be covered in configuration and arguments. So far I could think of is that, the settings include the port of the server and whether the server runs in daemon mode. There might be more, and I will add others later.

For configuration, you can see there is a .env file, which is for configuration. The dotenv_codegen crate helps us to parse the value from .env. There is also a cli.yml file, which is the schema of arguments of the program, powered by clap crate.

You could run the program with the argument -h to see how to set arguments for StellarSQL once you cargo build an executable file. Assume it is a debug build, the file is at target/debug/stellar_sql.

./stellar_sql -h

Then you can see the introduction for the program, and all information is based on the cli.yml file.

We have added some code in the main program.

    let yml = load_yaml!("../cli.yml");
    let m = App::from_yaml(yml).get_matches();

    let port = if let Some(port_) = m.value_of("port") {
    } else {
    println!("StellarSQL running on {} port", port);

Now we can parse arguments and read values from configuration! In this example, if PORT is not in the arguments, it would use the default value from .env.

That's all for today!

Quick Link
1.StellarSQL Repository
2.Gitbook of this series

Liu, An-Chi (劉安齊). A software engineer, who loves writing code and promoting CS to people. Welcome to follow me at Facebook Page. More information on Personal Site and Github.

StellarSQL 0: Introduction to the series articles
StellarSQL 2: Basic Concept of Server
Let's build a DBMS: StellarSQL -- a minimal SQL DBMS written in Rust30

2 則留言

iT邦新手 5 級 ‧ 2018-10-17 01:03:21


iT邦研究生 1 級 ‧ 2018-10-17 22:03:09


微中子 iT邦新手 4 級 ‧ 2018-10-17 23:30:04 檢舉

哈哈哈 我只是懶的中英文切換 XD

SunAllen iT邦研究生 1 級 ‧ 2018-10-18 00:18:24 檢舉