github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/datastore/options/options.go (about)

     1  package options
     2  
     3  import (
     4  	core "github.com/authzed/spicedb/pkg/proto/core/v1"
     5  )
     6  
     7  //go:generate go run github.com/ecordell/optgen -output zz_generated.query_options.go . QueryOptions ReverseQueryOptions RWTOptions
     8  //go:generate go run github.com/ecordell/optgen -output zz_generated.delete_options.go . DeleteOptions
     9  
    10  // SortOrder is an enum which represents the order in which the caller would like
    11  // the data returned.
    12  type SortOrder int8
    13  
    14  const (
    15  	// Unsorted lets the underlying datastore choose the order, or no order at all
    16  	Unsorted SortOrder = iota
    17  
    18  	// ByResource sorts the relationships by the resource component first
    19  	ByResource
    20  
    21  	// BySubject sorts the relationships by the subject component first. Note that
    22  	// BySubject might be quite a bit slower than ByResource, as relationships are
    23  	// indexed by resource.
    24  	BySubject
    25  )
    26  
    27  type Cursor *core.RelationTuple
    28  
    29  // QueryOptions are the options that can affect the results of a normal forward query.
    30  type QueryOptions struct {
    31  	Limit *uint64   `debugmap:"visible"`
    32  	Sort  SortOrder `debugmap:"visible"`
    33  	After Cursor    `debugmap:"visible"`
    34  }
    35  
    36  // ReverseQueryOptions are the options that can affect the results of a reverse query.
    37  type ReverseQueryOptions struct {
    38  	ResRelation *ResourceRelation `debugmap:"visible"`
    39  
    40  	LimitForReverse *uint64   `debugmap:"visible"`
    41  	SortForReverse  SortOrder `debugmap:"visible"`
    42  	AfterForReverse Cursor    `debugmap:"visible"`
    43  }
    44  
    45  // ResourceRelation combines a resource object type and relation.
    46  type ResourceRelation struct {
    47  	Namespace string
    48  	Relation  string
    49  }
    50  
    51  // RWTOptions are options that can affect the way a read-write transaction is
    52  // executed.
    53  type RWTOptions struct {
    54  	DisableRetries bool `debugmap:"visible"`
    55  }
    56  
    57  // DeleteOptions are the options that can affect the results of a delete relationships
    58  // operation.
    59  type DeleteOptions struct {
    60  	DeleteLimit *uint64 `debugmap:"visible"`
    61  }
    62  
    63  var (
    64  	one = uint64(1)
    65  
    66  	// LimitOne is a constant *uint64 that can be used with WithLimit requests.
    67  	LimitOne = &one
    68  )