From b495dee7d44eef53018f78ff0386aabf2e4dfa99 Mon Sep 17 00:00:00 2001 From: jay Date: Mon, 24 Sep 2018 19:57:12 +0800 Subject: [PATCH] fix query err check --- model/account.go | 4 ++++ model/facebook_page.go | 10 ++++++++-- model/twitch_channel.go | 7 +++++++ model/youtube_channel.go | 8 +++++++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/model/account.go b/model/account.go index 06b21fb..f76c9b1 100644 --- a/model/account.go +++ b/model/account.go @@ -1,6 +1,7 @@ package model import ( + "database/sql" "time" ) @@ -26,6 +27,9 @@ func GetAllAccount() (accs []*Account, err error) { func GetAccount(account string) (acc *Account, err error) { acc = &Account{} err = x.Get(acc, `select * from "public"."account" where "account" = $1`, account) + if err == sql.ErrNoRows { + return nil, nil + } if err != nil { return nil, err } diff --git a/model/facebook_page.go b/model/facebook_page.go index efda19e..198d0f1 100644 --- a/model/facebook_page.go +++ b/model/facebook_page.go @@ -1,6 +1,9 @@ package model -import "time" +import ( + "database/sql" + "time" +) // FBGroup - type FBGroup struct { @@ -30,7 +33,10 @@ func GetAllFacebookPage() (pages []*FacebookPage, err error) { func GetFacebookPage(id string) (page *FacebookPage, err error) { page = &FacebookPage{} err = x.Get(page, `select * from "public"."facebook_page" where "id" = $1`, id) - return + if err != sql.ErrNoRows { + return nil, err + } + return nil, nil } // AddPage - diff --git a/model/twitch_channel.go b/model/twitch_channel.go index be6c230..079fa1e 100644 --- a/model/twitch_channel.go +++ b/model/twitch_channel.go @@ -1,6 +1,7 @@ package model import ( + "database/sql" "errors" "time" ) @@ -42,6 +43,9 @@ func GetTwitchChannelWithName(name string) (ch *TwitchChannel, err error) { } ch = &TwitchChannel{} err = x.Get(ch, `select * from "public"."twitch_channel" where "name" = $1`, name) + if err == sql.ErrNoRows { + return nil, nil + } return } @@ -52,6 +56,9 @@ func GetTwitchChannelWithID(id string) (ch *TwitchChannel, err error) { } ch = &TwitchChannel{} err = x.Get(ch, `select * from "public"."twitch_channel" where "id" = $1`, id) + if err == sql.ErrNoRows { + return nil, nil + } return } diff --git a/model/youtube_channel.go b/model/youtube_channel.go index 9e89fc0..b9cdba0 100644 --- a/model/youtube_channel.go +++ b/model/youtube_channel.go @@ -1,6 +1,9 @@ package model -import "time" +import ( + "database/sql" + "time" +) // YoutubeGroup - type YoutubeGroup struct { @@ -35,6 +38,9 @@ func GetYoutubeChannelsWithExpire(e int64) (yt []*YoutubeChannel, err error) { func GetYoutubeChannelWithID(id string) (yt *YoutubeChannel, err error) { yt = &YoutubeChannel{} err = x.Get(yt, `select * from "public"."youtube_channel" where "id" = $1`, id) + if err == sql.ErrNoRows { + return nil, nil + } return }