update vendor
This commit is contained in:
parent
5332a4592b
commit
0da02160f0
@ -25,6 +25,7 @@ func ScanToStruct(rows *sql.Rows, ss interface{}) (ok bool, err error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ScanToStructAll -
|
||||||
func ScanToStructAll(rows *sql.Rows, ss interface{}) error {
|
func ScanToStructAll(rows *sql.Rows, ss interface{}) error {
|
||||||
sliceVal := reflect.Indirect(reflect.ValueOf(ss))
|
sliceVal := reflect.Indirect(reflect.ValueOf(ss))
|
||||||
if sliceVal.Kind() != reflect.Slice {
|
if sliceVal.Kind() != reflect.Slice {
|
||||||
@ -53,6 +54,7 @@ func ScanToStructAll(rows *sql.Rows, ss interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ResultToMap -
|
||||||
func ResultToMap(r *sql.Rows) ([]map[string]interface{}, error) {
|
func ResultToMap(r *sql.Rows) ([]map[string]interface{}, error) {
|
||||||
result := make([]map[string]interface{}, 0)
|
result := make([]map[string]interface{}, 0)
|
||||||
cols, err := r.Columns()
|
cols, err := r.Columns()
|
||||||
@ -74,6 +76,7 @@ func ResultToMap(r *sql.Rows) ([]map[string]interface{}, error) {
|
|||||||
}
|
}
|
||||||
for i, v := range vals {
|
for i, v := range vals {
|
||||||
tmp[cols[i]] = v
|
tmp[cols[i]] = v
|
||||||
|
vals[i] = nil
|
||||||
}
|
}
|
||||||
result = append(result, tmp)
|
result = append(result, tmp)
|
||||||
}
|
}
|
||||||
@ -81,6 +84,7 @@ func ResultToMap(r *sql.Rows) ([]map[string]interface{}, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MapToStruct -
|
||||||
func MapToStruct(data map[string]interface{}, out interface{}) error {
|
func MapToStruct(data map[string]interface{}, out interface{}) error {
|
||||||
ss := reflect.ValueOf(out).Elem()
|
ss := reflect.ValueOf(out).Elem()
|
||||||
for i := 0; i < ss.NumField(); i++ {
|
for i := 0; i < ss.NumField(); i++ {
|
||||||
|
84
vendor/git.trj.tw/golang/utils/main.go
vendored
84
vendor/git.trj.tw/golang/utils/main.go
vendored
@ -1,84 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"git.trj.tw/golang/utils/dbtool"
|
|
||||||
_ "github.com/lib/pq"
|
|
||||||
)
|
|
||||||
|
|
||||||
// FileT - file db schema
|
|
||||||
type FileT struct {
|
|
||||||
ID string `sql:"id"`
|
|
||||||
Name string `sql:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
connStr := "postgres://postgres@localhost:5432/gallery?sslmode=disable"
|
|
||||||
db, err := sql.Open("postgres", connStr)
|
|
||||||
handleError(err)
|
|
||||||
defer db.Close()
|
|
||||||
|
|
||||||
result, err := db.Query(`insert into "public"."account" ("account", "password", "nick", "email") values ($1, $2, $3, $4) returning *`, "aaaaa", "bbbb", "cccc", "dddd")
|
|
||||||
handleError(err)
|
|
||||||
defer result.Close()
|
|
||||||
|
|
||||||
dd, err := dbtool.ResultToMap(result)
|
|
||||||
handleError(err)
|
|
||||||
|
|
||||||
fmt.Println(dd)
|
|
||||||
|
|
||||||
// var id, name string
|
|
||||||
// for rows.Next() {
|
|
||||||
// rows.Scan(&id, &name)
|
|
||||||
// fmt.Printf("id: %s, name: %s \n", id, name)
|
|
||||||
// }
|
|
||||||
// var fts []FileT
|
|
||||||
// err := ttt(&fts)
|
|
||||||
// handleError(err)
|
|
||||||
|
|
||||||
// fmt.Println(fts[0].Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ttt(dest interface{}) error {
|
|
||||||
vv := reflect.Indirect(reflect.ValueOf(dest))
|
|
||||||
fmt.Println(vv)
|
|
||||||
|
|
||||||
vt := vv.Type().Elem()
|
|
||||||
fmt.Println(vt)
|
|
||||||
|
|
||||||
fmt.Println("test :::::::::")
|
|
||||||
pv := reflect.New(vt)
|
|
||||||
fmt.Println(pv.Kind(), pv.Elem().Kind(), pv.Type())
|
|
||||||
|
|
||||||
// fmt.Println(pv.Elem().Type().Field(0).Name)
|
|
||||||
|
|
||||||
pve := pv.Interface()
|
|
||||||
|
|
||||||
// fmt.Println(reflect.ValueOf(pv.Interface()).Elem().NumField())
|
|
||||||
d := make(map[string]interface{})
|
|
||||||
d["id"] = sql.RawBytes{0x30}
|
|
||||||
d["name"] = sql.RawBytes{0x31, 0x32}
|
|
||||||
|
|
||||||
err := dbtool.MapToStruct(d, pve)
|
|
||||||
handleError(err)
|
|
||||||
|
|
||||||
fmt.Println(pve)
|
|
||||||
|
|
||||||
// for i := 0; i < pve.NumField(); i++ {
|
|
||||||
// fmt.Println(pve.Type().Field(i).Name)
|
|
||||||
// }
|
|
||||||
vv.Set(reflect.Append(vv, reflect.ValueOf(pve).Elem()))
|
|
||||||
fmt.Println("test :::::::::")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleError(err error) {
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
12
vendor/vendor.json
vendored
12
vendor/vendor.json
vendored
@ -3,16 +3,16 @@
|
|||||||
"ignore": "test",
|
"ignore": "test",
|
||||||
"package": [
|
"package": [
|
||||||
{
|
{
|
||||||
"checksumSHA1": "/tt3GCCkDiN+tineQHLBsR3wamo=",
|
"checksumSHA1": "2ngfNw/Z9bjxYx1Za5D028eS/BU=",
|
||||||
"path": "git.trj.tw/golang/utils",
|
"path": "git.trj.tw/golang/utils",
|
||||||
"revision": "4b015522fecd284d6bbfa7626b604eb2956526e5",
|
"revision": "117c17b0294c4e46bfc8ae56791326300401b1ab",
|
||||||
"revisionTime": "2018-04-25T07:53:26Z"
|
"revisionTime": "2018-04-25T07:56:22Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "u2K9MAPCGFCro6yQZEjOIBcQjXo=",
|
"checksumSHA1": "8/7wIcmSm/zpybUmLYSgm2izqpc=",
|
||||||
"path": "git.trj.tw/golang/utils/dbtool",
|
"path": "git.trj.tw/golang/utils/dbtool",
|
||||||
"revision": "4749bdbad30363c8938cffb864637876403a7a38",
|
"revision": "117c17b0294c4e46bfc8ae56791326300401b1ab",
|
||||||
"revisionTime": "2018-04-20T06:34:49Z"
|
"revisionTime": "2018-04-25T07:56:22Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "8682CypcUWdUlGSK8C2DGB/CcTk=",
|
"checksumSHA1": "8682CypcUWdUlGSK8C2DGB/CcTk=",
|
||||||
|
Loading…
Reference in New Issue
Block a user