-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataquery.go
81 lines (67 loc) · 1.67 KB
/
dataquery.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 goquery
import (
"errors"
"fmt"
"reflect"
)
const selectkey = "select"
//const updatekey = "update"
//const insertkey = "insert"
type RowFunction func(r Rows) error
type Rows interface {
Columns() ([]string, error)
ColumnTypes() ([]reflect.Type, error)
Next() bool
Scan(dest ...interface{}) error
ScanStruct(dest interface{}) error
Close() error
}
type DataSet interface {
Entity() string
FieldSlice() interface{} //@depricated. Will be removed in the next version...maybe
Fields() interface{} //@depricated. Will be removed in the next version...maybe
Commands() map[string]string
PutCommand(key string, stmt string)
}
type Statements map[string]string
func (s Statements) Get(key string) (string, error) {
if val, ok := s[key]; ok {
return val, nil
}
return "", errors.New("Invalid statement")
}
func (s Statements) GetOrPanic(key string) string {
if val, ok := s[key]; ok {
return val
}
panic(errors.New("Invalid statement"))
}
type TableDataSet struct {
Name string
Schema string //optional
Statements Statements
TableFields any
}
func (t *TableDataSet) FieldSlice() interface{} {
typ := reflect.TypeOf(t.TableFields)
slice := reflect.New(reflect.SliceOf(typ))
return slice.Interface()
}
func (t *TableDataSet) Fields() interface{} {
return t.TableFields
}
func (t *TableDataSet) Entity() string {
if t.Schema != "" {
return fmt.Sprintf("%s.%s", t.Schema, t.Name)
}
return t.Name
}
func (t *TableDataSet) Commands() map[string]string {
return t.Statements
}
func (t *TableDataSet) PutCommand(key string, stmt string) {
if t.Statements == nil {
t.Statements = make(map[string]string)
}
t.Statements[selectkey] = stmt
}