Skip to content

llxgdtop/RusticDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RusticDB

A from-scratch, educational SQL database implementation written in Rust. Implements core SQL features (parsing, execution, storage) for learning purposes.Inspired by roseduan. Not production-ready, but a fully-functional tour of database internals.

If you like, please give me a star.

image-20260222171843155

Currently, the storage engine is based on memory, and it is only natural to switch to a disk-based storage engine. During development, I implemented a simplified version of the Bitcask storage engine but did not commit it. Readers can consider implementing the Engine trait themselves to enable this SQL database to store data on disk. For beginners, they can implement Bitcask or BTree; for more advanced users, they can implement BPlusTree or LSM-Tree. Later I will implement a BPlusTree storage engine.

All comments are generated by Claude Code. If there are any errors, please point them out.

Updating...

Next one is "Index support".However, it might only be possible after I graduate or find a better job.

How To Run?

cd src
cargo run --bin server

and then open another terminal

cargo run --bin client

Currently supported SQL statements

1. Create Table

CREATE TABLE table_name (
    [ column_name data_type [ column_constraint [...] ] ]
    [, ... ]
   );

   where data_type is:
    - BOOLEAN(BOOL): true | false
    - FLOAT(DOUBLE)
    - INTEGER(INT)
    - STRING(TEXT, VARCHAR)

   where column_constraint is:
   [ NOT NULL | NULL | DEFAULT expr ]

2. Insert Into

INSERT INTO table_name
[ ( column_name [, ...] ) ]
values ( expr [, ...] );

3. Select * From

SELECT [* | col_name | function [ [ AS ] output_name [, ...] ]]
FROM from_item
[WHERE expr]
[GROUP BY col_name]
[HAVING expr]
[ORDER BY col_name [asc | desc] [, ...]]
[LIMIT count]
[OFFSET count]

where function is:

  • count(col_name)
  • min(col_name)
  • max(col_name)
  • sum(col_name)
  • avg(col_name)

where from_item is:

  • table_name
  • table_name join_type table_name [ON predicate]

where join_type is:

  • cross join
  • join
  • left join
  • right join

where on predicate is:

  • column_name = column_name

4. Update

UPDATE table_name
SET column_name = expr [, ...]
[WHERE condition];

where condition is: `column_name = expr`

5. Delete

DELETE FROM table_name
[WHERE condition];

where condition is: `column_name = expr`

6. Show Table

SHOW TABLES
SHOW TABLE `table_name`

7. Transaction

BEGIN;

COMMIT;

ROLLBACK;

About

RusticDB: A humble SQL database built to learn, not to scale.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages