Group project in school. Implementation of a DB server in Rust.
Find a file
Jindřich Moravec 0702f4e3e1 Merge branch 'update-readme' into 'main'
Update README.md

See merge request x433485/minisql!41
2024-02-05 23:52:28 +01:00
client cargo format 2024-01-28 22:40:41 +01:00
minisql Saving of metadata 2024-02-05 23:07:56 +01:00
parser feat: connect server to the new interpreter 2024-02-05 21:59:33 +01:00
proto refactor: add standalone PgOid type 2024-02-01 22:27:58 +01:00
server feat: pass cancellation token to interpreter 2024-02-05 22:13:48 +01:00
storage_engine Merge remote-tracking branch 'origin/interpreter2-misc' into interpreter-to-storage-engine 2024-02-05 22:01:34 +01:00
.gitignore feat(proto): add proto crate to workspace 2023-12-15 16:41:02 +01:00
.gitlab-ci.yml ci: add pipeline for build and test 2024-01-28 18:30:06 +01:00
Cargo.lock feat: metadata serialization 2024-02-05 21:36:58 +01:00
Cargo.toml First attempt at storage engine 2024-02-01 03:02:12 +01:00
demo-1.sql Add new demo data 2024-02-05 22:49:18 +01:00
demo-2.sql Add new demo data 2024-02-05 22:49:18 +01:00
demo-3.sql Make two more entries have value "42" in the table 2024-02-05 23:26:24 +01:00
DESIGN_OLD.md Explain the role of the DESIGN_OLD.md file 2024-02-01 13:35:10 +01:00
DIVISION_OF_LABOUR.txt Clear up division of labour 2024-01-28 22:51:27 +01:00
README.md Update README.md 2024-02-05 23:49:05 +01:00

MiniSQL

Project Structure

  • client - REPL client for connecting to the server
  • server - MiniSQL server
  • minisql - SQL AST interpreter
  • parser - SQL parser
  • proto - Implementation of subset of PostgreSQL protocol

Requirements

  • Rust + Cargo with version >= 1.74.0 (using impl in return statements)
  • Optional: psql cli for testing the server

Usage

Running the server

cargo run -p server -- [OPTIONS] --folder <FOLDER>
Options:
  -a, --address <ADDRESS>  IP address for the server to listen on [default: 127.0.0.1]
  -p, --port <PORT>        Port for the server to listen on [default: 5432]
  -f, --folder <FOLDER>    Path to the folder for database data
  -t, --throttle <DELAY>   Delay between rows in milliseconds
  -h, --help               Print help

This will start the server listening on <ADDRESS>:<PORT> and load the state from <FOLDER>. If the <FOLDER> does not exist, it will be created.

Demo Database

Commands that set up a database with demo data are available in demo-1.sql, demo-2.sql, and demo-3.sql.

These files showcase the following things:

  • demo-1.sql: small tables that handle Unicode and make use of the Optional type
  • demo-2.sql: a bigger (1000 rows) table with realistic data
  • demo-3.sql: a big (10,000 rows) table with simple data (was easier to generate)

See comments in these files for details.

Running the client

cargo run -p client -- [OPTIONS]
Options:
  -p, --port <PORT>          Port number of the server [default: 5432]
      --host <HOST>          Host name or IP address of the server [default: 127.0.0.1]
      --username <USERNAME>  User name [default: "minisql user"]
  -h, --help                 Print help

This will start a REPL client that connects to the server at <HOST>:<PORT> and authorizes with <USERNAME>. SQL queries can be entered line by line. The client will print the result of each query.

To exit the REPL client, enter exit or quit.

Features

  • SQL must be on single line, in UPPERCASE, as it should be. The ; at EOL is optional.
  • Supported operations: CREATE TABLE, CREATE INDEX, SELECT, INSERT, DELETE
  • Supported data types: UUID, STRING, INT, NUMBER
  • Supported subset of PostgreSQL protocol, without authentication and simple query flow

Operations

CREATE TABLE

  • Every table requires one column with type UUID as PRIMARY KEY
CREATE TABLE <TableName> (<ColumnName> <DataType>, ...);

With the demo database, this can be used to create a new table:

CREATE TABLE games (id UUID PRIMARY KEY, name STRING, year INT, price NUMBER);

CREATE INDEX

  • Indexing is not supported for the NUMBER data type
CREATE INDEX <IndexName> ON <TableName> (<ColumnName>);

With the demo database, this can be used to create a new index:

CREATE INDEX CarsYear ON cars (year);

SELECT

  • WHERE clause is optional and only equality is supported
  • All columns can be selected with *
SELECT <ColumnName>, ... FROM <TableName> [WHERE <ColumnName> = <Value>];

With the demo database, this can be used to select all cars with year 2001:

SELECT * FROM cars WHERE year = 2001;

INSERT

INSERT INTO <TableName> (<ColumnName>, ...) VALUES (<Value>, ...);

With the demo database, this can be used to insert a new user:

INSERT INTO users (id, name, surname, email) VALUES (u12345, "John", "Doe", "johhny.trucker@seznam.cz");

DELETE

  • WHERE clause is optional and only equality is supported
DELETE FROM <TableName> [WHERE <ColumnName> = <Value>];

With the demo database, this can be used to delete all users with name Christina:

DELETE FROM users WHERE name = "Christina";

Data Types

  • UUID - special integer prefixed with u, e.g. u12345
  • STRING - string enclosed in double quotes, e.g. "Hello World"
  • INT - integer, e.g. 12345
  • NUMBER - floating point number, e.g. 123.45
  • Option(Something) - optional type, e.g. Some("james.stuart@gmail.com") or None

Testing with psql

Thanks to the subset of PostgreSQL protocol implemented in proto, the server can be tested with psql, which offers REPL client similar to the client crate:

psql -h <HOST> -p <PORT>