Documentation
¶
Index ¶
- Constants
- Variables
- type ResourceRepository
- func (r *ResourceRepository) Count(ctx context.Context, resource repo.Resource, query repo.Query) (int, error)
- func (r *ResourceRepository) Create(ctx context.Context, resource repo.Resource) error
- func (r *ResourceRepository) Delete(ctx context.Context, resource repo.Resource, query repo.Query) (bool, error)
- func (r *ResourceRepository) First(ctx context.Context, resource repo.Resource, query repo.Query) (bool, error)
- func (r *ResourceRepository) List(ctx context.Context, resource repo.Resource, result any, query repo.Query) error
- func (r *ResourceRepository) OffboardTenant(ctx context.Context, tenantID string) error
- func (r *ResourceRepository) Patch(ctx context.Context, resource repo.Resource, query repo.Query) (bool, error)
- func (r *ResourceRepository) Set(ctx context.Context, resource repo.Resource) error
- func (r *ResourceRepository) Transaction(ctx context.Context, txFunc repo.TransactionFunc) error
- func (r *ResourceRepository) WithTenant(ctx context.Context, resource repo.Resource, ...) error
Constants ¶
const (
PublicSchema = "public"
)
Variables ¶
Functions ¶
This section is empty.
Types ¶
type ResourceRepository ¶
type ResourceRepository struct {
// contains filtered or unexported fields
}
ResourceRepository represents the repository for managing Resource data.
func NewRepository ¶
func NewRepository(db *multitenancy.DB) *ResourceRepository
NewRepository creates and returns a new instance of ResourceRepository.
func (*ResourceRepository) Count ¶
func (r *ResourceRepository) Count( ctx context.Context, resource repo.Resource, query repo.Query, ) (int, error)
Count returns the number of records matching the query conditions.
func (*ResourceRepository) Delete ¶
func (r *ResourceRepository) Delete( ctx context.Context, resource repo.Resource, query repo.Query, ) (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. If no query is provided it deletes the item by the primaryKey
func (*ResourceRepository) First ¶
func (r *ResourceRepository) First( ctx context.Context, resource repo.Resource, query repo.Query, ) (bool, error)
First fill given Resource with data, if found. Given Resource is used as query data. It will find the resource with the primary key as the where condition by omition
func (*ResourceRepository) List ¶
func (r *ResourceRepository) List( ctx context.Context, resource repo.Resource, result any, query repo.Query, ) error
List retrieves records from the database based on the provided query parameters and model. Result is an address
func (*ResourceRepository) OffboardTenant ¶
func (r *ResourceRepository) OffboardTenant(ctx context.Context, tenantID string) error
OffboardTenant cleans up the database by dropping the tenant-specific schema and associated tables. This method is intended to be used after a tenant has been removed.
func (*ResourceRepository) Patch ¶
func (r *ResourceRepository) Patch( ctx context.Context, resource repo.Resource, query repo.Query, ) (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) Set ¶
Set will create an item or update it if it already exists It returns an error if there was an error during the operation
func (*ResourceRepository) Transaction ¶
func (r *ResourceRepository) Transaction(ctx context.Context, txFunc repo.TransactionFunc) error
Transaction wraps a function inside a database transaction. 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.
func (*ResourceRepository) WithTenant ¶
func (r *ResourceRepository) WithTenant( ctx context.Context, resource repo.Resource, fn func(tx *multitenancy.DB) error, ) error
WithTenant runs GORM actions for a specific tenant