Documentation
¶
Index ¶
- Variables
- func GetDataSourceName(conf config.DB) (string, error)
- func Migrate(db *gorm.DB) error
- func StartDB(ctx context.Context, dbConf config.DB) (*gorm.DB, error)
- type ResourceRepository
- func (r ResourceRepository) Create(ctx context.Context, resource repository.Resource) error
- func (r ResourceRepository) Delete(ctx context.Context, resource repository.Resource) (bool, error)
- func (r ResourceRepository) Find(ctx context.Context, resource repository.Resource) (bool, error)
- func (r ResourceRepository) List(ctx context.Context, result any, query repository.Query) error
- func (r ResourceRepository) Patch(ctx context.Context, resource repository.Resource) (bool, error)
- func (r ResourceRepository) PatchAll(ctx context.Context, resource repository.Resource, result any, ...) (int64, error)
- func (r ResourceRepository) Transaction(ctx context.Context, txFunc repository.TransactionFunc) error
Constants ¶
This section is empty.
Variables ¶
var ErrUnknownTypeForJSONBField = errors.New("unknown type for jsonb field")
Functions ¶
Types ¶
type ResourceRepository ¶
type ResourceRepository struct {
// contains filtered or unexported fields
}
ResourceRepository represents the repository for managing Resource data.
func NewRepository ¶
func NewRepository(db *gorm.DB) *ResourceRepository
NewRepository creates and returns a new instance of ResourceRepository.
func (ResourceRepository) Create ¶
func (r ResourceRepository) Create(ctx context.Context, resource repository.Resource) error
Create adds meta information and stores a Resource.
func (ResourceRepository) Delete ¶
func (r ResourceRepository) Delete(ctx context.Context, resource repository.Resource) (bool, error)
Delete removes the Resource.
It returns true if a record was deleted successfully, false if there was no record to delete, and error if there was an error during the deletion.
func (ResourceRepository) Find ¶
func (r ResourceRepository) Find(ctx context.Context, resource repository.Resource) (bool, error)
Find fill given Resource with data, if found. Given Resource is used as query data.
func (ResourceRepository) List ¶
func (r ResourceRepository) List(ctx context.Context, result any, query repository.Query) error
List retrieves records from the database based on the provided query parameters and model.
func (ResourceRepository) Patch ¶
func (r ResourceRepository) Patch(ctx context.Context, resource repository.Resource) (bool, error)
Patch will patch the resource with primary key as the where condition.
It returns true if a record was patched successfully, and error if there was an error during the patch.
func (ResourceRepository) PatchAll ¶
func (r ResourceRepository) PatchAll(ctx context.Context, resource repository.Resource, result any, query repository.Query) (int64, error)
PatchAll will update all the resources that matches the query. It returns the number of affected rows and error if there was an error during the patch operation.
func (ResourceRepository) Transaction ¶
func (r ResourceRepository) Transaction(ctx context.Context, txFunc repository.TransactionFunc) error
Transaction will give transaction locking on particular rows. txFunc is a type TransactionFunc where we can define the transactional logic. if txFunc return no error then transaction is committed, else if txFunc return error then transaction is rolled back. Note: please dont use Goroutines inside the txFunc as this might lead to panic.