summaryrefslogtreecommitdiff
path: root/vendor/github.com/authzed/spicedb/pkg/datastore/counters.go
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-07-22 17:35:49 -0600
committermo khan <mo@mokhan.ca>2025-07-22 17:35:49 -0600
commit20ef0d92694465ac86b550df139e8366a0a2b4fa (patch)
tree3f14589e1ce6eb9306a3af31c3a1f9e1af5ed637 /vendor/github.com/authzed/spicedb/pkg/datastore/counters.go
parent44e0d272c040cdc53a98b9f1dc58ae7da67752e6 (diff)
feat: connect to spicedb
Diffstat (limited to 'vendor/github.com/authzed/spicedb/pkg/datastore/counters.go')
-rw-r--r--vendor/github.com/authzed/spicedb/pkg/datastore/counters.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/vendor/github.com/authzed/spicedb/pkg/datastore/counters.go b/vendor/github.com/authzed/spicedb/pkg/datastore/counters.go
new file mode 100644
index 0000000..9b90ea4
--- /dev/null
+++ b/vendor/github.com/authzed/spicedb/pkg/datastore/counters.go
@@ -0,0 +1,47 @@
+package datastore
+
+import (
+ "context"
+
+ core "github.com/authzed/spicedb/pkg/proto/core/v1"
+)
+
+// RelationshipCounter is a struct that represents a count of relationships that match a filter.
+type RelationshipCounter struct {
+ // Name is the name of the counter.
+ Name string
+
+ // Filter is the filter that the count represents.
+ Filter *core.RelationshipFilter
+
+ // Count is the count of relationships that match the filter.
+ Count int
+
+ // ComputedAtRevision is the revision at which the count was last computed. If NoRevision,
+ // the count has never been computed.
+ ComputedAtRevision Revision
+}
+
+// CounterRegisterer is an interface for registering and unregistering counts.
+type CounterRegisterer interface {
+ // RegisterCounter registers a count with the provided filter. If the counter already exists,
+ // returns an error.
+ RegisterCounter(ctx context.Context, name string, filter *core.RelationshipFilter) error
+
+ // UnregisterCounter unregisters a counter. If the counter did not exist, returns an error.
+ UnregisterCounter(ctx context.Context, name string) error
+
+ // StoreCounterValue stores a count for the counter with the given name, at the given revision.
+ // If the counter does not exist, returns an error.
+ StoreCounterValue(ctx context.Context, name string, value int, computedAtRevision Revision) error
+}
+
+// CounterReader is an interface for reading counts.
+type CounterReader interface {
+ // CountRelationships returns the count of relationships that match the provided counter. If the counter is not
+ // registered, returns an error.
+ CountRelationships(ctx context.Context, name string) (int, error)
+
+ // LookupCounters returns all registered counters.
+ LookupCounters(ctx context.Context) ([]RelationshipCounter, error)
+}