repository

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: MIT Imports: 9 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[M IModel] struct {
	// contains filtered or unexported fields
}

func (*BaseRepository[M]) Assign

func (m *BaseRepository[M]) Assign(attrs ...any) IRepository[M]

func (*BaseRepository[M]) Association

func (m *BaseRepository[M]) Association(column string) core.IError

func (*BaseRepository[M]) Attrs

func (m *BaseRepository[M]) Attrs(attrs ...any) IRepository[M]

func (*BaseRepository[M]) Clauses

func (m *BaseRepository[M]) Clauses(conds ...clause.Expression) IRepository[M]

func (*BaseRepository[M]) Count

func (m *BaseRepository[M]) Count() (int64, core.IError)

func (*BaseRepository[M]) Create

func (m *BaseRepository[M]) Create(values any) core.IError

Create insert the value into database

func (*BaseRepository[M]) Delete

func (m *BaseRepository[M]) Delete(conds ...any) core.IError

Delete value match given conditions, if the value has primary key, then will including the primary key as condition

func (*BaseRepository[M]) Distinct

func (m *BaseRepository[M]) Distinct(args ...any) IRepository[M]

Distinct specify distinct fields that you want querying

func (*BaseRepository[M]) Exec

func (m *BaseRepository[M]) Exec(sql string, values ...any) core.IError

Exec execute raw sql

func (*BaseRepository[M]) FindAll

func (m *BaseRepository[M]) FindAll(conds ...any) ([]M, core.IError)

FindAll find records that match given conditions

func (*BaseRepository[M]) FindInBatches

func (m *BaseRepository[M]) FindInBatches(dest any, batchSize int, fc func(tx *gorm.DB, batch int) error) *gorm.DB

func (*BaseRepository[M]) FindOne

func (m *BaseRepository[M]) FindOne(conds ...any) (*M, core.IError)

FindOne find first record that match given conditions, order by primary key

func (*BaseRepository[M]) FindOneOrCreate

func (m *BaseRepository[M]) FindOneOrCreate(dest any, conds ...any) core.IError

func (*BaseRepository[M]) FindOneOrInit

func (m *BaseRepository[M]) FindOneOrInit(dest interface{}, conds ...any) core.IError

func (*BaseRepository[M]) Group

func (m *BaseRepository[M]) Group(name string) IRepository[M]

func (*BaseRepository[M]) HardDelete

func (m *BaseRepository[M]) HardDelete(conds ...any) core.IError

HardDelete delete value match given conditions, if the value has primary key, then will including the primary key as condition

func (*BaseRepository[M]) Joins

func (m *BaseRepository[M]) Joins(query string, args ...any) IRepository[M]

func (*BaseRepository[M]) Limit

func (m *BaseRepository[M]) Limit(limit int) IRepository[M]

func (*BaseRepository[M]) NewSession

func (m *BaseRepository[M]) NewSession() IRepository[M]

func (*BaseRepository[M]) Offset

func (m *BaseRepository[M]) Offset(offset int) IRepository[M]

func (*BaseRepository[M]) Omit

func (m *BaseRepository[M]) Omit(columns ...string) IRepository[M]

func (*BaseRepository[M]) Order

func (m *BaseRepository[M]) Order(value any) IRepository[M]

func (*BaseRepository[M]) Pagination

func (m *BaseRepository[M]) Pagination(pageOptions *models.PageOptions) (*Pagination[M], core.IError)

func (*BaseRepository[M]) Pluck

func (m *BaseRepository[M]) Pluck(column string, desc any) core.IError

func (*BaseRepository[M]) Preload

func (m *BaseRepository[M]) Preload(query string, args ...any) IRepository[M]

func (*BaseRepository[M]) Raw

func (m *BaseRepository[M]) Raw(dest any, sql string, values ...any) core.IError

func (*BaseRepository[M]) Row

func (m *BaseRepository[M]) Row() *sql.Row

func (*BaseRepository[M]) Rows

func (m *BaseRepository[M]) Rows() (*sql.Rows, error)

func (*BaseRepository[M]) Save

func (m *BaseRepository[M]) Save(values any) core.IError

func (*BaseRepository[M]) Scan

func (m *BaseRepository[M]) Scan(dest any) core.IError

func (*BaseRepository[M]) Select

func (m *BaseRepository[M]) Select(query any, args ...any) IRepository[M]

func (*BaseRepository[M]) Unscoped

func (m *BaseRepository[M]) Unscoped() IRepository[M]

func (*BaseRepository[M]) Update

func (m *BaseRepository[M]) Update(column string, value any) IRepository[M]

func (*BaseRepository[M]) Updates

func (m *BaseRepository[M]) Updates(values any) core.IError

Update update attributes with callbacks, refer: https://gorm.io/docs/update.html#Update-Changed-Fields

func (*BaseRepository[M]) Where

func (m *BaseRepository[M]) Where(query any, args ...any) IRepository[M]

func (*BaseRepository[M]) WithContext

func (m *BaseRepository[M]) WithContext(ctx context.Context) IRepository[M]

type IModel

type IModel interface {
	TableName() string
}

type IRepository

type IRepository[M IModel] interface {
	FindAll(conds ...any) ([]M, core.IError)                                               // Function to find all records that match the given conditions
	FindOne(conds ...any) (*M, core.IError)                                                // Function to find the first record that matches the given conditions
	Count() (int64, core.IError)                                                           // Function to count the number of records
	Create(values any) core.IError                                                         // Function to insert a value into the database
	Updates(values any) core.IError                                                        // Function to update attributes with callbacks
	Delete(conds ...any) core.IError                                                       // Function to delete a value that matches the given conditions
	HardDelete(conds ...any) core.IError                                                   // Function to hard delete a value that matches the given conditions
	Pagination(pageOptions *models.PageOptions) (*Pagination[M], core.IError)              // Function to perform pagination on the records
	Save(values any) core.IError                                                           // Function to set values on a model
	Where(query any, args ...any) IRepository[M]                                           // Function to filter records based on a query
	Preload(query string, args ...any) IRepository[M]                                      // Function to preload associations
	Unscoped() IRepository[M]                                                              // Function to apply an unscoped query
	Exec(sql string, values ...any) core.IError                                            // Function to execute raw SQL queries
	Group(name string) IRepository[M]                                                      // Function to group records
	Joins(query string, args ...any) IRepository[M]                                        // Function to perform joins
	Order(value any) IRepository[M]                                                        // Function to order the records
	Distinct(args ...any) IRepository[M]                                                   // Function to specify distinct fields for querying
	Update(column string, value any) IRepository[M]                                        // Function to update a column with a value
	Select(query any, args ...any) IRepository[M]                                          // Function to select specific columns
	Omit(columns ...string) IRepository[M]                                                 // Function to omit specific columns
	Limit(limit int) IRepository[M]                                                        // Function to limit the number of records
	Offset(offset int) IRepository[M]                                                      // Function to specify the offset of records
	Association(column string) core.IError                                                 // Function to retrieve an association
	FindInBatches(dest any, batchSize int, fc func(tx *gorm.DB, batch int) error) *gorm.DB // Function to find records in batches
	FindOneOrInit(dest any, conds ...any) core.IError                                      // Function to find the first record that matches the given conditions or initialize a new one
	FindOneOrCreate(dest any, conds ...any) core.IError                                    // Function to find the first record that matches the given conditions or create a new one
	Attrs(attrs ...any) IRepository[M]                                                     // Function to set attributes on a model
	Assign(attrs ...any) IRepository[M]                                                    // Function to assign attributes to a model
	Pluck(column string, desc any) core.IError                                             // Function to retrieve a specific column value
	Scan(dest any) core.IError                                                             // Function to scan query results into a destination
	Row() *sql.Row                                                                         // Function to retrieve a single row
	Rows() (*sql.Rows, error)                                                              // Function to retrieve multiple rows
	Raw(dest any, sql string, values ...any) core.IError                                   // Function to execute a raw SQL query
	Clauses(conds ...clause.Expression) IRepository[M]                                     // Function to apply additional query clauses
	WithContext(ctx context.Context) IRepository[M]                                        // Function to set the context used for future queries
	NewSession() IRepository[M]                                                            // Function to create a new session for this query
}

func New

func New[M IModel](ctx core.IContext) IRepository[M]

func NewWithDB

func NewWithDB[M IModel](ctx core.IContext, db *gorm.DB) IRepository[M]

type MockRepository

type MockRepository[M IModel] struct {
	mock.Mock
}

MockIRepository is a mock of IRepository interface.

func NewMock

func NewMock[M IModel]() *MockRepository[M]

func (*MockRepository[M]) Assign

func (m *MockRepository[M]) Assign(attrs ...interface{}) IRepository[M]

func (*MockRepository[M]) Association

func (m *MockRepository[M]) Association(column string) core.IError

func (*MockRepository[M]) Attrs

func (m *MockRepository[M]) Attrs(attrs ...interface{}) IRepository[M]

func (*MockRepository[M]) Clauses

func (m *MockRepository[M]) Clauses(conds ...clause.Expression) IRepository[M]

func (*MockRepository[M]) Count

func (m *MockRepository[M]) Count() (int64, core.IError)

func (*MockRepository[M]) Create

func (m *MockRepository[M]) Create(values interface{}) core.IError

func (*MockRepository[M]) Delete

func (m *MockRepository[M]) Delete(conds ...interface{}) core.IError

func (*MockRepository[M]) Distinct

func (m *MockRepository[M]) Distinct(args ...interface{}) IRepository[M]

func (*MockRepository[M]) Exec

func (m *MockRepository[M]) Exec(sql string, values ...interface{}) core.IError

func (*MockRepository[M]) FindAll

func (m *MockRepository[M]) FindAll(conds ...interface{}) ([]M, core.IError)

func (*MockRepository[M]) FindInBatches

func (m *MockRepository[M]) FindInBatches(dest interface{}, batchSize int, fc func(tx *gorm.DB, batch int) error) *gorm.DB

func (*MockRepository[M]) FindOne

func (m *MockRepository[M]) FindOne(conds ...interface{}) (*M, core.IError)

func (*MockRepository[M]) FindOneOrCreate

func (m *MockRepository[M]) FindOneOrCreate(dest interface{}, conds ...interface{}) core.IError

func (*MockRepository[M]) FindOneOrInit

func (m *MockRepository[M]) FindOneOrInit(dest interface{}, conds ...interface{}) core.IError

func (*MockRepository[M]) Group

func (m *MockRepository[M]) Group(name string) IRepository[M]

func (*MockRepository[M]) HardDelete

func (m *MockRepository[M]) HardDelete(conds ...interface{}) core.IError

func (*MockRepository[M]) Joins

func (m *MockRepository[M]) Joins(query string, args ...interface{}) IRepository[M]

func (*MockRepository[M]) Limit

func (m *MockRepository[M]) Limit(limit int) IRepository[M]

func (*MockRepository[M]) NewSession

func (m *MockRepository[M]) NewSession() IRepository[M]

func (*MockRepository[M]) Offset

func (m *MockRepository[M]) Offset(offset int) IRepository[M]

func (*MockRepository[M]) Omit

func (m *MockRepository[M]) Omit(columns ...string) IRepository[M]

func (*MockRepository[M]) Order

func (m *MockRepository[M]) Order(value interface{}) IRepository[M]

func (*MockRepository[M]) Pagination

func (m *MockRepository[M]) Pagination(pageOptions *models.PageOptions) (*Pagination[M], core.IError)

func (*MockRepository[M]) Pluck

func (m *MockRepository[M]) Pluck(column string, desc interface{}) core.IError

func (*MockRepository[M]) Preload

func (m *MockRepository[M]) Preload(query string, args ...interface{}) IRepository[M]

func (*MockRepository[M]) Raw

func (m *MockRepository[M]) Raw(dest interface{}, sql string, values ...interface{}) core.IError

func (*MockRepository[M]) Row

func (m *MockRepository[M]) Row() *sql.Row

func (*MockRepository[M]) Rows

func (m *MockRepository[M]) Rows() (*sql.Rows, error)

func (*MockRepository[M]) Save

func (m *MockRepository[M]) Save(values interface{}) core.IError

func (*MockRepository[M]) Scan

func (m *MockRepository[M]) Scan(dest interface{}) core.IError

func (*MockRepository[M]) Select

func (m *MockRepository[M]) Select(query interface{}, args ...interface{}) IRepository[M]

func (*MockRepository[M]) Unscoped

func (m *MockRepository[M]) Unscoped() IRepository[M]

func (*MockRepository[M]) Update

func (m *MockRepository[M]) Update(column string, value interface{}) IRepository[M]

func (*MockRepository[M]) Updates

func (m *MockRepository[M]) Updates(values interface{}) core.IError

func (*MockRepository[M]) Where

func (m *MockRepository[M]) Where(query interface{}, args ...interface{}) IRepository[M]

func (*MockRepository[M]) WithContext

func (m *MockRepository[M]) WithContext(ctx context.Context) IRepository[M]

type Pagination

type Pagination[M any] struct {
	Page  int64 `json:"page" example:"1"`
	Total int64 `json:"total" example:"45"`
	Limit int64 `json:"limit" example:"30"`
	Count int64 `json:"count" example:"30"`
	Items []M   `json:"items"`
}

Jump to

Keyboard shortcuts

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