fix all error and bug !!!!!!!!!!!!!

This commit is contained in:
Jay
2018-09-21 01:14:08 +08:00
parent 07436cd8df
commit 906b7be381
24 changed files with 133 additions and 109 deletions
+8 -16
View File
@@ -1,7 +1,6 @@
package model
import (
"database/sql"
"errors"
"time"
)
@@ -26,24 +25,17 @@ func GetGroupCommand(c, g string) (cmd *Commands, err error) {
if len(c) == 0 {
return nil, errors.New("command is empty")
}
tmpCmd := struct {
Commands
Message2 sql.NullString `db:"message2"`
}{}
query := `select c.*, c2.message as message2 from "public"."commands" c
left join "public"."commands" c2
on c2.cmd = c.cmd and c2."group" = $2
query := `select c.* from "public"."commands" c
where c."cmd" = $1
and c."group" = ''`
err = x.Get(&tmpCmd, query, c, g)
and (c."group" = '' or c."group" = $2)
order by c."group" desc
limit 1`
row := x.QueryRowx(query, c, g)
// err = x.Get(&cmd, query, c, g)
cmd = &Commands{}
err = row.StructScan(cmd)
if err != nil {
return nil, err
}
cmd = &tmpCmd.Commands
if tmpCmd.Message2.Valid {
cmd.Message = tmpCmd.Message2.String
}
return
}
+2 -1
View File
@@ -28,7 +28,8 @@ func GetAllFacebookPage() (pages []*FacebookPage, err error) {
// GetFacebookPage -
func GetFacebookPage(id string) (page *FacebookPage, err error) {
err = x.Get(&page, `select * from "public"."facebook_page" where "id" = $1`, id)
page = &FacebookPage{}
err = x.Get(page, `select * from "public"."facebook_page" where "id" = $1`, id)
return
}
+9 -15
View File
@@ -1,7 +1,6 @@
package model
import (
"database/sql"
"errors"
"time"
)
@@ -20,24 +19,19 @@ func GetGroupKeyCommand(c, g string) (cmd *KeyCommands, err error) {
if len(c) == 0 {
return nil, errors.New("command is empty")
}
tmpCmd := struct {
KeyCommands
Message2 sql.NullString `db:"message2"`
}{}
query := `select c.*, c2.message as message2 from "public"."key_commands" c
left join "public"."key_commands" c2
on c2.key = c.key and c2."group" = $2
query := `select c.* from "public"."key_commands" c
where c."key" = $1
and c."group" = ''`
err = x.Get(&tmpCmd, query, c, g)
and (c."group" = '' or c."group" = $2)
order by c."group" desc
limit 1`
row := x.QueryRowx(query, c, g)
// err = x.Get(&cmd, query, c, g)
cmd = &KeyCommands{}
err = row.StructScan(cmd)
if err != nil {
return nil, err
}
cmd = &tmpCmd.KeyCommands
if tmpCmd.Message2.Valid {
cmd.Message = tmpCmd.Message2.String
}
return
}
+4 -2
View File
@@ -40,13 +40,15 @@ func CheckGroupOwner(user, g string) (exists bool, err error) {
// GetLineGroup -
func GetLineGroup(id string) (g *LineGroup, err error) {
err = x.Get(&g, `select * from "public"."line_group" where "id" = $1`, id)
g = &LineGroup{}
err = x.Get(g, `select * from "public"."line_group" where "id" = $1`, id)
return
}
// AddLineGroup -
func AddLineGroup(name, owner string, notify bool) (g *LineGroup, err error) {
err = x.Get(&g, `insert into "public"."line_group" ("name", "owner", "notify") values ($1, $2, $3)`, name, owner, notify)
g = &LineGroup{}
err = x.Get(g, `insert into "public"."line_group" ("name", "owner", "notify") values ($1, $2, $3)`, name, owner, notify)
if err != nil {
return nil, err
}
+2 -1
View File
@@ -15,6 +15,7 @@ type LineMessageLog struct {
// AddLineMessageLog -
func AddLineMessageLog(g, u, msg string) (msglog *LineMessageLog, err error) {
query := `insert into "public"."line_message_log" ("group", "user", "message") values ($1, $2, $3)`
err = x.Get(&msglog, query, g, u, msg)
msglog = &LineMessageLog{}
err = x.Get(msglog, query, g, u, msg)
return
}
+2 -1
View File
@@ -12,7 +12,8 @@ type LineUser struct {
// GetLineUserByID -
func GetLineUserByID(id string) (u *LineUser, err error) {
err = x.Get(&u, `select * from "public"."line_user" where "id" = $1`, id)
u = &LineUser{}
err = x.Get(u, `select * from "public"."line_user" where "id" = $1`, id)
return
}
+4 -2
View File
@@ -40,7 +40,8 @@ func GetTwitchChannelWithName(name string) (ch *TwitchChannel, err error) {
if len(name) == 0 {
return nil, errors.New("name empty")
}
err = x.Get(&ch, `select * from "public"."twitch_channel" where "name" = $1`, name)
ch = &TwitchChannel{}
err = x.Get(ch, `select * from "public"."twitch_channel" where "name" = $1`, name)
return
}
@@ -49,7 +50,8 @@ func GetTwitchChannelWithID(id string) (ch *TwitchChannel, err error) {
if len(id) == 0 {
return nil, errors.New("id empty")
}
err = x.Get(&ch, `select * from "public"."twitch_channel" where "id" = $1`, id)
ch = &TwitchChannel{}
err = x.Get(ch, `select * from "public"."twitch_channel" where "id" = $1`, id)
return
}
+2 -1
View File
@@ -33,7 +33,8 @@ func GetYoutubeChannelsWithExpire(e int64) (yt []*YoutubeChannel, err error) {
// GetYoutubeChannelWithID -
func GetYoutubeChannelWithID(id string) (yt *YoutubeChannel, err error) {
err = x.Get(&yt, `select * from "public"."youtube_channel" where "id" = $1`, id)
yt = &YoutubeChannel{}
err = x.Get(yt, `select * from "public"."youtube_channel" where "id" = $1`, id)
return
}