Package lmdbscan provides a wrapper for lmdb.Cursor to simplify iteration.




    This section is empty.


    This section is empty.


    This section is empty.


    type Scanner

    type Scanner struct {
    	// contains filtered or unexported fields

      Scanner is a low level construct for scanning databases inside a transaction.


        This example demonstrates basic usage of a Scanner to scan a database. It is important to always call scanner.Err() which will returned any unexpected error which interrupted scanner.Scan().


        func New

        func New(txn *lmdb.Txn, dbi lmdb.DBI) *Scanner

          New allocates and intializes a Scanner for dbi within txn. When the Scanner returned by New is no longer needed its Close method must be called.

          func (*Scanner) Close

          func (s *Scanner) Close()

            Close closes the cursor underlying s and clears its ows internal structures. Close does not attempt to terminate the enclosing transaction.

            Scan must not be called after Close.

            func (*Scanner) Cursor

            func (s *Scanner) Cursor() *lmdb.Cursor

              Cursor returns the lmdb.Cursor underlying s. Cursor returns nil if s is closed.

              func (*Scanner) Del

              func (s *Scanner) Del(flags uint) error

                Del will delete the key at the current cursor location.

                Del is deprecated. Instead use s.Cursor().Del(flags).

                func (*Scanner) Err

                func (s *Scanner) Err() error

                  Err returns a non-nil error if and only if the previous call to s.Scan() resulted in an error other than lmdb.ErrNotFound.

                  func (*Scanner) Key

                  func (s *Scanner) Key() []byte

                    Key returns the key read during the last call to Scan.

                    func (*Scanner) Scan

                    func (s *Scanner) Scan() bool

                      Scan gets successive key-value pairs using the underlying cursor. Scan returns false when key-value pairs are exhausted or another error is encountered.

                      func (*Scanner) Set

                      func (s *Scanner) Set(k, v []byte, opset uint) bool

                        Set moves the cursor with s.Cursor().Get(k, v, opset), and sets s.Key(), s.Val(), and s.Err() accordingly. The cursor will not move in the next call to Scan.


                          This example demonstrates scanning a key range in a database. Set is used to move the cursor's starting position to the desired prefix.


                          func (*Scanner) SetNext

                          func (s *Scanner) SetNext(k, v []byte, opset, opnext uint) bool

                            SetNext moves the cursor like s.Set(k, v, opset) for the next call to s.Scan(). Subsequent calls to s.Scan() move the cursor as c.Get(nil, nil, opnext)


                              This example demonstrates scanning all values for a key in a root database with the lmdb.DupSort flag set. SetNext is used instead of Set to configure Cursor the to return ErrNotFound (EOF) after all duplicate keys have been iterated.

                              Example (GetMultiple)

                                This advanced example demonstrates batch scanning of values for duplicate keys in a database with the lmdb.DupFixed and lmdb.DupSort flags set. The outer loop scans unique keys and the inner loop scans duplicate values. The GetMultiple op requires an additional check following its use to determine if no duplicates exist in the database.

                                Example (NextNoDup)

                                  This example demonstrates scanning all values for duplicate keys in a database with the lmdb.DupSort flag set. Two loops are used to iterate over unique keys and their values respectively. The example exploits the return value from SetNext as the termination condition for the first loop.


                                  func (*Scanner) Val

                                  func (s *Scanner) Val() []byte

                                    Val returns the value read during the last call to Scan.

                                    Source Files