You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
stardb/reflect_test.go

56 lines
1.2 KiB
Go

package stardb
import (
"fmt"
"testing"
)
type Useless struct {
Leader string `db:"leader"`
Usable bool `db:"use"`
O *Whoami `db:"---"`
Data []byte `db:"data"`
}
type Whoami struct {
Hehe string `db:"hehe"`
}
func TestUpInOrm(t *testing.T) {
var hehe = Useless{
Leader: "no",
Usable: false,
}
sqlstr, param, err := getUpdateSentence(hehe, "ryz", "leader")
fmt.Println(sqlstr, param, err)
sqlstr, param, err = getInsertSentence(hehe, "ryz", "use")
fmt.Println(sqlstr, param, err)
}
func Test_SetRefVal(t *testing.T) {
var hehe = Useless{
Leader: "no",
Data: []byte{1, 2, 3},
}
fmt.Printf("%+v\n", hehe)
fmt.Println(setRefValue(&hehe, "db", "leader", "sb"))
fmt.Printf("%+v\n", hehe)
fmt.Println(getAllRefKey(hehe, "db"))
fmt.Println(getAllRefValue(hehe, "db"))
fmt.Println(setRefValue(&hehe, "db", "data", []byte{4, 5, 6, 7, 8}))
fmt.Printf("%+v\n", hehe)
fmt.Println(getAllRefKey(hehe, "db"))
fmt.Println(getAllRefValue(hehe, "db"))
}
func Test_Ref(t *testing.T) {
oooooo := Useless{
Leader: "Heheeee",
}
oooooo.O = &Whoami{"fuck"}
fmt.Println(getAllRefKey(oooooo, "db"))
fmt.Println(getAllRefValue(oooooo, "db"))
fmt.Println(getAllRefValue(&oooooo, "db"))
}