runtime

package
v1.16.5 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package runtime provides runtime utilities for the ORM.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when a record is not found.
	ErrNotFound = errors.New("record not found")

	// ErrInvalidModel is returned when an invalid model is provided.
	ErrInvalidModel = errors.New("invalid model")

	// ErrNoPrimaryKey is returned when a table has no primary key.
	ErrNoPrimaryKey = errors.New("no primary key defined")

	// ErrDuplicateKey is returned when a unique constraint is violated.
	ErrDuplicateKey = errors.New("duplicate key value")

	// ErrForeignKeyViolation is returned when a foreign key constraint is violated.
	ErrForeignKeyViolation = errors.New("foreign key violation")

	// ErrInvalidType is returned when a type conversion fails.
	ErrInvalidType = errors.New("invalid type")

	// ErrTransactionClosed is returned when operating on a closed transaction.
	ErrTransactionClosed = errors.New("transaction already closed")

	// ErrNoConnection is returned when no database connection is available.
	ErrNoConnection = errors.New("no database connection")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Host     string
	Port     int
	Database string
	User     string
	Password string
	SSLMode  string
	MaxConns int32
	MinConns int32
}

Config represents database configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default database configuration.

type DB

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

DB represents a database connection.

func Connect

func Connect(ctx context.Context, config *Config) (*DB, error)

Connect creates a new DB instance by connecting to PostgreSQL.

func ConnectWithURL

func ConnectWithURL(ctx context.Context, url string) (*DB, error)

ConnectWithURL creates a new DB instance using a connection URL.

func NewDB

func NewDB(pool *pgxpool.Pool) *DB

NewDB creates a new DB instance from a connection pool.

func (*DB) Begin

func (db *DB) Begin(ctx context.Context) (pgx.Tx, error)

Begin starts a new transaction.

func (*DB) BeginTx

func (db *DB) BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)

BeginTx starts a new transaction with options.

func (*DB) Close

func (db *DB) Close()

Close closes the database connection pool.

func (*DB) Exec

func (db *DB) Exec(ctx context.Context, sql string, args ...any) (int64, error)

Exec executes a query without returning any rows.

func (*DB) Ping

func (db *DB) Ping(ctx context.Context) error

Ping verifies the database connection is alive.

func (*DB) Pool

func (db *DB) Pool() *pgxpool.Pool

Pool returns the underlying pgxpool.Pool.

func (*DB) Query

func (db *DB) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)

Query executes a query that returns rows.

func (*DB) QueryRow

func (db *DB) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row

QueryRow executes a query that returns at most one row.

type MigrationError

type MigrationError struct {
	Version string
	Message string
	Err     error
}

MigrationError represents a migration error.

func (*MigrationError) Error

func (e *MigrationError) Error() string

Error implements the error interface.

func (*MigrationError) Unwrap

func (e *MigrationError) Unwrap() error

Unwrap returns the underlying error.

type QueryError

type QueryError struct {
	Query string
	Err   error
}

QueryError represents a query execution error.

func (*QueryError) Error

func (e *QueryError) Error() string

Error implements the error interface.

func (*QueryError) Unwrap

func (e *QueryError) Unwrap() error

Unwrap returns the underlying error.

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError represents a validation error.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error implements the error interface.

Jump to

Keyboard shortcuts

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