1: Preparation & Basic Infrastructure
2018/10/16
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 https://sh.rustup.rs -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.
Code
StellarSQL is on Github. You could get the source code of StellarSQL
git clone https://github.com/tigercosmos/StellarSQL
cd StellarSQL
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.
CI
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") {
port_
} else {
dotenv!("PORT")
};
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!