-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
74 lines (61 loc) · 1.54 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
"github.com/1x-eng/yadab/memory"
"github.com/1x-eng/yadab/parser"
"github.com/1x-eng/yadab/util"
)
func main() {
mb := memory.NewMemoryBackend()
reader := bufio.NewReader(os.Stdin)
fmt.Println(" Y Y A DDDD A BBBBB ")
fmt.Println(" Y Y A A D D A A B B ")
fmt.Println(" Y AAAAAA D D AAAAAA BBBB ")
fmt.Println(" Y A A D D A A B B ")
fmt.Println(" Y A A DDDD A A BBBBB ")
fmt.Println("")
fmt.Println(" Welcome! This is `yadab` - yet another (relational) database ;)")
for {
fmt.Print("# ")
text, err := reader.ReadString('\n')
if err != nil {
log.Fatal(err)
}
text = strings.Replace(text, "\n", "", -1)
ast, err := parser.Parse(text)
if err != nil {
log.Fatal(err)
}
for _, stmt := range ast.Statements {
switch stmt.Kind {
case util.CreateTableKind:
err = mb.CreateTable(stmt.CreateTableStatement)
if err != nil {
log.Fatal(err)
}
fmt.Println("ok")
case util.InsertKind:
err = mb.Insert(stmt.InsertStatement)
if err != nil {
log.Fatal(err)
}
fmt.Println("ok")
case util.SelectKind:
results, err := mb.Select(stmt.SelectStatement)
if err != nil {
log.Fatal(err)
}
util.PrintTableHeader(results.Columns)
util.PrintTableSeparator()
for _, result := range results.Rows {
util.PrintTableRow(result, results.Columns)
}
fmt.Println("ok")
}
}
}
}