db

package
v0.385.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PgNotNullConstraintViolation    = "23502"
	PgForeignKeyConstraintViolation = "23503"
	PgUniqueConstraintViolation     = "23505"
)

Functions

func QuoteIdentifier

func QuoteIdentifier(name string) string

func QuoteLiteral

func QuoteLiteral(literal string) string

func WithDatabase added in v0.368.0

func WithDatabase(ctx context.Context, database Database) context.Context

Types

type ConnectionInfo

type ConnectionInfo struct {
	Host     string
	Port     string
	Username string
	Password string
	Database string
}

func (*ConnectionInfo) ServerString

func (dbConnInfo *ConnectionInfo) ServerString() string

func (*ConnectionInfo) String

func (dbConnInfo *ConnectionInfo) String() string

func (*ConnectionInfo) WithDatabase

func (dbConnInfo *ConnectionInfo) WithDatabase(database string) *ConnectionInfo

type Database

type Database interface {
	// Executes SQL query statement and returns rows.
	ExecuteQuery(ctx context.Context, sql string, args ...any) (*ExecuteQueryResult, error)
	// Executes SQL statement and returns number of rows affected.
	ExecuteStatement(ctx context.Context, sql string, args ...any) (*ExecuteStatementResult, error)
	// Runs fn inside a transaction which is commited if fn returns a nil error
	Transaction(ctx context.Context, fn func(ctx context.Context) error) error
	Close() error
	GetDB() *gorm.DB
}

func GetDatabase added in v0.368.0

func GetDatabase(ctx context.Context) (Database, error)

func New

func New(ctx context.Context, connString string) (Database, error)

type DbError

type DbError struct {
	// if the error was associated with a specific table, the name of the table
	Table string
	// if the error was associated with specific table columns, the names of these columns
	Columns []string
	// the primary human-readable error message. This should be accurate but terse (typically one line). Always present
	Message string
	// the SQLSTATE code for the error - https://www.postgresql.org/docs/current/errcodes-appendix.html. Always present
	PgErrCode string
	// the underlying error
	Err error
}

func (*DbError) Error

func (err *DbError) Error() string

func (*DbError) Unwrap

func (err *DbError) Unwrap() error

type ExecuteQueryResult

type ExecuteQueryResult struct {
	Rows []map[string]any
}

type ExecuteStatementResult

type ExecuteStatementResult struct {
	RowsAffected int64
}

type GormDB

type GormDB struct {
	// contains filtered or unexported fields
}

func (*GormDB) Close

func (db *GormDB) Close() error

func (*GormDB) ExecuteQuery

func (db *GormDB) ExecuteQuery(ctx context.Context, sqlQuery string, args ...any) (*ExecuteQueryResult, error)

func (*GormDB) ExecuteStatement

func (db *GormDB) ExecuteStatement(ctx context.Context, sqlQuery string, args ...any) (*ExecuteStatementResult, error)

func (*GormDB) GetDB

func (db *GormDB) GetDB() *gorm.DB

func (*GormDB) Transaction

func (db *GormDB) Transaction(ctx context.Context, fn func(context.Context) error) error

Jump to

Keyboard shortcuts

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