sql

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PublicSchema = "public"
)

Variables

View Source
var (
	ErrPatchForeign              = errors.New("failed patching foreign key entity")
	ErrTenantOffboarding         = errors.New("tenant offboarding error")
	ErrUnsupportedOrderDirective = errors.New("unsupported order directive")
)

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) Create

func (r *ResourceRepository) Create(ctx context.Context, resource repo.Resource) error

Create adds meta information and stores a Resource.

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,
) (int, 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

func (r *ResourceRepository) Set(ctx context.Context, resource repo.Resource) error

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

Jump to

Keyboard shortcuts

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