Group project in school. Implementation of a DB server in Rust.
Find a file
Maxim Svistunov 63171f3b32 Merge branch 'docs' into 'main'
Project documentation

See merge request x433485/minisql!23
2024-01-28 23:07:53 +01:00
client cargo format 2024-01-28 22:40:41 +01:00
minisql cargo format 2024-01-28 22:40:41 +01:00
parser cargo format 2024-01-28 22:40:41 +01:00
proto cargo format 2024-01-28 22:40:41 +01:00
server cargo format 2024-01-28 22:40:41 +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 fix: empty select returns header 2024-01-28 20:45:09 +01:00
Cargo.toml Add parsing (incl. validation) 2024-01-26 18:20:45 +01:00
demo.json Add demo DB with two tables 2024-01-28 22:10:33 +01:00
DESIGN.md Move Column into schema.rs 2024-01-28 18:40:34 +01:00
DIVISION_OF_LABOUR.txt Clear up division of labour 2024-01-28 22:51:27 +01:00
README.md docs: remove empty line 2024-01-28 23:01: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] --file <FILE>
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, --file <FILE>        Path to the data file
  -h, --help               Print help

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

Demo Database

A database with demo data is available in demo.json. To run the server with this database, use:

cargo run -p server -- --file demo.json

This database contains two tables:

  • Table users with columns id, name, surname, email
  • Table cars with columns id, vid, brand, model, year

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 and end with ;, as it should be
  • 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>, ...);

CREATE INDEX

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

SELECT

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

INSERT

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

DELETE

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

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

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>