mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add channel models
This commit is contained in:
parent
54d1b93b2d
commit
07a39a7fcb
2 changed files with 22 additions and 1 deletions
|
@ -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).
|
||||
|
|
|
@ -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},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue