Exemplo n.º 1
0
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
}
Exemplo n.º 2
0
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
}
Exemplo n.º 3
0
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
}