query.gno
0.96 Kb ยท 43 lines
1package datastore
2
3import (
4 "gno.land/p/moul/collection"
5)
6
7var defaultQuery = Query{indexName: collection.IDIndex}
8
9// Query contains arguments for querying a storage.
10type Query struct {
11 offset int
12 size int
13 indexName string
14 indexKey string
15}
16
17// Offset returns the position of the first record to return.
18// The minimum offset value is 0.
19func (q Query) Offset() int {
20 return q.offset
21}
22
23// Size returns the maximum number of records a query returns.
24func (q Query) Size() int {
25 return q.size
26}
27
28// IndexName returns the name of the storage index being used for the query.
29func (q Query) IndexName() string {
30 return q.indexName
31}
32
33// IndexKey return the index key value to locate the records.
34// An empty string is returned when all indexed records match the query.
35func (q Query) IndexKey() string {
36 return q.indexKey
37}
38
39// IsEmpty checks if the query is empty.
40// Empty queries return no records.
41func (q Query) IsEmpty() bool {
42 return q.indexName == ""
43}