go.temporal.io/server@v1.23.0/common/persistence/nosql/nosqlplugin/cassandra/gocql/query.go (about) 1 // The MIT License 2 // 3 // Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. 4 // 5 // Copyright (c) 2020 Uber Technologies, Inc. 6 // 7 // Permission is hereby granted, free of charge, to any person obtaining a copy 8 // of this software and associated documentation files (the "Software"), to deal 9 // in the Software without restriction, including without limitation the rights 10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 // copies of the Software, and to permit persons to whom the Software is 12 // furnished to do so, subject to the following conditions: 13 // 14 // The above copyright notice and this permission notice shall be included in 15 // all copies or substantial portions of the Software. 16 // 17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 // THE SOFTWARE. 24 25 package gocql 26 27 import ( 28 "context" 29 30 "github.com/gocql/gocql" 31 ) 32 33 var _ Query = (*query)(nil) 34 35 type ( 36 query struct { 37 session *session 38 gocqlQuery *gocql.Query 39 } 40 ) 41 42 func newQuery( 43 session *session, 44 gocqlQuery *gocql.Query, 45 ) *query { 46 return &query{ 47 session: session, 48 gocqlQuery: gocqlQuery, 49 } 50 } 51 52 func (q *query) Exec() (retError error) { 53 defer func() { q.session.handleError(retError) }() 54 55 return q.gocqlQuery.Exec() 56 } 57 58 func (q *query) Scan( 59 dest ...interface{}, 60 ) (retError error) { 61 defer func() { q.session.handleError(retError) }() 62 63 return q.gocqlQuery.Scan(dest...) 64 } 65 66 func (q *query) ScanCAS( 67 dest ...interface{}, 68 ) (_ bool, retError error) { 69 defer func() { q.session.handleError(retError) }() 70 71 return q.gocqlQuery.ScanCAS(dest...) 72 } 73 74 func (q *query) MapScan( 75 m map[string]interface{}, 76 ) (retError error) { 77 defer func() { q.session.handleError(retError) }() 78 79 return q.gocqlQuery.MapScan(m) 80 } 81 82 func (q *query) MapScanCAS( 83 dest map[string]interface{}, 84 ) (_ bool, retError error) { 85 defer func() { q.session.handleError(retError) }() 86 87 return q.gocqlQuery.MapScanCAS(dest) 88 } 89 90 func (q *query) Iter() Iter { 91 iter := q.gocqlQuery.Iter() 92 return newIter(q.session, iter) 93 } 94 95 func (q *query) PageSize(n int) Query { 96 q.gocqlQuery.PageSize(n) 97 return newQuery(q.session, q.gocqlQuery) 98 } 99 100 func (q *query) PageState(state []byte) Query { 101 q.gocqlQuery.PageState(state) 102 return newQuery(q.session, q.gocqlQuery) 103 } 104 105 func (q *query) Consistency(c Consistency) Query { 106 q.gocqlQuery.Consistency(mustConvertConsistency(c)) 107 return newQuery(q.session, q.gocqlQuery) 108 } 109 110 func (q *query) WithTimestamp(timestamp int64) Query { 111 q.gocqlQuery.WithTimestamp(timestamp) 112 return newQuery(q.session, q.gocqlQuery) 113 } 114 115 func (q *query) WithContext(ctx context.Context) Query { 116 q2 := q.gocqlQuery.WithContext(ctx) 117 if q2 == nil { 118 return nil 119 } 120 return newQuery(q.session, q2) 121 } 122 123 func (q *query) Bind(v ...interface{}) Query { 124 q.gocqlQuery.Bind(v...) 125 return newQuery(q.session, q.gocqlQuery) 126 }