add channel models

This commit is contained in:
lyx0 2022-08-09 00:07:32 +02:00
parent 54d1b93b2d
commit 07a39a7fcb
2 changed files with 22 additions and 1 deletions

View file

@ -10,6 +10,7 @@ import (
"github.com/gempir/go-twitch-irc/v3"
"github.com/joho/godotenv"
_ "github.com/lib/pq"
"github.com/lyx0/nourybot/internal/data"
"github.com/lyx0/nourybot/pkg/common"
"go.uber.org/zap"
)
@ -30,6 +31,7 @@ type Application struct {
TwitchClient *twitch.Client
Logger *zap.SugaredLogger
Db *sql.DB
models data.Models
}
func main() {
@ -69,6 +71,7 @@ func main() {
TwitchClient: tc,
Logger: sugar,
Db: db,
models: data.NewModels(db),
}
// Received a PrivateMessage (normal chat message).

View file

@ -1,7 +1,25 @@
package data
import "errors"
import (
"database/sql"
"errors"
)
var (
ErrRecordNotFound = errors.New("record not found")
)
// 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)
}
}
func NewModels(db *sql.DB) Models {
return Models{
Channels: ChannelModel{DB: db},
}
}