db

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Row

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

Row is a helper function that wraps sql rows to scan into a single struct. Row scans structs based on their db tag, and scan any fields not tagged with the db tag matched column name, So had better to tag all fields with db tag to avoid unexpected behavior.

func Rows

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

Rows is a helper function that wraps sql rows to scan into a slice. Rows scans structs based on their db tag, and scan any fields not tagged with the db tag matched column name, So had better to tag all fields with db tag to avoid unexpected behavior.

Types

type Record

type Record = map[string]any

Record is a type alias for map[string]any.

func RowMap

func RowMap(ctx context.Context, db *sql.DB, query string, args ...any) (Record, error)

RowMap is a helper function that wraps sql rows to scan into a single Record. Key of the map is the column name, and value is the column value. It returns the first row of the result set.

func RowsMap

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

RowsMap is a helper function that wraps sql rows to scan into a slice of Record. Key of the map is the column name, and value is the column value.

Jump to

Keyboard shortcuts

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