mirror of
https://github.com/cuigh/swirl
synced 2025-01-03 17:42:29 +00:00
66 lines
1.3 KiB
Go
66 lines
1.3 KiB
Go
package mongo
|
|
|
|
import (
|
|
"github.com/cuigh/swirl/model"
|
|
"github.com/globalsign/mgo"
|
|
"github.com/globalsign/mgo/bson"
|
|
)
|
|
|
|
func (d *Dao) ChartList() (charts []*model.Chart, err error) {
|
|
d.do(func(db *database) {
|
|
charts = []*model.Chart{}
|
|
err = db.C("chart").Find(nil).All(&charts)
|
|
})
|
|
return
|
|
}
|
|
|
|
func (d *Dao) ChartCreate(chart *model.Chart) (err error) {
|
|
d.do(func(db *database) {
|
|
err = db.C("chart").Insert(chart)
|
|
})
|
|
return
|
|
}
|
|
|
|
func (d *Dao) ChartGet(name string) (chart *model.Chart, err error) {
|
|
d.do(func(db *database) {
|
|
chart = &model.Chart{}
|
|
err = db.C("chart").FindId(name).One(chart)
|
|
if err == mgo.ErrNotFound {
|
|
chart, err = nil, nil
|
|
} else if err != nil {
|
|
chart = nil
|
|
}
|
|
})
|
|
return
|
|
}
|
|
|
|
func (d *Dao) ChartBatch(names ...string) (charts []*model.Chart, err error) {
|
|
d.do(func(db *database) {
|
|
q := bson.M{"_id": bson.M{"$in": names}}
|
|
charts = make([]*model.Chart, 0)
|
|
err = db.C("chart").Find(q).All(&charts)
|
|
return
|
|
})
|
|
return
|
|
}
|
|
|
|
func (d *Dao) ChartUpdate(chart *model.Chart) (err error) {
|
|
d.do(func(db *database) {
|
|
//update := bson.M{
|
|
// "$set": bson.M{
|
|
// "name": chart.Name,
|
|
// "desc": chart.Description,
|
|
// },
|
|
//}
|
|
err = db.C("chart").UpdateId(chart.Name, chart)
|
|
})
|
|
return
|
|
}
|
|
|
|
func (d *Dao) ChartDelete(name string) (err error) {
|
|
d.do(func(db *database) {
|
|
err = db.C("chart").RemoveId(name)
|
|
})
|
|
return
|
|
}
|