feat: added a struct for table

This commit is contained in:
2026-07-21 23:22:15 +05:30
parent 1ec9de4b0b
commit b2a61c66e4
2 changed files with 21 additions and 2 deletions
+2 -1
View File
@@ -16,6 +16,7 @@ func Run() {
inputBuffer := NewInputBuffer() inputBuffer := NewInputBuffer()
statement := NewStatement() statement := NewStatement()
table := NewTable()
for { for {
PrintConsole() PrintConsole()
inputBuffer.ReadConsole() inputBuffer.ReadConsole()
@@ -37,7 +38,7 @@ func Run() {
continue continue
} }
statement.ExecuteStatement() statement.ExecuteStatement(table)
fmt.Println("Executed") fmt.Println("Executed")
} }
+19 -1
View File
@@ -41,10 +41,28 @@ type Statement struct {
row row row row
} }
const (
_pageSize = 4096
maxPages = 100
)
type Table struct {
numOfRows uint
pages [maxPages]any
}
func NewStatement() *Statement { func NewStatement() *Statement {
return &Statement{0, row{0, "", ""}} return &Statement{0, row{0, "", ""}}
} }
func NewTable() *Table {
newTable := Table{numOfRows: 0}
for i := range maxPages {
newTable.pages[i] = nil
}
return &newTable
}
func DoMetaCommands(inputBuffer *InputBuffer) MetaCommandResults { func DoMetaCommands(inputBuffer *InputBuffer) MetaCommandResults {
metacommand := MetaCommandUnrecognised metacommand := MetaCommandUnrecognised
if inputBuffer.Buffer == ".exit" { if inputBuffer.Buffer == ".exit" {
@@ -76,7 +94,7 @@ func (statement *Statement) PrepareStatements(inputBuffer *InputBuffer) PrepareR
return PrepareUnrecognised return PrepareUnrecognised
} }
func (statement *Statement) ExecuteStatement() { func (statement *Statement) ExecuteStatement(table *Table) {
switch statement.stype { switch statement.stype {
case StatementInsert: case StatementInsert:
fmt.Println("This is where the logic of insert statement should go") fmt.Println("This is where the logic of insert statement should go")