Documentation
¶
Index ¶
Constants ¶
const DefaultMigrationPoolName = "__default__migration_pool_name__"
const DefaultPoolName = "__default__pool_name__"
Variables ¶
This section is empty.
Functions ¶
func SearchFunc ¶ added in v1.64.16
func SearchFunc[T any]( ctx context.Context, dbConnection *gorm.DB, query *data.SearchQuery, validateColumn func(string) error, ) ([]T, error)
SearchFunc performs a complex search with pagination and filtering. It accepts a validation function to check column names, allowing flexible validation strategies.
Types ¶
type BaseRepository ¶ added in v1.63.0
type BaseRepository[T any] interface { Pool() pool.Pool WorkManager() workerpool.Manager GetByID(ctx context.Context, id string) (T, error) GetLastestBy(ctx context.Context, properties map[string]any) (T, error) GetAllBy(ctx context.Context, properties map[string]any, offset, limit int) ([]T, error) Search(ctx context.Context, query *data.SearchQuery) (workerpool.JobResultPipe[[]T], error) Count(ctx context.Context) (int64, error) CountBy(ctx context.Context, properties map[string]any) (int64, error) Create(ctx context.Context, entity T) error BatchSize() int BulkCreate(ctx context.Context, entities []T) error FieldsImmutable() []string FieldsAllowed() map[string]struct{} ExtendFieldsAllowed(fields ...string) IsFieldAllowed(column string) error Update(ctx context.Context, entity T, affectedFields ...string) (int64, error) BulkUpdate(ctx context.Context, entityIDs []string, params map[string]any) (int64, error) Delete(ctx context.Context, id string) error DeleteBatch(ctx context.Context, ids []string) error }
BaseRepository provides generic CRUD operations for any model type. T is the model type (e.g., *models.Room).
func NewBaseRepository ¶ added in v1.63.0
func NewBaseRepository[T data.BaseModelI]( ctx context.Context, dbPool pool.Pool, workMan workerpool.Manager, modelFactory func() T, opts ...BaseRepositoryOption, ) BaseRepository[T]
NewBaseRepository creates a new base repository instance. modelFactory should return a pointer to a new model instance (e.g., func() *models.Room { return &models.Room{} }).
type BaseRepositoryOption ¶ added in v1.94.2
type BaseRepositoryOption func(*baseRepositoryConfig)
BaseRepositoryOption configures optional behaviour on NewBaseRepository.
func WithBulkCreateConflictColumns ¶ added in v1.94.2
func WithBulkCreateConflictColumns(columns ...string) BaseRepositoryOption
WithBulkCreateConflictColumns sets the ON CONFLICT target columns for BulkCreate. Columns must match an existing unique index on the target table, otherwise Postgres rejects the insert.
type Manager ¶ added in v1.63.0
type Manager interface {
AddPool(ctx context.Context, reference string, store pool.Pool)
RemovePool(ctx context.Context, reference string)
GetPool(ctx context.Context, reference string) pool.Pool
Close(ctx context.Context)
SaveMigration(ctx context.Context, pool pool.Pool, migrationPatches ...*migration.Patch) error
// Migrate finds missing migrations and records them in the database.
Migrate(ctx context.Context, pool pool.Pool, migrationsDirPath string, migrations ...any) error
}