func TestFindTemplateTsB(t *testing.T) { tpl := TCFind.GetTemplate(reflect.TypeOf(tsB{})) tran := trans.NewTransaction(pool) tpl.Engrave(&tran.Actions, "gomdise.tsB:0b4063db-81ae-46cc-99e3-b64863caf0ce") fmt.Println(tran.Actions) tran.Exec() }
func TestSaveTemplateTsB(t *testing.T) { tsB := MakeTsB() tpl := TCSave.GetTemplate(reflect.TypeOf(tsB)) trans := trans.NewTransaction(pool) tpl.Engrave(&trans.Actions, mdl.NewKey(reflect.ValueOf(tsB)), reflect.ValueOf(tsB)) printActions(trans.Actions) trans.Exec() }
func (gom *Gomdise) SaveWithKey(arg interface{}, key string) (err error) { defer func() { err = errorRecover() }() tpl := tpl.TCSave.GetTemplate(reflect.TypeOf(arg)) tran := trans.NewTransaction(gom.pool) v := reflect.ValueOf(arg) tpl.Engrave(&tran.Actions, key, v) tran.Exec() return nil }
func (gom *Gomdise) Find(key string, dest interface{}) (err error) { defer func() { err = errorRecover() }() tpl := tpl.TCFind.GetTemplate(reflect.TypeOf(dest)) tran := trans.NewTransaction(gom.pool) tpl.Engrave(&tran.Actions, key) root := tran.Actions[0] tran.Exec() mdl.Decode(root, dest) return nil }
func (gom *Gomdise) Save(arg interface{}) (key string, err error) { defer func() { err = errorRecover() if err != nil { key = "" } }() tpl := tpl.TCSave.GetTemplate(reflect.TypeOf(arg)) tran := trans.NewTransaction(gom.pool) v := reflect.ValueOf(arg) key = mdl.NewKey(v) tpl.Engrave(&tran.Actions, key, v) tran.Exec() return key, nil }