managers

package
v4.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseManager

type BaseManager interface {
	tracing.Tracer
	// GetQueryBuilder creates a new squirrel builder for a SQL query
	GetQueryBuilder() db.SQLBuilder
	// GetTxQueryBuilder is the same as GetQueryBuilder but also opens a transaction
	GetTxQueryBuilder(ctx context.Context, opts *sql.TxOptions) (db.SQLBuilder, *sql.Tx, error)
	// GetPageInfo returns the page info object for a given page
	//
	// `scope` is the SQL where statement that defines the scope
	// of the query (e.g. organization_id)
	// `filter` is the SQL where statement that defines how the data is filtered by the user.
	// The user would not see any counts beyond the scope
	// but will see the total count beyond the filter
	GetPageInfo(ctx context.Context, table string, page parameters.Page, scope, filter squirrel.Sqlizer) (pageInfo PageInfo, err error)
	// GetPageInfoWithQuery is a more low-level version of `GetPageInfo` that allow to use an arbitrary
	// query for calculating `PageInfo`.
	// Can be used when some joins or additional query parameters are needed.
	// Any query setting that conflicts with `Select("COUNT(1)")` (e.g. `ORDER BY`) should not be
	// used in the `query`, otherwise an invalid query will be generated and an error will be returned.
	GetPageInfoWithQuery(ctx context.Context, query squirrel.SelectBuilder, page parameters.Page, filter squirrel.Sqlizer) (pageInfo PageInfo, err error)
}

BaseManager describes a typical data manager

func NewBaseManager

func NewBaseManager(db *sql.DB, componentName string) BaseManager

NewBaseManager creates a new base manager

type IDResolver

type IDResolver interface {
	// Resolve returns an ID of the given record identified by the value which can be either
	// an UUID or a unique string value of the given secondary column.
	// where is a map of where statements to their list of arguments
	Resolve(ctx context.Context, sql db.SQLBuilder, value string, filter squirrel.Sqlizer) (string, error)
	// Sqlizer returns a Sqlizer interface that contains where statements for a given
	// filter and the ID column, so you can immediately use it with
	// the where of the select builder
	Sqlizer(ctx context.Context, sql db.SQLBuilder, value string, filter squirrel.Sqlizer) (squirrel.Sqlizer, error)
}

IDResolver makes possible to access database records by their IDs or unique values

func NewIDResolver

func NewIDResolver(table, idColumn, secondaryColumn string) IDResolver

NewIDResolver creates a new name->id resolver for a table, for example var (

CollectionIDResolver = NewIDResolver("collections", "collection_id", "name")
TableIDResolver = NewIDResolver("tables", "table_id", "name")

)

type PageInfo

type PageInfo struct {
	// Total number of items
	ItemCount uint32 `json:"itemCount"`
	// Maximum items that can be on the page.
	// They may be different from the requested number of times
	ItemsPerPage uint32 `json:"itemsPerPage"`
	// Item count if filters were not applied
	UnfilteredItemCount uint32 `json:"unfilteredItemCount"`
	// The current page number using 1-based array indexing
	Current uint32 `json:"current"`
}

PageInfo - Contains the pagination metadata for a response

Jump to

Keyboard shortcuts

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