From 07a39a7fcb65ba0c9e0590eb1306af33ca876c10 Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Tue, 9 Aug 2022 00:07:32 +0200 Subject: [PATCH] add channel models --- cmd/bot/main.go | 3 +++ internal/data/models.go | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/cmd/bot/main.go b/cmd/bot/main.go index 7c73b78..605c49a 100644 --- a/cmd/bot/main.go +++ b/cmd/bot/main.go @@ -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). diff --git a/internal/data/models.go b/internal/data/models.go index 4d3ac9b..1e6b9a3 100644 --- a/internal/data/models.go +++ b/internal/data/models.go @@ -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}, + } +}