swirl/dao/bolt/registry.go

63 lines
1.5 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 Registry = "registry"
2021-12-06 12:24:22 +00:00
func (d *Dao) RegistryCreate(ctx context.Context, registry *model.Registry) (err error) {
2021-12-16 08:11:16 +00:00
return d.replace(Registry, registry.ID, registry)
2018-04-27 13:17:00 +00:00
}
2021-12-06 12:24:22 +00:00
func (d *Dao) RegistryUpdate(ctx context.Context, registry *model.Registry) (err error) {
2021-12-16 08:11:16 +00:00
old := &model.Registry{}
return d.update(Registry, registry.ID, old, func() interface{} {
registry.CreatedAt = old.CreatedAt
registry.CreatedBy = old.CreatedBy
if registry.Password == "" {
registry.Password = old.Password
2018-04-27 13:17:00 +00:00
}
2021-12-16 08:11:16 +00:00
return registry
2018-04-27 13:17:00 +00:00
})
}
2021-12-16 08:11:16 +00:00
func (d *Dao) RegistryGetAll(ctx context.Context) (registries []*model.Registry, err error) {
err = d.each(Registry, func(v []byte) error {
2018-04-27 13:17:00 +00:00
r := &model.Registry{}
2021-12-16 08:11:16 +00:00
err = decode(v, r)
2018-04-27 13:17:00 +00:00
if err != nil {
return err
}
registries = append(registries, r)
return nil
})
return
}
2021-12-06 12:24:22 +00:00
func (d *Dao) RegistryGet(ctx context.Context, id string) (registry *model.Registry, err error) {
2021-12-16 08:11:16 +00:00
registry = &model.Registry{}
err = d.get(Registry, id, registry)
if err == ErrNoRecords {
return nil, nil
} else if err != nil {
registry = nil
2018-04-27 13:17:00 +00:00
}
return
}
2021-12-06 12:24:22 +00:00
func (d *Dao) RegistryGetByURL(ctx context.Context, url string) (registry *model.Registry, err error) {
2021-12-16 08:11:16 +00:00
r := &model.Registry{}
found, err := d.find(Registry, r, func() bool { return r.URL == url })
if found {
return r, nil
}
return nil, err
2021-12-06 12:24:22 +00:00
}
func (d *Dao) RegistryDelete(ctx context.Context, id string) (err error) {
2021-12-16 08:11:16 +00:00
return d.delete(Registry, id)
2018-04-27 13:17:00 +00:00
}