Documentation
¶
Index ¶
- Variables
- func CloseConnection() error
- func FilterSearch(q *bun.SelectQuery, search string, fields ...string)
- func GetDB() *bun.DB
- func NewConnection(c *Config, l *zap.Logger) (err error)
- func RequestSort(sort []string) string
- type BaseRepository
- func (r *BaseRepository[T]) FindAll(opts *common.QueryOption, customQuery CustomQueryFn) ([]*T, int64, error)
- func (r *BaseRepository[T]) FindByID(id any) (*T, error)
- func (r *BaseRepository[T]) FindOne(customQuery CustomQueryFn) (*T, error)
- func (r *BaseRepository[T]) Insert(entity *T) error
- func (r *BaseRepository[T]) SoftDelete(id any) error
- func (r *BaseRepository[T]) Update(entity *T, fields ...string) error
- func (r *BaseRepository[T]) WithContext(ctx context.Context) common.BaseRepositoryInterface[T]
- type Client
- type Config
- type CustomQueryFn
- type ZapQueryHook
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrClientNotInitialized = errors.New("db client not initialized; call NewConnection first")
)
internal shared client singleton
Functions ¶
func CloseConnection ¶
func CloseConnection() error
CloseConnection closes the default client connection.
func FilterSearch ¶
func FilterSearch(q *bun.SelectQuery, search string, fields ...string)
FilterSearch adds a case-insensitive search filter for the given fields.
func GetDB ¶
GetDB returns the globally initialized *bun.DB instance. You should call NewConnection first before calling GetDB.
func NewConnection ¶
NewConnection initializes a new Bun DB connection and sets it as the default. It also adds a zap logger hook and optionally a verbose logger if debug is true.
func RequestSort ¶
Types ¶
type BaseRepository ¶
type BaseRepository[T any] struct { DB *bun.DB Context context.Context // contains filtered or unexported fields }
func NewBaseRepository ¶
func (*BaseRepository[T]) FindAll ¶
func (r *BaseRepository[T]) FindAll(opts *common.QueryOption, customQuery CustomQueryFn) ([]*T, int64, error)
func (*BaseRepository[T]) FindByID ¶
func (r *BaseRepository[T]) FindByID(id any) (*T, error)
func (*BaseRepository[T]) FindOne ¶
func (r *BaseRepository[T]) FindOne(customQuery CustomQueryFn) (*T, error)
func (*BaseRepository[T]) Insert ¶
func (r *BaseRepository[T]) Insert(entity *T) error
func (*BaseRepository[T]) SoftDelete ¶
func (r *BaseRepository[T]) SoftDelete(id any) error
func (*BaseRepository[T]) Update ¶
func (r *BaseRepository[T]) Update(entity *T, fields ...string) error
func (*BaseRepository[T]) WithContext ¶
func (r *BaseRepository[T]) WithContext(ctx context.Context) common.BaseRepositoryInterface[T]
type Config ¶
type Config struct {
Server string // Host or IP of the Postgres server
Username string // Database username
Password string // Database password
Database string // Database name
Datasource string // Full DSN string (overrides Server/Username/Password/Database)
}
Config holds the configuration parameters for connecting to a PostgreSQL database.
func ConfigDefault ¶
ConfigDefault creating an config readed from .env file make sure you load the env file in your init app
type CustomQueryFn ¶
type CustomQueryFn func(q *bun.SelectQuery) *bun.SelectQuery
type ZapQueryHook ¶
func (*ZapQueryHook) AfterQuery ¶
func (h *ZapQueryHook) AfterQuery(ctx context.Context, event *bun.QueryEvent)
func (*ZapQueryHook) BeforeQuery ¶
func (h *ZapQueryHook) BeforeQuery(ctx context.Context, event *bun.QueryEvent) context.Context
Click to show internal directories.
Click to hide internal directories.