Documentation ¶
Index ¶
- func Fields(fields ...string) repository.Option
- func GroupBy(fields ...string) repository.Option
- func MaxResults(n int) repository.Option
- func NewRepository(db *gorm.DB, entity repository.Model) repository.Repository
- func Offset(offset int) repository.Option
- func OrderBy(orders ...OrderByField) repository.Option
- func Preload(field string, filter ...interface{}) repository.Option
- func Where(template string, values ...interface{}) repository.Option
- type Model
- type Option
- type OrderByField
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fields ¶
func Fields(fields ...string) repository.Option
Fields defines fields to return. Passing this Option to a Repository operation overwrites any previous Fields options passed.
func GroupBy ¶
func GroupBy(fields ...string) repository.Option
GroupBy groups results based field values. Passing this Option to a Repository operation overwrites any previous GroupBy options passed.
func MaxResults ¶
func MaxResults(n int) repository.Option
MaxResults defines the maximum number of results for an operation that can return multiple results. Passing this Option to a Repository operation overwrites any previous MaxResults options passed.
func NewRepository ¶
func NewRepository(db *gorm.DB, entity repository.Model) repository.Repository
NewRepository initializes a new repository.Repository implementation for SQL databases.
func Offset ¶
func Offset(offset int) repository.Option
Offset defines a number of results to skip before starting to capture values to return. This Option will be ignored if the MaxResults Option is not present. Passing this Option to a Repository operation overwrites any previous Offset options passed.
func OrderBy ¶
func OrderBy(orders ...OrderByField) repository.Option
OrderBy sorts results based on fields. Use the Ascending and Descending functions to pass orders to this Option. In situations with multiple orders, they are applied in sequence. Multiple OrderBy options can be passed to a single Repository operation. They are appended to any previous orders.
func Preload ¶
func Preload(field string, filter ...interface{}) repository.Option
Preload allows loading a single related model to have it be included in the returned value. The field parameter must match the model field name exactly (case-sensitive). An optional filter composed of a template and any number of values can be passed to filter preloaded results. Multiple Preload options can be passed to a single Repository operation. They are appended to any previous preloads.
func Where ¶
func Where(template string, values ...interface{}) repository.Option
Where filters results based on passed conditions. Multiple Filter options can be passed to a single Repository operation. They are logically ANDed together.
Types ¶
type Model ¶
type Model struct { // ID contains the primary key identifier. ID uint `gorm:"primaryKey"` // CreatedAt contains the date and time at which this model has been persisted. CreatedAt time.Time `json:"created_at"` // UpdatedAt contains the last date and time when this model has been updated. UpdatedAt time.Time `json:"updated_at"` // DeletedAt is used to implement soft record deletion. If set, the record will be considered // as deleted. DeletedAt *time.Time `json:"deleted_at" gorm:"index"` }
Model implements the repository.Model interface for SQL backends. It provides a set of common generic fields and operations that partially implement the repository.Model interface. To use it, embed it in your application-specific repository.Model implementation.
type Option ¶
Option is a SQL-specific repository.Option implementation. It is used to configure SQL repository operations.
type OrderByField ¶
type OrderByField string
OrderByField contains order by information for a field
func Ascending ¶
func Ascending(field string) OrderByField
Ascending sorts the passed field in ascending order.
func Descending ¶
func Descending(field string) OrderByField
Descending sorts the passed field in descending order.