update
This commit is contained in:
parent
2b17fa04be
commit
5332a4592b
84
vendor/git.trj.tw/golang/utils/main.go
vendored
Normal file
84
vendor/git.trj.tw/golang/utils/main.go
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
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)
|
||||
}
|
||||
}
|
6
vendor/vendor.json
vendored
6
vendor/vendor.json
vendored
@ -2,6 +2,12 @@
|
||||
"comment": "",
|
||||
"ignore": "test",
|
||||
"package": [
|
||||
{
|
||||
"checksumSHA1": "/tt3GCCkDiN+tineQHLBsR3wamo=",
|
||||
"path": "git.trj.tw/golang/utils",
|
||||
"revision": "4b015522fecd284d6bbfa7626b604eb2956526e5",
|
||||
"revisionTime": "2018-04-25T07:53:26Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "u2K9MAPCGFCro6yQZEjOIBcQjXo=",
|
||||
"path": "git.trj.tw/golang/utils/dbtool",
|
||||
|
Loading…
Reference in New Issue
Block a user