repository

package
v0.0.0-...-794f3e4 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseRepository

type BaseRepository[T any] struct {
	// contains filtered or unexported fields
}

BaseRepository - provides default persistence

func NewBaseRepository

func NewBaseRepository[T any](
	store DataStore,
	baseTableName string,
	baseTableSuffix string,
	expiration time.Duration,
	builder domain.Factory[T],
) (*BaseRepository[T], error)

NewBaseRepository creates base repository

func (*BaseRepository[T]) Create

func (r *BaseRepository[T]) Create(
	_ context.Context,
	organizationID string,
	namespace string,
	id string,
	obj *T,
	expiration time.Duration,
) (err error)

Create adds a new item in the database.

func (*BaseRepository[T]) Delete

func (r *BaseRepository[T]) Delete(
	_ context.Context,
	organizationID string,
	namespace string,
	id string) error

func (*BaseRepository[T]) GetByID

func (r *BaseRepository[T]) GetByID(
	ctx context.Context,
	organizationID string,
	namespace string,
	id string,
) (*T, error)

GetByID - finds an object by id

func (*BaseRepository[T]) GetByIDs

func (r *BaseRepository[T]) GetByIDs(
	_ context.Context,
	organizationID string,
	namespace string,
	ids ...string) (res map[string]*T, err error)

GetByIDs retrieves objects by ids

func (*BaseRepository[T]) Query

func (r *BaseRepository[T]) Query(
	_ context.Context,
	organizationID string,
	namespace string,
	predicate map[string]string,
	lastOffsetToken string,
	limit int64) (res []*T, nextOffsetToken string, err error)

Query - queries data

func (*BaseRepository[T]) Size

func (r *BaseRepository[T]) Size(
	_ context.Context,
	organizationID string,
	namespace string,
) (int64, error)

Size of table

func (*BaseRepository[T]) Update

func (r *BaseRepository[T]) Update(
	_ context.Context,
	organizationID string,
	namespace string,
	id string,
	version int64,
	obj *T,
	expiration time.Duration,
) (err error)

Update changes existing record in the database.

type DataStore

type DataStore interface {
	// CreateTable creates underlying table if needed.
	CreateTable(
		baseTableName string,
		baseTableSuffix string,
	) (err error)

	// Size of records for tenant.
	Size(
		baseTableName string,
		baseTableSuffix string,
		tenant string,
		namespace string,
	) (size int64, err error)

	// Get finds records by ids.
	Get(
		baseTableName string,
		baseTableSuffix string,
		tenant string,
		namespace string,
		ids ...string,
	) (res map[string][]byte, err error)

	// Query searches records by predicates.
	Query(
		baseTableName string,
		baseTableSuffix string,
		tenant string,
		namespace string,
		predicate map[string]string,
		lastEvaluatedKeyStr string,
		limit int64,
	) (res map[string][]byte, nextKeyStr string, err error)

	// Create adds a new record.
	Create(
		baseTableName string,
		baseTableSuffix string,
		tenant string,
		namespace string,
		id string,
		value []byte,
		expiration time.Duration) (err error)

	// Update changes existing record.
	Update(
		baseTableName string,
		baseTableSuffix string,
		tenant string,
		namespace string,
		id string,
		version int64,
		value []byte,
		expiration time.Duration) (err error)

	// Delete removes existing record.
	Delete(
		baseTableName string,
		baseTableSuffix string,
		tenant string,
		namespace string,
		id string,
	) (err error)

	// ClearTable removes all records for tenant
	ClearTable(
		baseTableName string,
		baseTableSuffix string,
		tenant string,
		namespace string,
	) (err error)
}

DataStore interface

type Repository

type Repository[T any] interface {
	// GetByIDs - finds objects matching ids.
	GetByIDs(
		ctx context.Context,
		organizationID string,
		namespace string,
		ids ...string,
	) (map[string]*T, error)

	// GetByID - finds an object by id.
	GetByID(
		ctx context.Context,
		organizationID string,
		namespace string,
		id string,
	) (*T, error)

	// Create - creates a new object.
	Create(
		ctx context.Context,
		organizationID string,
		namespace string,
		id string,
		obj *T,
		expiration time.Duration,
	) error

	// Update - saves existing object.
	Update(
		ctx context.Context,
		organizationID string,
		namespace string,
		id string,
		version int64,
		obj *T,
		expiration time.Duration,
	) error

	// Query - queries objects
	Query(
		ctx context.Context,
		organizationID string,
		namespace string,
		predicate map[string]string,
		offset string,
		limit int64,
	) (res []*T, nextOffset string, err error)

	// Delete - remove the object
	Delete(
		ctx context.Context,
		organizationID string,
		namespace string,
		id string,
	) error

	// Size of table
	Size(
		ctx context.Context,
		organizationID string,
		namespace string,
	) (int64, error)
}

func NewGroupRepository

func NewGroupRepository(
	store DataStore,
) (Repository[types.Group], error)

NewGroupRepository creates repository for persisting groups

func NewHashIndexRepository

func NewHashIndexRepository(
	store DataStore,
) (Repository[domain.HashIndex], error)

NewHashIndexRepository creates repository for indexes

func NewOrganizationRepository

func NewOrganizationRepository(
	store DataStore,
) (Repository[types.Organization], error)

NewOrganizationRepository creates repository for persisting organization

func NewPermissionRepository

func NewPermissionRepository(
	store DataStore,
) (Repository[types.Permission], error)

NewPermissionRepository creates repository for persisting permission

func NewPrincipalRepository

func NewPrincipalRepository(
	store DataStore,
) (Repository[types.Principal], error)

NewPrincipalRepository creates repository for persisting principals

func NewRelationshipRepository

func NewRelationshipRepository(
	store DataStore,
) (Repository[types.Relationship], error)

NewRelationshipRepository creates repository for persisting relationships

func NewResourceRepository

func NewResourceRepository(
	store DataStore,
) (Repository[types.Resource], error)

NewResourceRepository creates repository for persisting resources

func NewRoleRepository

func NewRoleRepository(
	store DataStore,
) (Repository[types.Role], error)

NewRoleRepository creates repository for persisting roles

type ResourceInstanceRepositoryFactory

type ResourceInstanceRepositoryFactory interface {
	CreateResourceInstanceRepository(resourceID string) (Repository[types.ResourceInstance], error)
}

ResourceInstanceRepositoryFactory helper

func NewResourceInstanceRepository

func NewResourceInstanceRepository(
	store DataStore,
	expiration time.Duration,
) (ResourceInstanceRepositoryFactory, error)

NewResourceInstanceRepository creates repository for persisting resources instance

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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