Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Error ¶
Error checks the error with SQL error codes and returns a storage error if it is nill it returns nil
func IsNotFound ¶
Types ¶
type DB ¶
type DB interface {
// Ping checks if the database is alive
Ping() error
// Close closes the database connection
Close() error
// Begin starts a new transaction
Beginx() (*sqlx.Tx, error)
Reader
Writer
}
DB defines an interface for a database connection with restricive minimum methods fro SQLX
type Reader ¶
type Reader interface {
// SelectContext gets a single row from the database
GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
// SelectContext gets multiple rows from the database
SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
}
Reader defines an interface for a database connection with read methods. This is used to define a read-only connection. This helps to prevent accidental writes to the database when a read-only connection is used and moving the read operations to a separate database for performance reasons like read replicas.
type Writer ¶
type Writer interface {
// NamedExecContext executes a query without returning any rows
NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)
// ExecContext executes a query without returning any rows
ExecContext(context.Context, string, ...any) (sql.Result, error)
}
Writer defines an interface for a database connection with write methods. This is used to define a write-only connection. This helps with moving the write operations to a separate database for performance reasons.