Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FindOptions ¶ added in v1.0.0
FindOptions type defines options for limiting and paging search results.
Property:
- Limit: an integer that specifies the maximum number of results to be returned by a search or query. It's often used in conjunction with the Page property to implement pagination.
- Page: an integer that represents the current page number in a paginated result set. It's often used in combination with the Limit property to determine which subset of data to return.
type Repository ¶
type Repository[T any] interface { GetDB() *gorm.DB Create(ctx context.Context, entity *T) error CreateInTransaction(ctx context.Context, db *gorm.DB, entity *T) error Find(ctx context.Context, entity interface{}, options *FindOptions) (list []*T, err error) FindInTransaction(ctx context.Context, db *gorm.DB, entity interface{}, options *FindOptions) (list []*T, err error) Count(ctx context.Context, entity interface{}) (count int64, err error) CountInTransaction(ctx context.Context, db *gorm.DB, entity interface{}) (count int64, err error) Get(ctx context.Context, id string) (entity *T, err error) GetInTransaction(ctx context.Context, db *gorm.DB, id string) (entity *T, err error) Update(ctx context.Context, entity T) (updated *T, err error) UpdateInTransaction(ctx context.Context, db *gorm.DB, entity T) (updated *T, err error) Delete(ctx context.Context, id string) (deleted bool, err error) DeleteInTransaction(ctx context.Context, db *gorm.DB, id string) (deleted bool, err error) }
Repository defines a set of methods for interacting with a database using GORM in Go.
Property:
- GetDB: returns a pointer to a gorm.DB instance that allows performing database operations.
- Create: creates a new entity of type T in the database.
- CreateInTransaction: creates a new entity in the database within a transaction. It takes a context.Context and a *gorm.DB as parameters, along with a pointer to the entity to be created. It returns an error if the creation fails.
- Find: retrieves a list of entities from the repository based on specified criteria in the FindOptions parameter. It returns a slice of pointers to the type T and an error if any occurred during the operation.
- FindInTransaction: finds multiple entities in a transactional context. It takes a context.Context object, a *gorm.DB object representing the transaction, an interface object representing the entity to be found, and a *FindOptions object representing the options for the find operation. It returns a slice of pointers to the found entities.
- Count: returns the number of entities in the repository.
- CountInTransaction: : counts the number of entities in the database within a transaction. It takes a context.Context and a *gorm.DB as parameters, along with an entity interface representing the type of entity to count. It returns the count as an int64 and an error if any occurred.
- Get: retrieves a single entity of type T from the repository based on the provided ID. It returns the retrieved entity and an error if any occurred during the retrieval process.
- GetInTransaction: retrieves a single entity of type T from the database within a transaction. It takes a context.Context and a *gorm.DB as parameters and returns a pointer to the retrieved entity of type T and an error if any.
- Update: updates an existing entity in the repository. It takes a context.Context object and an entity of type T as input and returns the updated entity of type T and an error. If the update is successful, the updated entity is returned; otherwise, an error is returned.
- UpdateInTransaction: updates an entity of type T in a transactional context. It takes a context.Context and a *gorm.DB as parameters, along with the entity to be updated. It returns the updated entity of type *T and an error if any occurred during the update process.
- Delete: deletes an entity from the repository based on its ID. It takes a context.Context object and the ID of the entity to be deleted as input parameters. It returns a boolean value indicating whether the entity was successfully deleted or not, along with an error object if any.
- DeleteInTransaction:deletes an entity with the given ID from the database within a transaction. It takes a context.Context object, a *gorm.DB object representing the transaction, and the ID of the entity to be deleted. It returns a boolean indicating whether the entity was successfully deleted and an error.
type Rulesheets ¶
type Rulesheets interface { Repository[models.Rulesheet] }
Rulesheets is defining an interface that has a single method signature `Repository[models.Rulesheet]` that is defined in repository.go.
func GetRulesheets ¶
func GetRulesheets() Rulesheets
GetRulesheets returns an instance of the Rulesheets struct, creating it if it doesn't already exist.
func NewRulesheetsWithDB ¶ added in v1.8.0
func NewRulesheetsWithDB(db *gorm.DB) (Rulesheets, error)
NewRulesheetsWithDB creates a new instance of Rulesheets with a given db connection and performs db migration.
Click to show internal directories.
Click to hide internal directories.