mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
65 lines
1.8 KiB
Go
65 lines
1.8 KiB
Go
package data
|
|
|
|
import (
|
|
"database/sql"
|
|
"errors"
|
|
)
|
|
|
|
var (
|
|
ErrRecordNotFound = errors.New("record not found")
|
|
ErrChannelRecordAlreadyExists = errors.New("channel already in database")
|
|
ErrEditConflict = errors.New("edit conflict")
|
|
ErrCommandRecordAlreadyExists = errors.New("command already exists")
|
|
ErrLastFMUserRecordAlreadyExists = errors.New("lastfm connection already set")
|
|
ErrUserAlreadyExists = errors.New("user already in database")
|
|
)
|
|
|
|
// struct Models wraps the models, making them callable
|
|
// as app.models.Channels.Get(login)
|
|
type Models struct {
|
|
Channels interface {
|
|
Insert(channel *Channel) error
|
|
Get(login string) (*Channel, error)
|
|
GetAll() ([]*Channel, error)
|
|
GetJoinable() ([]string, error)
|
|
Delete(login string) error
|
|
}
|
|
Users interface {
|
|
Insert(login, twitchId string) error
|
|
Get(login string) (*User, error)
|
|
Check(twitchId string) (*User, error)
|
|
SetLevel(login string, level int) error
|
|
GetLevel(twitchId string) (int, error)
|
|
SetLocation(login, location string) error
|
|
GetLocation(login string) (string, error)
|
|
SetLastFM(login, lastfmUser string) error
|
|
GetLastFM(login string) (string, error)
|
|
Delete(login string) error
|
|
}
|
|
Commands interface {
|
|
Get(name string) (*Command, error)
|
|
Insert(command *Command) error
|
|
Update(command *Command) error
|
|
SetLevel(name string, level int) error
|
|
SetCategory(name, category string) error
|
|
SetHelp(name, helptext string) error
|
|
Delete(name string) error
|
|
}
|
|
Timers interface {
|
|
Get(name string) (*Timer, error)
|
|
Insert(timer *Timer) error
|
|
Update(timer *Timer) error
|
|
GetAll() ([]*Timer, error)
|
|
Delete(name string) error
|
|
}
|
|
}
|
|
|
|
func NewModels(db *sql.DB) Models {
|
|
return Models{
|
|
Channels: ChannelModel{DB: db},
|
|
Users: UserModel{DB: db},
|
|
Commands: CommandModel{DB: db},
|
|
Timers: TimerModel{DB: db},
|
|
}
|
|
}
|