-
Notifications
You must be signed in to change notification settings - Fork 72
/
backend.go
91 lines (74 loc) · 1.65 KB
/
backend.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
82
83
84
85
86
87
88
89
90
91
package gosql
import "errors"
type ColumnType uint
const (
TextType ColumnType = iota
IntType
BoolType
)
func (c ColumnType) String() string {
switch c {
case TextType:
return "TextType"
case IntType:
return "IntType"
case BoolType:
return "BoolType"
default:
return "Error"
}
}
type Cell interface {
AsText() *string
AsInt() *int32
AsBool() *bool
}
type Results struct {
Columns []ResultColumn
Rows [][]Cell
}
type ResultColumn struct {
Type ColumnType
Name string
NotNull bool
}
type Index struct {
Name string
Exp string
Type string
Unique bool
PrimaryKey bool
}
type TableMetadata struct {
Name string
Columns []ResultColumn
Indexes []Index
}
type Backend interface {
CreateTable(*CreateTableStatement) error
DropTable(*DropTableStatement) error
CreateIndex(*CreateIndexStatement) error
Insert(*InsertStatement) error
Select(*SelectStatement) (*Results, error)
GetTables() []TableMetadata
}
// Useful to embed when prototyping new backends
type EmptyBackend struct{}
func (eb EmptyBackend) CreateTable(_ *CreateTableStatement) error {
return errors.New("Create not supported")
}
func (eb EmptyBackend) DropTable(_ *DropTableStatement) error {
return errors.New("Drop not supported")
}
func (eb EmptyBackend) CreateIndex(_ *CreateIndexStatement) error {
return errors.New("Create index not supported")
}
func (eb EmptyBackend) Insert(_ *InsertStatement) error {
return errors.New("Insert not supported")
}
func (eb EmptyBackend) Select(_ *SelectStatement) (*Results, error) {
return nil, errors.New("Select not supported")
}
func (eb EmptyBackend) GetTables() []TableMetadata {
return nil
}