Skip to content

Commit

Permalink
docs: update README and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkinben committed May 5, 2022
1 parent 676aca7 commit 9d57686
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 68 deletions.
67 changes: 5 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,17 @@ A tiny and dummy database built by myself.



## Introdution
## Introduction

This project is inspired by sqlite, has a similar architecture with sqlite (but simpler).

<img src = "./docs/img/sqlite.png" style = "width: 40%" />

- `tinydb` is the simplest prototype of database, it only contains **ONE** table (see `table_t` and `row_t` in source file `types.h`), whose schema is `id(uint32_t), username(string), email(string)` .
- `id(int)` is the primary key of our table, we will implement index via B+Tree.
- `sqlparser-main.c` - The entry of tinydb. In this program, I implement an tiny SQL Parser based on Flex & Bison, thus the SQL statements in this program are mostly like sqlite or MySQL. And it supports `where` conditions.


There are two version of `tinydb`:

- `main.c` - In this program, I parse the SQL statements by spliting strings, thus the SQL statements are incomplete. And it does **NOT** support `where` keyword.
- `main2.c` - In this program, I implement an tiny SQL Parser based on Flex & Bison, thus the SQL statements in this program are mostly like sqlite or MySQL. And it supports `where` conditions.

For both of them, they have the same format of database file.



## Build `main.c`

This project has only one `.c` file. And you can build it by:

```text
make dummy
./tinydb mydb.db
```

And it will enter our REPL (Read, Evaluate, Print, Loop) program:

```text
tinydb > insert 1 1 1
Executed.
tinydb > insert 2 2 2
Executed.
tinydb > insert 3 3 3
Executed.
tinydb > update 1 a a
Executed.
tinydb > delete 3
Executed.
tinydb > select
(1, a, a)
(2, 2, 2)
total 2 rows
Executed.
tinydb >
```

From so far, `tinydb` supports these sql statement:

- `insert`
- `select`
- `delete`
- `update`
- `commit`
- `rollback`

And it also support some meta commands (for debugging):

- `.help`
- `.exit`
- `.constants`
- `.btree`



## Build `main2.c`
## Build `sqlparser-main.c`

```bash
make build
Expand All @@ -92,7 +35,7 @@ In this program, I implement a SQL Parser. It will support SQL statements like:
- `COMMIT;`
- `ROLLBACK;`

For the above keywords, we can also use lower cases: `select, insert, delete, update, ...`
For the above keywords, they can be lower cases: `select, insert, delete, update, ...`

Please note that there is a `';'` after each SQL statement.

Expand Down Expand Up @@ -138,7 +81,7 @@ Running this testing script, will fill the database file `mydb.db` with dummy da



## Recommend Readings
## Further Reading

- [1] [SQLite Database System: Design and Implementation](https://play.google.com/store/books/details/SQLite_Database_System_Design_and_Implementation_F?id=9Z6IQQnX1JEC&gl=US)
- [2] [Architecture of SQLite](https://www.sqlite.org/arch.html)
Expand Down
16 changes: 11 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/* In this main.c, I implement the REPL by splitting the string (e.g. strtok, strcmp).
* It only support SQL statements as following:
* 1) insert 1 1 1 (Insert one row into the table.)
* 2) update 1 a a (Update one row where id = 1.)
* 3) delete 3 (Delete one row where id = 3.)
* 4) select (Print all rows in table.)
* 5) commit (Commit all dirty pages in memory.)
* 6) rollback (Rollback ONE operation.)
* This file is deprecated, since we have more advanced SQL parser, see sqlparser-main.c
*/
#include "common.h"
#include "dummyparser.h"
#include "transaction.h"
Expand Down Expand Up @@ -29,11 +39,7 @@ int main(int argc, char *argv[])
}
}

statement_t statement = {
.conditions = NULL,
.schemas = NULL,
.table_name = filename
};
statement_t statement = {.conditions = NULL, .schemas = NULL, .table_name = filename};
switch (parse_statement(input_buffer, &statement))
{
case PARSE_SUCCESS:
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ DBKERNEL=$(PROJECT)/db-kernel
INCLUDE=-I$(PROJECT) -I$(SQLPARSER) -I$(SQLVM) -I$(LIBS) -I$(DBKERNEL)

build: sqlparser
$(CC) $(INCLUDE) sqlparser.tab.c lex.yy.c main2.c -o tinydb
$(CC) $(INCLUDE) sqlparser.tab.c lex.yy.c sqlparser-main.c -o tinydb

clean:
rm *.db tinydb lex.yy.c *.tab.c *.tab.h
Expand Down
File renamed without changes.

0 comments on commit 9d57686

Please sign in to comment.