Documentation
¶
Index ¶
Constants ¶
View Source
const DefaultMigrationPoolName = "__default__migration_pool_name__"
View Source
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, ) 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 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
}
Click to show internal directories.
Click to hide internal directories.