5
5
package table
6
6
7
7
import (
8
+ "context"
9
+
8
10
"github.com/scylladb/gocqlx/v2"
9
11
"github.com/scylladb/gocqlx/v2/qb"
10
12
)
@@ -95,6 +97,11 @@ func (t *Table) GetQuery(session gocqlx.Session, columns ...string) *gocqlx.Quer
95
97
return session .Query (t .Get (columns ... ))
96
98
}
97
99
100
+ // GetQueryContext returns query wrapped with context which gets by partition key.
101
+ func (t * Table ) GetQueryContext (ctx context.Context , session gocqlx.Session , columns ... string ) * gocqlx.Queryx {
102
+ return t .GetQuery (session , columns ... ).WithContext (ctx )
103
+ }
104
+
98
105
// Select returns select by partition key statement.
99
106
func (t * Table ) Select (columns ... string ) (stmt string , names []string ) {
100
107
if len (columns ) == 0 {
@@ -112,6 +119,11 @@ func (t *Table) SelectQuery(session gocqlx.Session, columns ...string) *gocqlx.Q
112
119
return session .Query (t .Select (columns ... ))
113
120
}
114
121
122
+ // SelectQueryContext returns query wrapped with context which selects by partition key statement.
123
+ func (t * Table ) SelectQueryContext (ctx context.Context , session gocqlx.Session , columns ... string ) * gocqlx.Queryx {
124
+ return t .SelectQuery (session , columns ... ).WithContext (ctx )
125
+ }
126
+
115
127
// SelectBuilder returns a builder initialised to select by partition key
116
128
// statement.
117
129
func (t * Table ) SelectBuilder (columns ... string ) * qb.SelectBuilder {
@@ -128,6 +140,11 @@ func (t *Table) InsertQuery(session gocqlx.Session) *gocqlx.Queryx {
128
140
return session .Query (t .Insert ())
129
141
}
130
142
143
+ // InsertQueryContext returns query wrapped with context which inserts all columns.
144
+ func (t * Table ) InsertQueryContext (ctx context.Context , session gocqlx.Session ) * gocqlx.Queryx {
145
+ return t .InsertQuery (session ).WithContext (ctx )
146
+ }
147
+
131
148
// Update returns update by primary key statement.
132
149
func (t * Table ) Update (columns ... string ) (stmt string , names []string ) {
133
150
return t .UpdateBuilder (columns ... ).ToCql ()
@@ -138,6 +155,11 @@ func (t *Table) UpdateQuery(session gocqlx.Session, columns ...string) *gocqlx.Q
138
155
return session .Query (t .Update (columns ... ))
139
156
}
140
157
158
+ // UpdateQueryContext returns query wrapped with context which updates by primary key.
159
+ func (t * Table ) UpdateQueryContext (ctx context.Context , session gocqlx.Session , columns ... string ) * gocqlx.Queryx {
160
+ return t .UpdateQuery (session , columns ... ).WithContext (ctx )
161
+ }
162
+
141
163
// UpdateBuilder returns a builder initialised to update by primary key statement.
142
164
func (t * Table ) UpdateBuilder (columns ... string ) * qb.UpdateBuilder {
143
165
return qb .Update (t .metadata .Name ).Set (columns ... ).Where (t .primaryKeyCmp ... )
@@ -153,6 +175,11 @@ func (t *Table) DeleteQuery(session gocqlx.Session, columns ...string) *gocqlx.Q
153
175
return session .Query (t .Delete (columns ... ))
154
176
}
155
177
178
+ // DeleteQueryContext returns query wrapped with context which delete by primary key.
179
+ func (t * Table ) DeleteQueryContext (ctx context.Context , session gocqlx.Session , columns ... string ) * gocqlx.Queryx {
180
+ return t .DeleteQuery (session , columns ... ).WithContext (ctx )
181
+ }
182
+
156
183
// DeleteBuilder returns a builder initialised to delete by primary key statement.
157
184
func (t * Table ) DeleteBuilder (columns ... string ) * qb.DeleteBuilder {
158
185
return qb .Delete (t .metadata .Name ).Columns (columns ... ).Where (t .primaryKeyCmp ... )
0 commit comments