store

package
v1.27.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDuplicateGrant = errors.New("duplicate (subject, object, kind) in the batch")

ErrDuplicateGrant means a batch held two grants with the same (Subject, Object, Kind). The partial unique index allows one DIRECT role per grant, so the upsert touches a row twice and the DB rejects it; the handler maps this to InvalidArgument.

View Source
var ErrNoObjects = errors.New("store: read requires at least one object")

ErrNoObjects means a read was requested without any object to scope it to.

Functions

func AllObjectsGranted added in v1.18.0

func AllObjectsGranted(ctx context.Context, db storage.DBTX, subject uuid.UUID, objects []uuid.UUID, role uuid.UUID) (bool, error)

Types

type Cursor added in v1.27.0

type Cursor struct {
	Subject uuid.UUID
	Object  uuid.UUID
	Kind    Kind
	Role    uuid.UUID
}

Cursor is the keyset position of the last row returned by a scan.

type Grant

type Grant struct {
	Subject uuid.UUID
	Object  uuid.UUID
	Kind    Kind
	Role    uuid.UUID
}

type Kind

type Kind int32

Kind mirrors relationshipspb.Kind but keeps this package free of a proto dependency; the handler maps the proto enum onto it.

type ReadQuery added in v1.16.0

type ReadQuery struct {
	Subject uuid.UUID
	Objects []uuid.UUID
	Kinds   []Kind
}

type Relationship

type Relationship struct {
	Subject uuid.UUID
	Object  uuid.UUID
	Kind    Kind
	// EdgeType is the stored edge class (1=DIRECT). This API only writes DIRECT
	// rows; it is mapped through so the struct mirrors the row for future readers.
	EdgeType  int32
	Role      uuid.UUID
	CreatedAt time.Time
}

func BatchUpsert added in v1.14.0

func BatchUpsert(ctx context.Context, tx storage.Transaction, grants []Grant) ([]Relationship, error)

BatchUpsert writes the grants in statements of at most maxBatchSize rows and returns the stored rows in the same order as grants. The write stays atomic across chunks: BatchUpsert takes the transaction it runs in, and on any error the caller rolls back, so the rows written by earlier chunks never commit. A batch must not contain two grants with the same (Subject, Object, Kind); BatchUpsert returns ErrDuplicateGrant.

func Read added in v1.16.0

func Read(ctx context.Context, db storage.DBTX, query ReadQuery) ([]Relationship, error)

Read returns a subject's relationships for the given objects (optionally filtered by kind). It is read-only, so it takes a DBTX (the pool, or a tx).

type ScanQuery added in v1.27.0

type ScanQuery struct {
	OrgID   string
	Objects []uuid.UUID
	Kinds   []Kind
	Roles   []uuid.UUID
	After   *Cursor // nil reads the first page
	Limit   int
}

ScanQuery is the input to LookupByOrg. After is nil for the first page. Limit must be between 1 and maxPageSize.

type ScannedRelationship added in v1.27.0

type ScannedRelationship struct {
	Subject   uuid.UUID
	Object    uuid.UUID
	Kind      Kind
	Role      uuid.UUID
	CreatedAt time.Time
	LocalID   string
}

ScannedRelationship is one row of an org scan, plus the LocalID of the subject's identity in that org.

func LookupByOrg added in v1.27.0

func LookupByOrg(ctx context.Context, db storage.DBTX, query ScanQuery) ([]ScannedRelationship, error)

LookupByOrg returns one page of an org's relationships, keyset-paginated. It is read-only, so it takes a DBTX.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL