db

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2020 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

This package defines the database provider interface, and provides a simple in-memory implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB interface {
	// Insert the given resource into the database, or return any error.
	Insert(ctx context.Context, resource *prop.Resource) error
	// Count the number of resources that meets the given SCIM filter.
	Count(ctx context.Context, filter string) (int, error)
	// Get a resource by its id. The projection parameter specifies the attributes to be included or excluded from the
	// response. Implementations may elect to ignore this parameter in case caller services need all the attributes for
	// additional processing.
	Get(ctx context.Context, id string, projection *crud.Projection) (*prop.Resource, error)
	// Replace overwrites an existing reference resource with the content of the replacement resource. The reference
	// and the replacement resource are supposed to have the same id.
	Replace(ctx context.Context, ref *prop.Resource, replacement *prop.Resource) error
	// Delete a resource
	Delete(ctx context.Context, resource *prop.Resource) error
	// Query resources. The projection parameter specifies the attributes to be included or excluded from the
	// response. Implementations may elect to ignore this parameter in case caller services need all the attributes for
	// additional processing.
	Query(ctx context.Context, filter string, sort *crud.Sort, pagination *crud.Pagination, projection *crud.Projection) ([]*prop.Resource, error)
}

DB is the abstraction for the database that provides the persistence and look up capabilities.

func Memory

func Memory() DB

Memory return a new memory implementation of DB. This implementation saves resources in memory. Although it does allow for concurrent access through the use of RWMutex, it does not support high throughput usage. Hence, it is only intended for testing and showcasing purposes. This implementation also ignores all the field projection parameters that it always returned the full resource regardless of the request to include or exclude attributes.

func NoOp added in v2.1.0

func NoOp() DB

NoOp return an no op implementation of DB. This implementation does nothing and always returns nil error. For Count method, it returns 0 as count; for Get method, it returns nil resource; For Query method, it returns empty slice as results. This implementation might be useful when implementing use cases where resource does not require persistence.

Jump to

Keyboard shortcuts

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