mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
36 lines
759 B
Go
36 lines
759 B
Go
package data
|
|
|
|
import (
|
|
"database/sql"
|
|
"errors"
|
|
)
|
|
|
|
var (
|
|
ErrRecordNotFound = errors.New("record not found")
|
|
ErrRecordAlreadyExists = errors.New("channel already in database")
|
|
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)
|
|
Delete(login string) error
|
|
}
|
|
Users interface {
|
|
Insert(user *User) error
|
|
Get(login string) (*User, error)
|
|
Delete(login string) error
|
|
}
|
|
}
|
|
|
|
func NewModels(db *sql.DB) Models {
|
|
return Models{
|
|
Channels: ChannelModel{DB: db},
|
|
Users: UserModel{DB: db},
|
|
}
|
|
}
|