github.com/go-kivik/kivik/v4@v4.3.2/int/mock/rows.go (about) 1 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 2 // use this file except in compliance with the License. You may obtain a copy of 3 // the License at 4 // 5 // http://www.apache.org/licenses/LICENSE-2.0 6 // 7 // Unless required by applicable law or agreed to in writing, software 8 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10 // License for the specific language governing permissions and limitations under 11 // the License. 12 13 package mock 14 15 import ( 16 "io" 17 18 "github.com/go-kivik/kivik/v4/driver" 19 ) 20 21 // Rows mocks driver.Rows 22 type Rows struct { 23 // ID identifies a specific Rows instance. 24 ID string 25 CloseFunc func() error 26 NextFunc func(*driver.Row) error 27 OffsetFunc func() int64 28 TotalRowsFunc func() int64 29 UpdateSeqFunc func() string 30 } 31 32 var _ driver.Rows = &Rows{} 33 34 // Close calls r.CloseFunc 35 func (r *Rows) Close() error { 36 if r == nil || r.CloseFunc == nil { 37 return nil 38 } 39 return r.CloseFunc() 40 } 41 42 // Next calls r.NextFunc 43 func (r *Rows) Next(row *driver.Row) error { 44 if r == nil || r.NextFunc == nil { 45 return io.EOF 46 } 47 return r.NextFunc(row) 48 } 49 50 // Offset calls r.OffsetFunc 51 func (r *Rows) Offset() int64 { 52 if r == nil || r.OffsetFunc == nil { 53 return 0 54 } 55 return r.OffsetFunc() 56 } 57 58 // TotalRows calls r.TotalRowsFunc 59 func (r *Rows) TotalRows() int64 { 60 if r == nil || r.TotalRowsFunc == nil { 61 return 0 62 } 63 return r.TotalRowsFunc() 64 } 65 66 // UpdateSeq calls r.UpdateSeqFunc 67 func (r *Rows) UpdateSeq() string { 68 if r == nil || r.UpdateSeqFunc == nil { 69 return "" 70 } 71 return r.UpdateSeqFunc() 72 } 73 74 // RowsWarner wraps driver.RowsWarner 75 type RowsWarner struct { 76 *Rows 77 WarningFunc func() string 78 } 79 80 var _ driver.RowsWarner = &RowsWarner{} 81 82 // Warning calls r.WarningFunc 83 func (r *RowsWarner) Warning() string { 84 return r.WarningFunc() 85 } 86 87 // Bookmarker wraps driver.Bookmarker 88 type Bookmarker struct { 89 *Rows 90 BookmarkFunc func() string 91 } 92 93 var _ driver.Bookmarker = &Bookmarker{} 94 95 // Bookmark calls r.BookmarkFunc 96 func (r *Bookmarker) Bookmark() string { 97 return r.BookmarkFunc() 98 }