sql

package
v1.8.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownTypeForJSONBField = errors.New("unknown type for jsonb field")

Functions

func GetDataSourceName

func GetDataSourceName(conf config.DB) (string, error)

func Migrate

func Migrate(db *gorm.DB) error

Migrate runs DB migrations.

func StartDB

func StartDB(ctx context.Context, dbConf config.DB) (*gorm.DB, error)

StartDB starts DB connection and runs migrations.

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

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.

Jump to

Keyboard shortcuts

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