dbx

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package dbx implements database-related utility functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectRows

func CollectRows[T any](rows *sql.Rows, expected int, ignore func(error) bool) ([]T, error)

CollectRows reads the results of a SQL query.

expected is the expected number of rows. ignore determines which sql.Rows.Scan errors should be ignored.

If T is a struct, the columns of each row are assigned to visible fields of T.

T must not be a pointer.

func QueryCollect

func QueryCollect[T any](
	ctx context.Context,
	db *sql.DB,
	query string,
	args ...any,
) ([]T, error)

QueryCollect runs a SQL query.

The columns of each row are assigned to visible fields of T.

func QueryCollectCountIgnore

func QueryCollectCountIgnore[T any](
	ctx context.Context,
	db *sql.DB,
	count int,
	ignore func(error) bool,
	query string,
	args ...any,
) ([]T, error)

QueryCollectCountIgnore runs a SQL query.

count is the expected number of rows. ignore determines which sql.Rows.Scan errors should be ignored.

The columns of each row are assigned to visible fields of T.

func QueryCollectIgnore

func QueryCollectIgnore[T any](
	ctx context.Context,
	db *sql.DB,
	ignore func(error) bool,
	query string,
	args ...any,
) ([]T, error)

QueryCollectIgnore runs a SQL query.

ignore determines which sql.Rows.Scan errors should be ignored.

The columns of each row are assigned to visible fields of T.

func QueryScan

func QueryScan[T any](
	ctx context.Context,
	collect func(T),
	ignore func(error) bool,
	db *sql.DB,
	query string,
	args ...any,
) error

QueryScan is like ScanRows but also runs the query.

func ScanRows

func ScanRows[T any](
	rows *sql.Rows,
	collect func(T),
	ignore func(error) bool,
) error

ScanRows calls a function for every result of a SQL query.

collect is called for each row. ignore determines which sql.Rows.Scan errors should be ignored.

If T is a struct or a struct pointer, the columns of each row are assigned to visible fields of T.

If T is a struct pointer, collect receives the same pointer every time it's called. It must not store the pointer to the struct or its fields.

Types

This section is empty.

Jump to

Keyboard shortcuts

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