database

package
v0.0.0-...-85ddada Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

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 (pdb *PostgresDatabase) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

func (*PostgresDatabase) QueryContext

func (pdb *PostgresDatabase) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)

func (*PostgresDatabase) QueryRowContext

func (pdb *PostgresDatabase) QueryRowContext(ctx context.Context, query string, args ...any) (*sql.Row, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL