remykarem / sm0l-db

Database for learning purposes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sm0ldb

Heap-file based database for learning purposes.

Currently implemented a low-level direct page manipulation:

Create new page

sm0ldb> restart

---
Page:
00000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000010: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000020: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000030: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000040: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000050: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000060: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000070: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000080: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000090: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000a0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000f0: 0000 0000 0000 0000 0000 0000 0000 0001  ................
                                           |  | |
                                           |  | is there space?
                                           |  |  
                                           |  next order
                                           |
                                           total no. of records

Insert records

sm0ldb> insert sleeping
sm0ldb> insert swimming
sm0ldb> insert running
sm0ldb> insert jogging

---
Page:
00000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000010: 736c 6565 7069 6e67 7377 696d 6d69 6e67  sleepingswimming
00000020: 7275 6e6e 696e 6700 6a6f 6767 696e 6700  running.jogging.
00000030: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000040: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000050: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000060: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000070: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000080: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000090: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000a0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000e0: 0000 0000 0000 0000 0428 0320 0218 0110  .........(. ....
000000f0: 0000 0000 0000 0000 0000 0000 0005 0401  ................
                                           |  | |
                                           |  | is there space?
                                           |  |  
                                           |  next order
                                           |
                                           total no. of records

Delete record ID

sm0ldb> delete 3 

---
Page:
00000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000010: 736c 6565 7069 6e67 7377 696d 6d69 6e67  sleepingswimming
00000020: 0000 0000 0000 0000 6a6f 6767 696e 6700  ........jogging.
00000030: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000040: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000050: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000060: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000070: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000080: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000090: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000a0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000e0: 0000 0000 0000 0000 0428 0000 0218 0110  .........(......
000000f0: 0000 0000 0000 0000 0000 0000 0004 0201  ................
                                           |  | |
                                           |  | is there space?
                                           |  |  
                                           |  next order
                                           |
                                           total no. of records

Read record ID

sm0ldb> read 4
jogging

---
Page:
00000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000010: 736c 6565 7069 6e67 7377 696d 6d69 6e67  sleepingswimming
00000020: 0000 0000 0000 0000 6a6f 6767 696e 6700  ........jogging.
00000030: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000040: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000050: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000060: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000070: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000080: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000090: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000a0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000000e0: 0000 0000 0000 0000 0428 0000 0218 0110  .........(......
000000f0: 0000 0000 0000 0000 0000 0000 0004 0201  ................
                                           |  | |
                                           |  | is there space?
                                           |  |  
                                           |  next order
                                           |
                                           total no. of records

Future improvements when I have the energy:

  • Introduce index
  • Persist catalogs
  • Introduce buffer manager
  • Introduce page directory
  • Create new file if not enough space

About

Database for learning purposes


Languages

Language:Rust 100.0%