2022-08-08 23:58:38 +02:00
|
|
|
package data
|
|
|
|
|
2022-08-09 00:07:32 +02:00
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"errors"
|
|
|
|
)
|
2022-08-08 23:58:38 +02:00
|
|
|
|
|
|
|
var (
|
2022-08-09 21:25:44 +02:00
|
|
|
ErrRecordNotFound = errors.New("record not found")
|
|
|
|
ErrRecordAlreadyExists = errors.New("channel already in database")
|
2022-08-09 22:34:12 +02:00
|
|
|
ErrUserAlreadyExists = errors.New("user already in database")
|
2022-08-08 23:58:38 +02:00
|
|
|
)
|
2022-08-09 00:07:32 +02:00
|
|
|
|
|
|
|
// 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)
|
2022-08-09 23:19:08 +02:00
|
|
|
GetAll() ([]*Channel, error)
|
2022-08-09 19:50:46 +02:00
|
|
|
Delete(login string) error
|
2022-08-09 00:07:32 +02:00
|
|
|
}
|
2022-08-09 22:34:12 +02:00
|
|
|
Users interface {
|
|
|
|
Insert(user *User) error
|
|
|
|
Get(login string) (*User, error)
|
2022-08-09 21:25:44 +02:00
|
|
|
Delete(login string) error
|
|
|
|
}
|
2022-08-09 00:07:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewModels(db *sql.DB) Models {
|
|
|
|
return Models{
|
|
|
|
Channels: ChannelModel{DB: db},
|
2022-08-09 22:34:12 +02:00
|
|
|
Users: UserModel{DB: db},
|
2022-08-09 00:07:32 +02:00
|
|
|
}
|
|
|
|
}
|