fix query err check

This commit is contained in:
Jay 2018-09-24 19:57:12 +08:00
parent 83601f2dd0
commit b495dee7d4
4 changed files with 26 additions and 3 deletions

View File

@ -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
}

View File

@ -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 -

View File

@ -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
}

View File

@ -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
}