Documentation
¶
Overview ¶
Package sqlout scans database row data into variables.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Rows ¶
type Rows interface { Next() bool Scan(dest ...any) error Columns() ([]string, error) Close() error Err() error }
Rows are rows returned by a database query.
type Scanner ¶
type Scanner struct { // Tag is the struct tag to map the column name to. Tag string // ColumnTagMap takes a database column name and returns what struct tag it // should match against. ColumnTagMap func(col string) string }
Scanner holds options for scanning.
func (*Scanner) Scan ¶
Scan takes database rows and scans the data into v. v must be a pointer to a basic type, a slice of basic types, a struct, or a slice of basic structs.
Example ¶
// Call sql.Open to get a valid *sql.DB. var db *sql.DB rows, err := db.Query( "SELECT verified, first_name, id FROM user WHERE verified = ?", true, ) if err != nil { // Query failed return } sc := Scanner{Tag: "sql"} var users []struct { ID int `sql:"id"` FirstName string `sql:"first_name"` Verified bool `sql:"verified"` } if err := sc.Scan(rows, &users); err != nil { // Failed to scan values return }
Output:
Click to show internal directories.
Click to hide internal directories.