PrefixScanEntries iterates over a key prefix at given bucket, prefix and limitNum. If reg is set a regular expression will be used to filter the found entries. LimitNum will limit the number of entries return. It will return keys and/or values based on the includeKeys and includeValues flags.
(bucket string, prefix []byte, reg string, offsetNum int, limitNum int, includeKeys, includeValues bool)
| 350 | // found entries. LimitNum will limit the number of entries return. It will |
| 351 | // return keys and/or values based on the includeKeys and includeValues flags. |
| 352 | func (tx *Tx) PrefixScanEntries(bucket string, prefix []byte, reg string, offsetNum int, limitNum int, includeKeys, includeValues bool) (keys, values [][]byte, err error) { |
| 353 | // This function is a bit awkward but that is to maintain backwards |
| 354 | // compatibility while enabling the caller to pick and choose which |
| 355 | // variation to call. |
| 356 | if err := tx.checkTxIsClosed(); err != nil { |
| 357 | return nil, nil, err |
| 358 | } |
| 359 | b, err := tx.db.bucketMgr.GetBucket(DataStructureBTree, bucket) |
| 360 | if err != nil { |
| 361 | return nil, nil, err |
| 362 | } |
| 363 | bucketId := b.Id |
| 364 | |
| 365 | xerr := func() error { |
| 366 | // Return expected error types based on Scan/SearchScan. |
| 367 | if reg == "" { |
| 368 | return ErrPrefixScan |
| 369 | } |
| 370 | return ErrPrefixSearchScan |
| 371 | } |
| 372 | |
| 373 | if idx, ok := tx.db.Index.BTree.exist(bucketId); ok { |
| 374 | var records []*core.Record |
| 375 | if reg == "" { |
| 376 | records = idx.PrefixScan(prefix, offsetNum, limitNum) |
| 377 | } else { |
| 378 | records = idx.PrefixSearchScan(prefix, reg, offsetNum, limitNum) |
| 379 | } |
| 380 | keys, values, err = tx.getHintIdxDataItemsWrapper(records, limitNum, bucketId, includeKeys, includeValues) |
| 381 | if err != nil { |
| 382 | return nil, nil, xerr() |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | if includeKeys && len(keys) == 0 { |
| 387 | return nil, nil, xerr() |
| 388 | } |
| 389 | if includeValues && len(values) == 0 { |
| 390 | return nil, nil, xerr() |
| 391 | } |
| 392 | return |
| 393 | } |
| 394 | |
| 395 | // PrefixScan iterates over a key prefix at given bucket, prefix and limitNum. |
| 396 | // LimitNum will limit the number of entries return. |