vendor dependencies with dep
This commit is contained in:
parent
93d8310491
commit
1384296a47
2712 changed files with 965742 additions and 0 deletions
47
vendor/github.com/go-pg/pg/example_hstore_test.go
generated
vendored
Normal file
47
vendor/github.com/go-pg/pg/example_hstore_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package pg_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-pg/pg"
|
||||
)
|
||||
|
||||
func ExampleDB_Model_hstoreStructTag() {
|
||||
type Item struct {
|
||||
Id int64
|
||||
Attrs map[string]string `pg:",hstore"` // marshalled as PostgreSQL hstore
|
||||
}
|
||||
|
||||
_, err := db.Exec(`CREATE TEMP TABLE items (id serial, attrs hstore)`)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer db.Exec("DROP TABLE items")
|
||||
|
||||
item1 := Item{
|
||||
Id: 1,
|
||||
Attrs: map[string]string{"hello": "world"},
|
||||
}
|
||||
if err := db.Insert(&item1); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var item Item
|
||||
err = db.Model(&item).Where("id = ?", 1).Select()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(item)
|
||||
// Output: {1 map[hello:world]}
|
||||
}
|
||||
|
||||
func ExampleHstore() {
|
||||
src := map[string]string{"hello": "world"}
|
||||
var dst map[string]string
|
||||
_, err := db.QueryOne(pg.Scan(pg.Hstore(&dst)), `SELECT ?`, pg.Hstore(src))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(dst)
|
||||
// Output: map[hello:world]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue