48 lines
701 B
Go
48 lines
701 B
Go
package orm
|
|
|
|
type IDocumentSlice interface {
|
|
Delete() error
|
|
Remove() error
|
|
Save() error
|
|
setExists(n bool)
|
|
getModel() *Model
|
|
}
|
|
|
|
type DocumentSlice []IDocument
|
|
|
|
func (d *DocumentSlice) Delete() error {
|
|
var err error
|
|
for _, doc := range *d {
|
|
err = doc.Delete()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (d *DocumentSlice) Remove() error {
|
|
return d.Delete()
|
|
}
|
|
|
|
func (d *DocumentSlice) Save() error {
|
|
var err error
|
|
for _, doc := range *d {
|
|
err = doc.Save()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (d *DocumentSlice) setExists(b bool) {
|
|
for _, s := range *d {
|
|
s.setExists(b)
|
|
}
|
|
}
|
|
|
|
func (d *DocumentSlice) getModel() *Model {
|
|
return (*d)[0].getModel()
|
|
}
|