fix query error

This commit is contained in:
Jay
2019-08-25 19:27:00 +08:00
parent 4acc78cd41
commit 703ffe34b2
4 changed files with 56 additions and 6 deletions
+18 -4
View File
@@ -61,12 +61,26 @@ func GetFacebookPageByChannelAndID(id, channel string) (page *FacebookPageModel,
return nil, errors.New("channel or id is empty")
}
db := models.GetConn()
page = &FacebookPageModel{}
query := `select id, lastpost, ctime, mtime from public.facebook_page where id = $1 and channel = $2`
err = db.Get(page, query, channel)
if err != nil && err != sql.ErrNoRows {
query := `
select
fb.id, fb.lastpost, fb.ctime, fb.mtime
from public.facebook_page fb
left join "discord"."channel_facebook_rt" rt
on rt.facebook = fb.id
where fb.id = $1 and rt.channel = $2`
result, err := db.Queryx(query, id, channel)
if err != nil {
return nil, err
}
if result.Next() {
page = &FacebookPageModel{}
err = result.StructScan(page)
if err != nil && err != sql.ErrNoRows {
return nil, err
}
}
return
}