-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparser.go
More file actions
69 lines (57 loc) · 1.34 KB
/
parser.go
File metadata and controls
69 lines (57 loc) · 1.34 KB
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
package simpleSqlParser
import "fmt"
type SelectStatement struct {
Keyspace string
Columns []string
TableName string
AllColumns bool
WhereColumns []string
WhereValues []string
Limit int
Operators []string
}
type DeleteStatement struct {
Keyspace string
TableName string
WhereColumn string
WhereValue string
Operator string
}
type InsertStatement struct {
Keyspace string
TableName string
Columns []string
Values []string
}
type CreateStatement struct {
Keyspace string
TableName string
Columns []string
PartitioningKey string
}
type DropStatement struct {
Keyspace string
TableName string
}
type sType int
const (
Select sType = iota
Insert
Create
)
func (s *SQL) captureValues(v string) {
s.InsertStatement.Values = append(s.InsertStatement.Values, v)
}
func (s *SQL) validateInsert() {
s.sType = Insert
if len(s.InsertStatement.Columns) < 1 {
//We are good
} else if len(s.InsertStatement.Columns) != len(s.InsertStatement.Values) {
s.InsertStatement = InsertStatement{}
fmt.Errorf(fmt.Sprintf("Columns and Values do not match. %d columns provided for %d values ", len(s.InsertStatement.Columns), len(s.InsertStatement.Values)))
}
}
func (s *SQL) setPartitionKey(v string) {
s.sType = Create
s.CreateStatement.PartitioningKey = s.CreateStatement.Columns[0]
}