forked from marianogappa/sqlparser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.go
81 lines (73 loc) · 1.64 KB
/
query.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
75
76
77
78
79
80
81
package query
// Query represents a parsed query
type Query struct {
Type Type
TableName string
Conditions []Condition
Updates map[string]string
Inserts [][]string
Fields []string // Used for SELECT (i.e. SELECTed field names) and INSERT (INSERTEDed field names)
}
// Type is the type of SQL query, e.g. SELECT/UPDATE
type Type int
const (
// UnknownType is the zero value for a Type
UnknownType Type = iota
// Select represents a SELECT query
Select
// Update represents an UPDATE query
Update
// Insert represents an INSERT query
Insert
// Delete represents a DELETE query
Delete
)
// TypeString is a string slice with the names of all types in order
var TypeString = []string{
"UnknownType",
"Select",
"Update",
"Insert",
"Delete",
}
// Operator is between operands in a condition
type Operator int
const (
// UnknownOperator is the zero value for an Operator
UnknownOperator Operator = iota
// Eq -> "="
Eq
// Ne -> "!="
Ne
// Gt -> ">"
Gt
// Lt -> "<"
Lt
// Gte -> ">="
Gte
// Lte -> "<="
Lte
)
// OperatorString is a string slice with the names of all operators in order
var OperatorString = []string{
"UnknownOperator",
"Eq",
"Ne",
"Gt",
"Lt",
"Gte",
"Lte",
}
// Condition is a single boolean condition in a WHERE clause
type Condition struct {
// Operand1 is the left hand side operand
Operand1 string
// Operand1IsField determines if Operand1 is a literal or a field name
Operand1IsField bool
// Operator is e.g. "=", ">"
Operator Operator
// Operand1 is the right hand side operand
Operand2 string
// Operand2IsField determines if Operand2 is a literal or a field name
Operand2IsField bool
}