swirl/dao/dao.go

99 lines
3.6 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"
"github.com/cuigh/swirl/misc"
)
2021-12-23 11:28:31 +00:00
var builders = make(map[string]Builder)
// Builder creates an Interface instance.
type Builder func(addr string) (Interface, error)
func Register(name string, builder Builder) {
builders[name] = builder
}
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 {
2022-02-10 03:09:03 +00:00
Upgrade(ctx context.Context) error
2018-04-27 13:17:00 +00:00
2021-12-23 11:28:31 +00:00
RoleGet(ctx context.Context, id string) (*Role, error)
RoleSearch(ctx context.Context, name string) (roles []*Role, err error)
RoleCreate(ctx context.Context, role *Role) error
RoleUpdate(ctx context.Context, role *Role) error
2021-12-06 12:24:22 +00:00
RoleDelete(ctx context.Context, id string) error
2021-12-23 11:28:31 +00:00
UserGet(ctx context.Context, id string) (*User, error)
UserGetByName(ctx context.Context, loginName string) (*User, error)
2021-12-24 09:24:09 +00:00
UserGetByToken(ctx context.Context, token string) (user *User, err error)
2021-12-23 11:28:31 +00:00
UserSearch(ctx context.Context, args *UserSearchArgs) (users []*User, count int, err error)
2021-12-16 08:11:16 +00:00
UserCount(ctx context.Context) (int, error)
2021-12-23 11:28:31 +00:00
UserCreate(ctx context.Context, user *User) error
UserUpdate(ctx context.Context, user *User) error
UserUpdateStatus(ctx context.Context, user *User) error
UserUpdateProfile(ctx context.Context, user *User) error
UserUpdatePassword(ctx context.Context, user *User) error
2021-12-06 12:24:22 +00:00
UserDelete(ctx context.Context, id string) error
2021-12-23 11:28:31 +00:00
SessionGet(ctx context.Context, id string) (*Session, error)
SessionCreate(ctx context.Context, session *Session) error
SessionUpdate(ctx context.Context, session *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
2021-12-23 11:28:31 +00:00
RegistryGet(ctx context.Context, id string) (*Registry, error)
RegistryGetByURL(ctx context.Context, url string) (registry *Registry, err error)
RegistryGetAll(ctx context.Context) (registries []*Registry, err error)
RegistryCreate(ctx context.Context, registry *Registry) error
RegistryUpdate(ctx context.Context, registry *Registry) error
2021-12-06 12:24:22 +00:00
RegistryDelete(ctx context.Context, id string) error
2021-12-23 11:28:31 +00:00
StackGet(ctx context.Context, name string) (*Stack, error)
StackGetAll(ctx context.Context) (stacks []*Stack, err error)
StackCreate(ctx context.Context, stack *Stack) error
StackUpdate(ctx context.Context, stack *Stack) error
2021-12-06 12:24:22 +00:00
StackDelete(ctx context.Context, name string) error
2021-12-23 11:28:31 +00:00
EventSearch(ctx context.Context, args *EventSearchArgs) (events []*Event, count int, err error)
EventCreate(ctx context.Context, event *Event) error
2022-01-04 08:44:03 +00:00
EventPrune(ctx context.Context, end time.Time) (err error)
2021-12-06 12:24:22 +00:00
2021-12-23 11:28:31 +00:00
SettingGet(ctx context.Context, id string) (*Setting, error)
SettingGetAll(ctx context.Context) (settings []*Setting, err error)
SettingUpdate(ctx context.Context, setting *Setting) error
2021-12-06 12:24:22 +00:00
2021-12-23 11:28:31 +00:00
ChartGet(ctx context.Context, id string) (*Chart, error)
ChartGetBatch(ctx context.Context, ids ...string) ([]*Chart, error)
ChartSearch(ctx context.Context, args *ChartSearchArgs) (charts []*Chart, count int, err error)
ChartCreate(ctx context.Context, chart *Chart) error
ChartUpdate(ctx context.Context, chart *Chart) error
2021-12-06 12:24:22 +00:00
ChartDelete(ctx context.Context, id string) error
2021-12-23 11:28:31 +00:00
DashboardGet(ctx context.Context, name, key string) (dashboard *Dashboard, err error)
DashboardUpdate(ctx context.Context, dashboard *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
2021-12-23 11:28:31 +00:00
if b, ok := builders[misc.Options.DBType]; ok {
i, err = b(misc.Options.DBAddress)
} else {
2021-12-23 10:00:14 +00:00
err = errors.New("unknown database type: " + misc.Options.DBType)
2017-11-13 10:16:16 +00:00
}
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-23 11:28:31 +00:00
return
2021-12-06 12:24:22 +00:00
}
func init() {
container.Put(newInterface)
2017-11-13 10:16:16 +00:00
}