README
¶
sqlstruct
This is a modified version of http://go.pkgdoc.org/github.com/kisielk/sqlstruct.
It adds support for embedded structs and adds a slightly different type info cache.
Basic use:
// struct to represent a query from bar
type Rows struct {
Name string `sql:"name_attr"`
Id int64 `sql:"@id"`
...
}
// Create a new session - this will also maintain a type info cache
// so it's beneficial for complex structs
s := sqlstruct.NewSession()
r := Rows{}
db := sql.Open(...)
dbquery := "select * from bar"
rows := mustQuery(db, dbquery)
for rows.Next() {
s.MustScan(&r, rows)
// do something with the Rows data in r
}
sqlstruct provides some convenience functions for using structs with go's database/sql package
Documentation can be found via godoc or at http://go.pkgdoc.org/github.com/kisielk/sqlstruct
Documentation
¶
Overview ¶
Package sqlstruct provides some convenience functions for using structs with the Go standard library's database/sql package.
The package works with structs that are tagged with a "sql" tag that identifies which column of a SQL query the field corresponds to.
For example:
type T struct { F1 string `sql:"f1"` F2 string `sql:"f2"` } rows, err := db.Query(fmt.Sprintf("SELECT %s FROM tablename", sqlstruct.Columns(T))) ... for rows.Next() { var t T err = sqlstruct.Scan(&t, rows) ... } err = rows.Err() // get any errors encountered during iteration
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Rows ¶
Rows defines the interface of types that are scannable with the Scan function. It is implemented by the sql.Rows type from the standard library
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func NewSession ¶
func NewSession() *Session