Documentation
¶
Overview ¶
Package postgres provides PostgreSQL implementations of the repository interfaces. This file contains test helpers for PostgreSQL integration tests.
Index ¶
- func GetTx(ctx context.Context) pgx.Tx
- func SetupTestDatabase(t *testing.T) (*pgxpool.Pool, context.Context, *zap.Logger, func())
- func SetupTestRepositories(t *testing.T) (ports.RepositoryFactory, context.Context, func())
- type BaseRepository
- func (r *BaseRepository[T]) Count(ctx context.Context, filter ports.FilterOptions) (int64, error)
- func (r *BaseRepository[T]) Delete(ctx context.Context, id uuid.UUID) error
- func (r *BaseRepository[T]) GetByID(ctx context.Context, id uuid.UUID) (T, error)
- func (r *BaseRepository[T]) List(ctx context.Context, options ports.QueryOptions) ([]T, *ports.PagedResult, error)
- type ChildRepository
- func (r *ChildRepository) Count(ctx context.Context, filter ports.FilterOptions) (int64, error)
- func (r *ChildRepository) Create(ctx context.Context, child *domain.Child) error
- func (r *ChildRepository) Delete(ctx context.Context, id uuid.UUID) error
- func (r *ChildRepository) GetByID(ctx context.Context, id uuid.UUID) (*domain.Child, error)
- func (r *ChildRepository) List(ctx context.Context, options ports.QueryOptions) ([]*domain.Child, *ports.PagedResult, error)
- func (r *ChildRepository) ListByParentID(ctx context.Context, parentID uuid.UUID, options ports.QueryOptions) ([]*domain.Child, *ports.PagedResult, error)
- func (r *ChildRepository) Update(ctx context.Context, child *domain.Child) error
- type GenericChildRepository
- func (r *GenericChildRepository) Create(ctx context.Context, child *domain.Child) error
- func (r *GenericChildRepository) ListByParentID(ctx context.Context, parentID uuid.UUID, options ports.QueryOptions) ([]*domain.Child, *ports.PagedResult, error)
- func (r *GenericChildRepository) Update(ctx context.Context, child *domain.Child) error
- type GenericParentRepository
- type GenericRepositoryFactory
- func (f *GenericRepositoryFactory) Close(ctx context.Context) error
- func (f *GenericRepositoryFactory) GetGenericChildRepository() ports.Repository[*domain.Child]
- func (f *GenericRepositoryFactory) GetGenericParentRepository() ports.Repository[*domain.Parent]
- func (f *GenericRepositoryFactory) GetTransactionManager() ports.TransactionManager
- func (f *GenericRepositoryFactory) InitSchema(ctx context.Context) error
- func (f *GenericRepositoryFactory) NewChildRepository() ports.ChildRepository
- func (f *GenericRepositoryFactory) NewParentRepository() ports.ParentRepository
- type ParentRepository
- func (r *ParentRepository) Count(ctx context.Context, filter ports.FilterOptions) (int64, error)
- func (r *ParentRepository) Create(ctx context.Context, parent *domain.Parent) error
- func (r *ParentRepository) Delete(ctx context.Context, id uuid.UUID) error
- func (r *ParentRepository) GetByID(ctx context.Context, id uuid.UUID) (*domain.Parent, error)
- func (r *ParentRepository) List(ctx context.Context, options ports.QueryOptions) ([]*domain.Parent, *ports.PagedResult, error)
- func (r *ParentRepository) Update(ctx context.Context, parent *domain.Parent) error
- type RepositoryFactory
- func (f *RepositoryFactory) Close(ctx context.Context) error
- func (f *RepositoryFactory) GetTransactionManager() ports.TransactionManager
- func (f *RepositoryFactory) InitSchema(ctx context.Context) error
- func (f *RepositoryFactory) NewChildRepository() ports.ChildRepository
- func (f *RepositoryFactory) NewParentRepository() ports.ParentRepository
- type TransactionManager
- func (tm *TransactionManager) BeginTx(ctx context.Context) (context.Context, error)
- func (tm *TransactionManager) CommitTx(ctx context.Context) error
- func (tm *TransactionManager) RollbackTx(ctx context.Context) error
- func (tm *TransactionManager) WithTx(ctx context.Context, fn func(ctx context.Context) error) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetTx ¶
GetTx is a helper function to get the transaction from the context This is used by the repositories to get the transaction
func SetupTestDatabase ¶
SetupTestDatabase sets up a PostgreSQL connection for testing. It returns a connection pool, context, logger, and cleanup function. The cleanup function should be deferred to ensure proper resource cleanup.
func SetupTestRepositories ¶
SetupTestRepositories sets up repositories for testing. It returns a repository factory, context, and cleanup function. The cleanup function should be deferred to ensure proper resource cleanup.
Types ¶
type BaseRepository ¶
BaseRepository is a generic base repository for PostgreSQL
func NewBaseRepository ¶
func NewBaseRepository[T domain.Entity]( pool *pgxpool.Pool, logger *zap.Logger, tracerName string, tableName string, scanFunc func(row pgx.Row) (T, error), buildListSQL func(filter ports.FilterOptions, sort ports.SortOptions) (string, []interface{}), ) *BaseRepository[T]
NewBaseRepository creates a new base repository
func (*BaseRepository[T]) Count ¶
func (r *BaseRepository[T]) Count(ctx context.Context, filter ports.FilterOptions) (int64, error)
Count returns the total count of entities matching the filter
func (*BaseRepository[T]) List ¶
func (r *BaseRepository[T]) List(ctx context.Context, options ports.QueryOptions) ([]T, *ports.PagedResult, error)
List retrieves a list of entities with pagination, filtering, and sorting
type ChildRepository ¶
type ChildRepository struct {
// contains filtered or unexported fields
}
ChildRepository implements the ports.ChildRepository interface for PostgreSQL
func NewChildRepository ¶
func NewChildRepository(pool *pgxpool.Pool, logger *zap.Logger) *ChildRepository
NewChildRepository creates a new PostgreSQL child repository
func (*ChildRepository) Count ¶
func (r *ChildRepository) Count(ctx context.Context, filter ports.FilterOptions) (int64, error)
Count returns the total count of children matching the filter
func (*ChildRepository) List ¶
func (r *ChildRepository) List(ctx context.Context, options ports.QueryOptions) ([]*domain.Child, *ports.PagedResult, error)
List retrieves a list of children with pagination, filtering, and sorting
func (*ChildRepository) ListByParentID ¶
func (r *ChildRepository) ListByParentID(ctx context.Context, parentID uuid.UUID, options ports.QueryOptions) ([]*domain.Child, *ports.PagedResult, error)
ListByParentID retrieves children for a specific parent with pagination, filtering, and sorting
type GenericChildRepository ¶
type GenericChildRepository struct { *BaseRepository[*domain.Child] // contains filtered or unexported fields }
GenericChildRepository implements the ports.Repository interface for Child entities
func NewGenericChildRepository ¶
func NewGenericChildRepository(pool *pgxpool.Pool, logger *zap.Logger) *GenericChildRepository
NewGenericChildRepository creates a new generic child repository
func (*GenericChildRepository) ListByParentID ¶
func (r *GenericChildRepository) ListByParentID(ctx context.Context, parentID uuid.UUID, options ports.QueryOptions) ([]*domain.Child, *ports.PagedResult, error)
ListByParentID retrieves children for a specific parent with pagination, filtering, and sorting
type GenericParentRepository ¶
type GenericParentRepository struct { *BaseRepository[*domain.Parent] // contains filtered or unexported fields }
GenericParentRepository implements the ports.Repository interface for Parent entities
func NewGenericParentRepository ¶
func NewGenericParentRepository(pool *pgxpool.Pool, logger *zap.Logger) *GenericParentRepository
NewGenericParentRepository creates a new generic parent repository
type GenericRepositoryFactory ¶
type GenericRepositoryFactory struct {
// contains filtered or unexported fields
}
GenericRepositoryFactory implements the ports.RepositoryFactory interface using generic repositories
func NewGenericRepositoryFactory ¶
func NewGenericRepositoryFactory(ctx context.Context, connString string, logger *zap.Logger) (*GenericRepositoryFactory, error)
NewGenericRepositoryFactory creates a new generic repository factory
func (*GenericRepositoryFactory) Close ¶
func (f *GenericRepositoryFactory) Close(ctx context.Context) error
Close closes the connection pool
func (*GenericRepositoryFactory) GetGenericChildRepository ¶
func (f *GenericRepositoryFactory) GetGenericChildRepository() ports.Repository[*domain.Child]
GetGenericChildRepository returns the generic child repository
func (*GenericRepositoryFactory) GetGenericParentRepository ¶
func (f *GenericRepositoryFactory) GetGenericParentRepository() ports.Repository[*domain.Parent]
GetGenericParentRepository returns the generic parent repository
func (*GenericRepositoryFactory) GetTransactionManager ¶
func (f *GenericRepositoryFactory) GetTransactionManager() ports.TransactionManager
GetTransactionManager returns the transaction manager
func (*GenericRepositoryFactory) InitSchema ¶
func (f *GenericRepositoryFactory) InitSchema(ctx context.Context) error
InitSchema initializes the database schema
func (*GenericRepositoryFactory) NewChildRepository ¶
func (f *GenericRepositoryFactory) NewChildRepository() ports.ChildRepository
NewChildRepository returns a child repository
func (*GenericRepositoryFactory) NewParentRepository ¶
func (f *GenericRepositoryFactory) NewParentRepository() ports.ParentRepository
NewParentRepository returns a parent repository
type ParentRepository ¶
type ParentRepository struct {
// contains filtered or unexported fields
}
ParentRepository implements the ports.ParentRepository interface for PostgreSQL
func NewParentRepository ¶
func NewParentRepository(pool *pgxpool.Pool, logger *zap.Logger) *ParentRepository
NewParentRepository creates a new PostgreSQL parent repository
func (*ParentRepository) Count ¶
func (r *ParentRepository) Count(ctx context.Context, filter ports.FilterOptions) (int64, error)
Count returns the total count of parents matching the filter
func (*ParentRepository) List ¶
func (r *ParentRepository) List(ctx context.Context, options ports.QueryOptions) ([]*domain.Parent, *ports.PagedResult, error)
List retrieves a list of parents with pagination, filtering, and sorting
type RepositoryFactory ¶
type RepositoryFactory struct {
// contains filtered or unexported fields
}
RepositoryFactory implements the ports.RepositoryFactory interface for PostgreSQL
func NewRepositoryFactory ¶
func NewRepositoryFactory(ctx context.Context, connString string, logger *zap.Logger) (*RepositoryFactory, error)
NewRepositoryFactory creates a new PostgreSQL repository factory
func (*RepositoryFactory) Close ¶
func (f *RepositoryFactory) Close(ctx context.Context) error
Close closes the connection pool
func (*RepositoryFactory) GetTransactionManager ¶
func (f *RepositoryFactory) GetTransactionManager() ports.TransactionManager
GetTransactionManager returns the transaction manager
func (*RepositoryFactory) InitSchema ¶
func (f *RepositoryFactory) InitSchema(ctx context.Context) error
InitSchema initializes the database schema
func (*RepositoryFactory) NewChildRepository ¶
func (f *RepositoryFactory) NewChildRepository() ports.ChildRepository
NewChildRepository returns a child repository
func (*RepositoryFactory) NewParentRepository ¶
func (f *RepositoryFactory) NewParentRepository() ports.ParentRepository
NewParentRepository returns a parent repository
type TransactionManager ¶
type TransactionManager struct {
// contains filtered or unexported fields
}
TransactionManager implements the ports.TransactionManager interface for PostgreSQL
func NewTransactionManager ¶
func NewTransactionManager(pool *pgxpool.Pool, logger *zap.Logger) *TransactionManager
NewTransactionManager creates a new PostgreSQL transaction manager
func (*TransactionManager) CommitTx ¶
func (tm *TransactionManager) CommitTx(ctx context.Context) error
CommitTx commits the transaction stored in the context
func (*TransactionManager) RollbackTx ¶
func (tm *TransactionManager) RollbackTx(ctx context.Context) error
RollbackTx rolls back the transaction stored in the context