Пример #1
0
func (c *CouchStore) DeleteOne(obj caddyshack.StoreObject) error {
	doc := couchdb.NewDocument(obj.GetKey(), "", c.DbObj)
	_, err := doc.GetDocument()
	if err != nil {
		return err
	}
	return doc.Delete()
}
Пример #2
0
func (c *CouchStore) Create(obj caddyshack.StoreObject) (err error) {
	strObj, err := json.Marshal(obj)

	doc := couchdb.NewDocument("", "", c.DbObj)
	err = doc.Create(strObj)
	obj.SetKey(doc.Id)
	return
}
Пример #3
0
func (c *CouchStore) ReadOne(key string) (error, caddyshack.StoreObject) {
	log.Info("ReadOne : Key = ", key)
	doc := couchdb.NewDocument(key, "", c.DbObj)
	jsonObj, err := doc.GetDocument()
	if err != nil {
		return err, nil
	}
	log.Debug("Read one resp :", string(jsonObj))

	//	err, obj := c.GetStoreObj(jsonObj)
	dynmaicObj := reflect.New(c.ObjType).Interface()
	err = json.Unmarshal(jsonObj, dynmaicObj)
	if err != nil {
		return err, nil
	}

	obj := dynmaicObj.(caddyshack.StoreObject)
	obj.SetKey(doc.Id)
	return err, obj
}
Пример #4
0
// The object passed should have CouchWrapperUpdate as an anonymous field containing the details.
func (c *CouchStore) UpdateOne(obj caddyshack.StoreObject) (err error) {
	byteObj, err := json.Marshal(obj)
	doc := couchdb.NewDocument(obj.GetKey(), "", c.DbObj)
	err = doc.Update(byteObj)
	return
}