Documentation
¶
Overview ¶
Package database provides database abstraction and migration support for program-director.
Index ¶
- type DB
- type Migration
- type PostgresDB
- func (p *PostgresDB) BeginTx(ctx context.Context) (Tx, error)
- func (p *PostgresDB) Close() error
- func (p *PostgresDB) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (p *PostgresDB) Migrate(ctx context.Context) error
- func (p *PostgresDB) Ping(ctx context.Context) error
- func (p *PostgresDB) Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (p *PostgresDB) QueryRow(ctx context.Context, query string, args ...interface{}) *sql.Row
- type PostgresTx
- func (t *PostgresTx) Commit() error
- func (t *PostgresTx) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (t *PostgresTx) Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (t *PostgresTx) QueryRow(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (t *PostgresTx) Rollback() error
- type SQLiteDB
- func (s *SQLiteDB) BeginTx(ctx context.Context) (Tx, error)
- func (s *SQLiteDB) Close() error
- func (s *SQLiteDB) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (s *SQLiteDB) Migrate(ctx context.Context) error
- func (s *SQLiteDB) Ping(ctx context.Context) error
- func (s *SQLiteDB) Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (s *SQLiteDB) QueryRow(ctx context.Context, query string, args ...interface{}) *sql.Row
- type SQLiteTx
- func (t *SQLiteTx) Commit() error
- func (t *SQLiteTx) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (t *SQLiteTx) Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (t *SQLiteTx) QueryRow(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (t *SQLiteTx) Rollback() error
- type Tx
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB interface {
// Core operations
Close() error
Ping(ctx context.Context) error
// Transaction support
BeginTx(ctx context.Context) (Tx, error)
// Query operations
Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryRow(ctx context.Context, query string, args ...interface{}) *sql.Row
Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
// Migration
Migrate(ctx context.Context) error
}
DB is the interface for database operations
type PostgresDB ¶
type PostgresDB struct {
// contains filtered or unexported fields
}
PostgresDB implements DB interface for PostgreSQL
func NewPostgres ¶
func NewPostgres(ctx context.Context, cfg *config.PostgresConfig, logger *slog.Logger) (*PostgresDB, error)
NewPostgres creates a new PostgreSQL connection
func (*PostgresDB) BeginTx ¶
func (p *PostgresDB) BeginTx(ctx context.Context) (Tx, error)
BeginTx starts a new transaction
func (*PostgresDB) Exec ¶
func (p *PostgresDB) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
Exec executes a query that doesn't return rows
func (*PostgresDB) Migrate ¶
func (p *PostgresDB) Migrate(ctx context.Context) error
Migrate runs all pending migrations
func (*PostgresDB) Ping ¶
func (p *PostgresDB) Ping(ctx context.Context) error
Ping checks if the database connection is alive
type PostgresTx ¶
type PostgresTx struct {
// contains filtered or unexported fields
}
PostgresTx wraps sql.Tx to implement Tx interface
func (*PostgresTx) Exec ¶
func (t *PostgresTx) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
Exec executes a query without returning any rows
func (*PostgresTx) Query ¶
func (t *PostgresTx) Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
Query executes a query that returns rows
func (*PostgresTx) Rollback ¶
func (t *PostgresTx) Rollback() error
Rollback rolls back the transaction
type SQLiteDB ¶
type SQLiteDB struct {
// contains filtered or unexported fields
}
SQLiteDB implements DB interface for SQLite
func NewSQLite ¶
func NewSQLite(ctx context.Context, cfg *config.SQLiteConfig, logger *slog.Logger) (*SQLiteDB, error)
NewSQLite creates a new SQLite connection
type SQLiteTx ¶
type SQLiteTx struct {
// contains filtered or unexported fields
}
SQLiteTx wraps sql.Tx to implement Tx interface
type Tx ¶
type Tx interface {
Commit() error
Rollback() error
Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryRow(ctx context.Context, query string, args ...interface{}) *sql.Row
Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}
Tx represents a database transaction
Directories
¶
| Path | Synopsis |
|---|---|
|
Package repository provides database repository implementations for media, history, and cooldowns.
|
Package repository provides database repository implementations for media, history, and cooldowns. |