columns

package module
v0.0.0-...-f9dec97 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RowsWithColumns

type RowsWithColumns struct {
	*sql.Rows
	// contains filtered or unexported fields
}

RowsWithColumns : holds the info about sql.Row fields

Example
// open database
db, err := sql.Open("sqlite3", "sql_test.db")
if err != nil {
	fmt.Println(err)
	return
}
defer db.Close()
// query
rows, err := db.Query("SELECT * FROM quotes LIMIT 1")
if err != nil {
	fmt.Println(err)
	return
}
defer rows.Close()
// promote sql.Rows in columns.RowsWithColumns
rh, err := New(rows)
if err != nil {
	fmt.Println(err)
	return
}
// 1st row
if rh.Next() {
	fmt.Println(rh.Length())
}
Output:
4

func New

func New(rows *sql.Rows) (*RowsWithColumns, error)

New : build a RowsWithColumns struct from a database/sql.Rows

func (RowsWithColumns) GetFieldByIndex

func (rh RowsWithColumns) GetFieldByIndex(index int) (string, interface{}, error)

GetFieldByIndex : find a field By index. Return name, value and error

func (RowsWithColumns) GetFieldByName

func (rh RowsWithColumns) GetFieldByName(name string) (int, interface{}, error)

GetFieldByName : find a field By name. Returns index, value and error

func (RowsWithColumns) GetStringFieldByIndex

func (rh RowsWithColumns) GetStringFieldByIndex(index int) (string, string, error)

GetStringFieldByIndex : find a field By index. Return name, value as string and error

func (RowsWithColumns) Length

func (rh RowsWithColumns) Length() int

Length : number of fields of the result set

func (*RowsWithColumns) Next

func (rh *RowsWithColumns) Next() bool

Next : read the bytes of the current row

Jump to

Keyboard shortcuts

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