db

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package db provides database connection management for sql-http-proxy.

Index

Constants

View Source
const ConnectTimeout = 10 * time.Second

ConnectTimeout is the timeout for validating database connection.

Variables

This section is empty.

Functions

func BindParams

func BindParams(db *sqlx.DB, query string, params map[string]any) (string, []any, error)

BindParams binds named parameters and rebinds for the driver.

func Connect

func Connect(cfg config.Config, configDir string) (*sqlx.DB, error)

Connect establishes a database connection based on the configuration. Returns nil if the configuration doesn't require a database connection. Validates the connection with a ping before returning. If database.init is configured, executes the init SQL after connecting. configDir is used to resolve relative paths in sql_files.

func QueryMany

func QueryMany(ctx context.Context, db *sqlx.DB, query string, args ...any) ([]map[string]any, error)

QueryMany executes a query expecting multiple rows.

func QueryOne

func QueryOne(ctx context.Context, db *sqlx.DB, query string, args ...any) (map[string]any, error)

QueryOne executes a query expecting a single row. Returns nil (not error) when no rows found.

Types

type ExecResult

type ExecResult struct {
	LastInsertId *int64 // nil if not available (non-MySQL drivers)
	RowsAffected int64
}

ExecResult holds the result of an exec operation.

func Exec

func Exec(ctx context.Context, db *sqlx.DB, query string, args ...any) (*ExecResult, error)

Exec executes a query without returning rows. For MySQL, it returns the last insert ID. For other drivers, LastInsertId is nil.

Jump to

Keyboard shortcuts

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