swirl/dao/bolt/stack.go

50 lines
1.1 KiB
Go
Raw Normal View History

2018-04-27 13:17:00 +00:00
package bolt
import (
2021-12-06 12:24:22 +00:00
"context"
2018-04-27 13:17:00 +00:00
"github.com/cuigh/swirl/model"
)
2021-12-16 08:11:16 +00:00
const Stack = "stack"
func (d *Dao) StackGetAll(ctx context.Context) (stacks []*model.Stack, err error) {
err = d.each(Stack, func(v []byte) error {
2018-04-27 13:17:00 +00:00
stack := &model.Stack{}
2021-12-16 08:11:16 +00:00
err = decode(v, stack)
2018-04-27 13:17:00 +00:00
if err == nil {
stacks = append(stacks, stack)
}
return err
})
return
}
2021-12-06 12:24:22 +00:00
func (d *Dao) StackCreate(ctx context.Context, stack *model.Stack) (err error) {
2021-12-16 08:11:16 +00:00
return d.replace(Stack, stack.Name, stack)
2018-04-27 13:17:00 +00:00
}
2021-12-06 12:24:22 +00:00
func (d *Dao) StackGet(ctx context.Context, name string) (stack *model.Stack, err error) {
2021-12-16 08:11:16 +00:00
stack = &model.Stack{}
err = d.get(Stack, name, stack)
if err == ErrNoRecords {
return nil, nil
} else if err != nil {
stack = nil
2018-04-27 13:17:00 +00:00
}
return
}
2021-12-06 12:24:22 +00:00
func (d *Dao) StackUpdate(ctx context.Context, stack *model.Stack) (err error) {
2021-12-16 08:11:16 +00:00
old := &model.Stack{}
return d.update(Role, stack.Name, old, func() interface{} {
stack.CreatedAt = old.CreatedAt
stack.CreatedBy = old.CreatedBy
return stack
2018-04-27 13:17:00 +00:00
})
}
2021-12-06 12:24:22 +00:00
func (d *Dao) StackDelete(ctx context.Context, name string) (err error) {
2021-12-16 08:11:16 +00:00
return d.delete(Stack, name)
2018-04-27 13:17:00 +00:00
}