Esempio n. 1
0
File: file.go Progetto: Laller/chill
func (c *C) New(a iface.Filter) ([]map[string]interface{}, error) {
	scheme, err := c.getScheme(a.Subject(), "Insert")
	if err != nil {
		return nil, err
	}
	return convert.SchemeToFields(scheme, nil)
}
Esempio n. 2
0
File: file.go Progetto: Laller/chill
func (c *C) Update(a iface.Filter, data map[string]interface{}) error {
	files_map, has := data["_files"].(map[string]interface{})
	upd := map[string]interface{}{
		"$set": data,
	}
	if has {
		ids, err := a.Ids()
		if err != nil {
			return err
		}
		err = c.moveFiles(a.Subject(), ids[0].Hex(), files_map)
		if err != nil {
			return err
		}
		delete(data, "_files")
		upd["$addToSet"] = eachIfNeeded(fileheadersToFilenames(files_map))
	}
	err := a.Update(upd)
	if err != nil {
		return err
	}
	if c.Ev != nil {
		c.Ev.Fire("Updated", a)
		c.Ev.Fire(a.Subject()+"Updated", a)
	}
	return nil
}
Esempio n. 3
0
File: file.go Progetto: Laller/chill
func (c *C) Edit(a iface.Filter) ([]map[string]interface{}, error) {
	doc, err := a.FindOne()
	if err != nil {
		return nil, err
	}
	scheme, err := c.getScheme(a.Subject(), "Update")
	if err != nil {
		return nil, err
	}
	return convert.SchemeToFields(scheme, doc)
}
Esempio n. 4
0
func (b *Basics) Update(a iface.Filter, data map[string]interface{}) error {
	upd := map[string]interface{}{
		"$set": data,
	}
	err := a.Update(upd)
	if err != nil {
		return err
	}
	if b.Ev != nil {
		b.Ev.Fire("Updated", a)
		b.Ev.Fire(a.Subject()+"Updated", a)
	}
	return nil
}
Esempio n. 5
0
func (f *Filter) Reduce(a ...iface.Filter) (iface.Filter, error) {
	l := len(a)
	if l == 0 {
		return &Filter{}, fmt.Errorf("Nothing to reduce.")
	}
	var prev iface.Filter
	prev = f
	for _, v := range a {
		ids, err := prev.Ids()
		if err != nil {
			return &Filter{}, err
		}
		v.AddParents("_"+prev.Subject(), ids)
		prev = v
	}
	return prev, nil
}
Esempio n. 6
0
func (b *Basics) Insert(a iface.Filter, data map[string]interface{}) (bson.ObjectId, error) {
	id := bson.NewObjectId()
	data["_id"] = id
	err := a.Insert(data)
	if err != nil {
		return "", err
	}
	if b.Ev != nil {
		q := map[string]interface{}{
			"_id": id,
		}
		filt := a.Clone().AddQuery(q)
		b.Ev.Fire("Inserted", filt)
		b.Ev.Fire(a.Subject()+"Inserted", filt)
	}
	return id, nil
}
Esempio n. 7
0
File: file.go Progetto: Laller/chill
func (c *C) Insert(a iface.Filter, data map[string]interface{}) (bson.ObjectId, error) {
	files_map, has_files := data["_files"].(map[string]interface{})
	if has_files {
		delete(data, "_files")
		merge(data, fileheadersToFilenames(files_map))
	}
	id, err := c.Basics.Insert(a, data)
	if err != nil {
		return id, err
	}
	if has_files {
		err := c.moveFiles(a.Subject(), id.Hex(), files_map)
		if err != nil {
			return "", err
		}
	}
	return id, nil
}