Documentation
¶
Index ¶
- Variables
- type DBHandle
- func (s *DBHandle[T]) Close() error
- func (s *DBHandle[T]) Maintenance(d time.Duration, f MaintenanceFunction) error
- func (s *DBHandle[T]) Open(ctx context.Context) error
- func (s *DBHandle[T]) Ping() error
- func (s *DBHandle[T]) Statement(key T, generator StatementGenerator) (*sql.Stmt, error)
- func (s *DBHandle[T]) StopMaintenance()
- func (s DBHandle[T]) String() string
- type DatabaseOptions
- type DriverName
- type MaintenanceFunction
- type StatementGenerator
Constants ¶
This section is empty.
Variables ¶
var ( ErrDatabaseNotOpen = errors.New("database not opened") ErrDatabaseAlreadyOpen = errors.New("database already opened") ErrDatabaseClosed = errors.New("database closed") ErrCantResetMaintenance = errors.New("can't reset maintenance ticker") ErrInvalidDuration = errors.New("invalid duration for maintenance ticker") MinMaintenanceInterval = 1 * time.Minute )
Functions ¶
This section is empty.
Types ¶
type DBHandle ¶
type DBHandle[T comparable] struct { Ctx context.Context DB *sql.DB Driver DriverName DSNSource DatabaseOptions // contains filtered or unexported fields }
func (*DBHandle[T]) Close ¶
Close will be called when the context passed to Open() is cancelled. It can also be called manually to release resources. It will close the database handle and any prepared statements, and stop any maintenance jobs.
func (*DBHandle[T]) Maintenance ¶
func (s *DBHandle[T]) Maintenance(d time.Duration, f MaintenanceFunction) error
Pass a maintenance function and a duration to run it at. The maintenance function will be called with the context and the database handle. If the function returns an error, the ticker will be stopped. If the duration is 0 or less than a second, an error will be returned. It is possible to set up multiple maintenance functions. The Maintenance ticker will be stopped when this DBHandle is closed, or with a StopMaintenance() call.
func (*DBHandle[T]) Statement ¶
func (s *DBHandle[T]) Statement(key T, generator StatementGenerator) (*sql.Stmt, error)
func (*DBHandle[T]) StopMaintenance ¶ added in v0.6.5
func (s *DBHandle[T]) StopMaintenance()
type DatabaseOptions ¶ added in v0.7.0
type DriverName ¶
type DriverName string
const ( SQLite DriverName = "sqlite3" MySQL DriverName = "mysql" )
type MaintenanceFunction ¶
MaintenanceFunction is a function that can be called periodically to perform maintenance on the database. It's passed the context and current database handle. Returning an error will stop the maintenance ticker.