swirl/dao/dao.go

95 lines
3.7 KiB
Go
Raw Normal View History

2017-09-26 12:50:09 +00:00
package dao
import (
2021-12-06 12:24:22 +00:00
"context"
"time"
2021-12-06 12:24:22 +00:00
"github.com/cuigh/auxo/app/container"
2017-09-26 12:50:09 +00:00
"github.com/cuigh/auxo/errors"
2018-04-27 13:17:00 +00:00
"github.com/cuigh/swirl/dao/bolt"
2017-09-26 12:50:09 +00:00
"github.com/cuigh/swirl/dao/mongo"
"github.com/cuigh/swirl/misc"
"github.com/cuigh/swirl/model"
)
2017-11-13 10:16:16 +00:00
// Interface is the interface that wraps all dao methods.
2017-09-26 12:50:09 +00:00
type Interface interface {
2021-12-06 12:24:22 +00:00
Init() error
2018-04-27 13:17:00 +00:00
2021-12-06 12:24:22 +00:00
RoleGet(ctx context.Context, id string) (*model.Role, error)
2021-12-16 08:11:16 +00:00
RoleSearch(ctx context.Context, name string) (roles []*model.Role, err error)
2021-12-06 12:24:22 +00:00
RoleCreate(ctx context.Context, role *model.Role) error
RoleUpdate(ctx context.Context, role *model.Role) error
RoleDelete(ctx context.Context, id string) error
2021-12-16 08:11:16 +00:00
UserGet(ctx context.Context, id string) (*model.User, error)
UserGetByName(ctx context.Context, loginName string) (*model.User, error)
UserSearch(ctx context.Context, args *model.UserSearchArgs) (users []*model.User, count int, err error)
UserCount(ctx context.Context) (int, error)
2021-12-06 12:24:22 +00:00
UserCreate(ctx context.Context, user *model.User) error
UserUpdate(ctx context.Context, user *model.User) error
2021-12-16 08:11:16 +00:00
UserUpdateStatus(ctx context.Context, user *model.User) error
UserUpdateProfile(ctx context.Context, user *model.User) error
UserUpdatePassword(ctx context.Context, user *model.User) error
2021-12-06 12:24:22 +00:00
UserDelete(ctx context.Context, id string) error
SessionGet(ctx context.Context, id string) (*model.Session, error)
SessionCreate(ctx context.Context, session *model.Session) error
2021-12-16 08:11:16 +00:00
SessionUpdate(ctx context.Context, session *model.Session) error
SessionUpdateExpiry(ctx context.Context, id string, expiry time.Time) (err error)
SessionUpdateDirty(ctx context.Context, userID string, roleID string) (err error)
2021-12-06 12:24:22 +00:00
RegistryGet(ctx context.Context, id string) (*model.Registry, error)
RegistryGetByURL(ctx context.Context, url string) (registry *model.Registry, err error)
2021-12-16 08:11:16 +00:00
RegistryGetAll(ctx context.Context) (registries []*model.Registry, err error)
RegistryCreate(ctx context.Context, registry *model.Registry) error
RegistryUpdate(ctx context.Context, registry *model.Registry) error
2021-12-06 12:24:22 +00:00
RegistryDelete(ctx context.Context, id string) error
StackGet(ctx context.Context, name string) (*model.Stack, error)
2021-12-16 08:11:16 +00:00
StackGetAll(ctx context.Context) (stacks []*model.Stack, err error)
2021-12-06 12:24:22 +00:00
StackCreate(ctx context.Context, stack *model.Stack) error
StackUpdate(ctx context.Context, stack *model.Stack) error
StackDelete(ctx context.Context, name string) error
2021-12-16 08:11:16 +00:00
EventSearch(ctx context.Context, args *model.EventSearchArgs) (events []*model.Event, count int, err error)
2021-12-06 12:24:22 +00:00
EventCreate(ctx context.Context, event *model.Event) error
SettingGet(ctx context.Context, id string) (*model.Setting, error)
2021-12-16 08:11:16 +00:00
SettingGetAll(ctx context.Context) (settings []*model.Setting, err error)
SettingUpdate(ctx context.Context, setting *model.Setting) error
2021-12-06 12:24:22 +00:00
ChartGet(ctx context.Context, id string) (*model.Chart, error)
2021-12-16 08:11:16 +00:00
ChartGetBatch(ctx context.Context, ids ...string) ([]*model.Chart, error)
ChartSearch(ctx context.Context, args *model.ChartSearchArgs) (charts []*model.Chart, count int, err error)
2021-12-06 12:24:22 +00:00
ChartCreate(ctx context.Context, chart *model.Chart) error
ChartUpdate(ctx context.Context, chart *model.Chart) error
ChartDelete(ctx context.Context, id string) error
DashboardGet(ctx context.Context, name, key string) (dashboard *model.Dashboard, err error)
DashboardUpdate(ctx context.Context, dashboard *model.Dashboard) error
2017-09-26 12:50:09 +00:00
}
2017-11-13 10:16:16 +00:00
2021-12-06 12:24:22 +00:00
func newInterface() (i Interface) {
var err error
2017-11-13 10:16:16 +00:00
switch misc.Options.DBType {
case "", "mongo":
2018-04-27 13:17:00 +00:00
i, err = mongo.New(misc.Options.DBAddress)
case "bolt":
i, err = bolt.New(misc.Options.DBAddress)
2017-11-13 10:16:16 +00:00
default:
err = errors.New("Unknown database type: " + misc.Options.DBType)
}
2018-04-27 13:17:00 +00:00
2021-12-06 12:24:22 +00:00
if err != nil {
panic(err)
2018-04-27 13:17:00 +00:00
}
2021-12-06 12:24:22 +00:00
return i
}
func init() {
container.Put(newInterface)
2017-11-13 10:16:16 +00:00
}