Documentation
¶
Index ¶
- type Database
- type PostgresDatabase
- func (pdb *PostgresDatabase) Close() error
- func (pdb *PostgresDatabase) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (pdb *PostgresDatabase) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (pdb *PostgresDatabase) QueryRowContext(ctx context.Context, query string, args ...any) (*sql.Row, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database interface {
// ExecContext executes a query that doesn't return rows.
// It should be used for INSERT, UPDATE, DELETE, and other non-query SQL statements.
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
// QueryRowContext retrieves a single row from the database.
// It should be used for querying a single row result.
QueryRowContext(ctx context.Context, query string, args ...any) (*sql.Row, error)
// QueryContext executes a query that returns multiple rows.
// It should be used for querying multiple rows of data.
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
// Close closes the database connection.
// It should be called when you're done using the database to release resources.
Close() error
}
Database is an interface that defines the methods required for interacting with a database.
type PostgresDatabase ¶
type PostgresDatabase struct {
// contains filtered or unexported fields
}
PostgresDatabase implements the Database interface for PostgreSQL.
func NewPostgresDatabase ¶
func NewPostgresDatabase(ctx context.Context, connectionString string) (*PostgresDatabase, error)
NewPostgresDatabase creates a new PostgresDatabase instance with the connection string and context. It establishes a connection to the PostgreSQL database and verifies its availability.
func (*PostgresDatabase) Close ¶
func (pdb *PostgresDatabase) Close() error
func (*PostgresDatabase) ExecContext ¶
func (*PostgresDatabase) QueryContext ¶
func (*PostgresDatabase) QueryRowContext ¶
Click to show internal directories.
Click to hide internal directories.