...

Source file src/github.com/go-kivik/kivik/v4/x/proxydb/rows.go

Documentation: github.com/go-kivik/kivik/v4/x/proxydb

     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 proxydb
    14  
    15  import (
    16  	"bytes"
    17  	"encoding/json"
    18  
    19  	"github.com/go-kivik/kivik/v4"
    20  	"github.com/go-kivik/kivik/v4/driver"
    21  )
    22  
    23  type rows struct {
    24  	*kivik.ResultSet
    25  }
    26  
    27  var _ driver.Rows = &rows{}
    28  
    29  func (r *rows) Next(row *driver.Row) error {
    30  	if !r.ResultSet.Next() {
    31  		return r.ResultSet.Err()
    32  	}
    33  	var value json.RawMessage
    34  	if err := r.ResultSet.ScanValue(&value); err != nil {
    35  		return err
    36  	}
    37  	var doc json.RawMessage
    38  	if err := r.ResultSet.ScanDoc(&doc); err != nil {
    39  		return err
    40  	}
    41  	var err error
    42  	row.ID, err = r.ResultSet.ID()
    43  	if err != nil {
    44  		return err
    45  	}
    46  	key, err := r.ResultSet.Key()
    47  	if err != nil {
    48  		return err
    49  	}
    50  	row.Key = json.RawMessage(key)
    51  	row.Value = bytes.NewReader(value)
    52  	row.Doc = bytes.NewReader(doc)
    53  	return nil
    54  }
    55  
    56  func (r *rows) Close() error {
    57  	return r.ResultSet.Close()
    58  }
    59  
    60  func (r *rows) Offset() int64 {
    61  	md, err := r.ResultSet.Metadata()
    62  	if err != nil {
    63  		return 0
    64  	}
    65  	return md.Offset
    66  }
    67  
    68  func (r *rows) TotalRows() int64 {
    69  	md, err := r.ResultSet.Metadata()
    70  	if err != nil {
    71  		return 0
    72  	}
    73  	return md.TotalRows
    74  }
    75  
    76  func (r *rows) UpdateSeq() string {
    77  	md, err := r.ResultSet.Metadata()
    78  	if err != nil {
    79  		return ""
    80  	}
    81  	return md.UpdateSeq
    82  }
    83  

View as plain text