forked from willfaught/gockle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
query.go
153 lines (118 loc) · 3.52 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package gockle
import (
"context"
"github.com/gocql/gocql"
"github.com/maraino/go-mock"
)
// Query represents a CQL query.
type Query interface {
// PageSize will tell the iterator to fetch the result in pages of size n.
PageSize(n int) Query
// WithContext will set the context to use during a query, it will be used
// to timeout when waiting for responses from Cassandra.
WithContext(ctx context.Context) Query
// PageState sets the paging state for the query to resume paging from a
// specific point in time. Setting this will disable to query paging for
// this query, and must be used for all subsequent pages.
PageState(state []byte) Query
// Exec executes the query without returning any rows.
Exec() error
// Iter executes the query and returns an iterator capable of iterating
// over all results.
Iter() Iterator
// MapScan executes the query, copies the columns of the first selected row
// into the map pointed at by m and discards the rest. If no rows
// were selected, ErrNotFound is returned.
MapScan(m map[string]interface{}) error
// Scan executes the query, copies the columns of the first selected row
// into the values pointed at by dest and discards the rest. If no rows
// were selected, ErrNotFound is returned.
Scan(dest ...interface{}) error
// Release releases a query back into a pool of queries. Released queries
// cannot be reused.
Release()
// GetConsistency returns the currently configured consistency level for
// the query.
GetConsistency() gocql.Consistency
// SetConsistency sets the consistency level for this query.
SetConsistency(c gocql.Consistency)
}
var (
_ Query = QueryMock{}
_ Query = query{}
)
// QueryMock is a mock Query.
type QueryMock struct {
mock.Mock
}
// PageSize implements Query.
func (m QueryMock) PageSize(n int) Query {
return m.Called(n).Get(0).(Query)
}
// WithContext implements Query.
func (m QueryMock) WithContext(ctx context.Context) Query {
return m.Called(ctx).Get(0).(Query)
}
// PageState implements Query.
func (m QueryMock) PageState(state []byte) Query {
return m.Called(state).Get(0).(Query)
}
// Exec implements Query.
func (m QueryMock) Exec() error {
return m.Called().Error(0)
}
// Iter implements Query.
func (m QueryMock) Iter() Iterator {
return m.Called().Get(0).(Iterator)
}
// MapScan implements Query.
func (m QueryMock) MapScan(mm map[string]interface{}) error {
return m.Called(mm).Error(0)
}
// Scan implements Query.
func (m QueryMock) Scan(dest ...interface{}) error {
return m.Called(dest).Error(0)
}
// Release implements Query.
func (m QueryMock) Release() {
m.Called()
}
func (m QueryMock) GetConsistency() gocql.Consistency {
return m.Called().Get(0).(gocql.Consistency)
}
func (m QueryMock) SetConsistency(c gocql.Consistency) {
m.Called(c)
}
type query struct {
q *gocql.Query
}
func (q query) PageSize(n int) Query {
return &query{q: q.q.PageSize(n)}
}
func (q query) WithContext(ctx context.Context) Query {
return &query{q: q.q.WithContext(ctx)}
}
func (q query) PageState(state []byte) Query {
return &query{q: q.q.PageState(state)}
}
func (q query) Exec() error {
return q.q.Exec()
}
func (q query) Iter() Iterator {
return &iterator{i: q.q.Iter()}
}
func (q query) MapScan(m map[string]interface{}) error {
return q.q.MapScan(m)
}
func (q query) Scan(dest ...interface{}) error {
return q.q.Scan(dest...)
}
func (q query) Release() {
q.q.Release()
}
func (q query) GetConsistency() gocql.Consistency {
return q.q.GetConsistency()
}
func (q query) SetConsistency(c gocql.Consistency) {
q.q.SetConsistency(c)
}