repository

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base[T model.Models] interface {
	Create(object ...*T) error
	DB() *gorm.DB
	Delete(object *T) error
	DeleteByFields(fieldValues map[string]FieldValue) error
	Find(options ...QueryOption) ([]*T, int64, error)
	Get(identifier string, options ...QueryOption) (*T, error)
	GetByFields(fieldValues map[string]FieldValue, options ...QueryOption) (*T, error)
	Update(object *T) error
	UpdateAssociation(object *T, associationName string, data any) error
	WithTransaction(transaction database.Transaction) *base[T]
}

func New

func New[T model.Models](db *gorm.DB) Base[T]

New initializes a new repository.

type FieldValue

type FieldValue struct {
	Operator string
	Value    any
	Raw      any
}

type Principal

type Principal interface {
	Base[model.Principal]
	FindMatchingAttribute(principalAttribute string) ([]*PrincipalMatchingAttribute, error)
}

func NewPrincipal

func NewPrincipal(repository Base[model.Principal]) Principal

NewPrincipal initializes a new principal repository.

type PrincipalMatchingAttribute

type PrincipalMatchingAttribute struct {
	PrincipalID    string
	AttributeValue string
}

type QueryOption

type QueryOption func(*queryOptions)

QueryOption specifies how options should be formatted.

An option is a function that takes this private struct and override values on it.

func WithFilter

func WithFilter(filter map[string]FieldValue) QueryOption

WithFilter allows to specify some filters to apply on the query.

func WithJoin

func WithJoin(joins ...string) QueryOption

func WithPage

func WithPage(page int64) QueryOption

WithPage allows to specify the page number you want to retrieve.

func WithPreloads

func WithPreloads(preloads ...string) QueryOption

WithPreloads allows to specify relationships you want to preload with the currently requested resource.

func WithSize

func WithSize(size int64) QueryOption

WithSize allows to specify the size (number of elements) you want to retrieve.

func WithSkipPagination

func WithSkipPagination() QueryOption

WithSkipPagination allows to skip pagination and retrieve all elements.

func WithSort

func WithSort(sort string) QueryOption

WithSort allows to specify the sort order you want to apply on the query.

type Repositories

type Repositories interface {
	base[model.Action] |
		base[model.Client] |
		base[model.CompiledPolicy] |
		base[model.Policy] |
		base[model.Principal] |
		base[model.Resource] |
		base[model.Role] |
		base[model.User] |
		resource
}

Repositories is a constraint interface that allows only authz library repositories.

type Resource

type Resource interface {
	Base[model.Resource]
	FindMatchingAttribute(resourceAttribute string, options ...ResourceQueryOption) ([]*ResourceMatchingAttribute, error)
}

func NewResource

func NewResource(repository Base[model.Resource]) Resource

NewResource initializes a new resource repository.

type ResourceMatchingAttribute

type ResourceMatchingAttribute struct {
	ResourceKind   string
	ResourceValue  string
	AttributeValue string
}

type ResourceQueryOption

type ResourceQueryOption func(*resourceQueryOptions)

func WithResourceIDs

func WithResourceIDs(resourceIDs []string) ResourceQueryOption

Jump to

Keyboard shortcuts

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