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 package model
import ( import (
"database/sql"
"time" "time"
) )
@ -26,6 +27,9 @@ func GetAllAccount() (accs []*Account, err error) {
func GetAccount(account string) (acc *Account, err error) { func GetAccount(account string) (acc *Account, err error) {
acc = &Account{} acc = &Account{}
err = x.Get(acc, `select * from "public"."account" where "account" = $1`, account) err = x.Get(acc, `select * from "public"."account" where "account" = $1`, account)
if err == sql.ErrNoRows {
return nil, nil
}
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -1,6 +1,9 @@
package model package model
import "time" import (
"database/sql"
"time"
)
// FBGroup - // FBGroup -
type FBGroup struct { type FBGroup struct {
@ -30,7 +33,10 @@ func GetAllFacebookPage() (pages []*FacebookPage, err error) {
func GetFacebookPage(id string) (page *FacebookPage, err error) { func GetFacebookPage(id string) (page *FacebookPage, err error) {
page = &FacebookPage{} page = &FacebookPage{}
err = x.Get(page, `select * from "public"."facebook_page" where "id" = $1`, id) 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 - // AddPage -

View File

@ -1,6 +1,7 @@
package model package model
import ( import (
"database/sql"
"errors" "errors"
"time" "time"
) )
@ -42,6 +43,9 @@ func GetTwitchChannelWithName(name string) (ch *TwitchChannel, err error) {
} }
ch = &TwitchChannel{} ch = &TwitchChannel{}
err = x.Get(ch, `select * from "public"."twitch_channel" where "name" = $1`, name) err = x.Get(ch, `select * from "public"."twitch_channel" where "name" = $1`, name)
if err == sql.ErrNoRows {
return nil, nil
}
return return
} }
@ -52,6 +56,9 @@ func GetTwitchChannelWithID(id string) (ch *TwitchChannel, err error) {
} }
ch = &TwitchChannel{} ch = &TwitchChannel{}
err = x.Get(ch, `select * from "public"."twitch_channel" where "id" = $1`, id) err = x.Get(ch, `select * from "public"."twitch_channel" where "id" = $1`, id)
if err == sql.ErrNoRows {
return nil, nil
}
return return
} }

View File

@ -1,6 +1,9 @@
package model package model
import "time" import (
"database/sql"
"time"
)
// YoutubeGroup - // YoutubeGroup -
type YoutubeGroup struct { type YoutubeGroup struct {
@ -35,6 +38,9 @@ func GetYoutubeChannelsWithExpire(e int64) (yt []*YoutubeChannel, err error) {
func GetYoutubeChannelWithID(id string) (yt *YoutubeChannel, err error) { func GetYoutubeChannelWithID(id string) (yt *YoutubeChannel, err error) {
yt = &YoutubeChannel{} yt = &YoutubeChannel{}
err = x.Get(yt, `select * from "public"."youtube_channel" where "id" = $1`, id) err = x.Get(yt, `select * from "public"."youtube_channel" where "id" = $1`, id)
if err == sql.ErrNoRows {
return nil, nil
}
return return
} }