dorisbot/models/discord/rt_table.go

90 lines
2.1 KiB
Go
Raw Normal View History

2019-07-13 09:44:31 +00:00
package discord
2019-07-14 07:04:14 +00:00
import (
"dorisbot/models"
"errors"
"time"
)
2019-07-13 09:44:31 +00:00
// ChannelFacebookRT -
type ChannelFacebookRT struct {
Channel string `db:"channel"`
Facebook string `db:"facebook"`
Tmpl string `db:"tmpl"`
Ctime time.Time `db:"ctime"`
Mtime time.Time `db:"mtime"`
}
// ChannelInstagramRT -
type ChannelInstagramRT struct {
Channel string `db:"channel"`
Instagram string `db:"instagram"`
Tmpl string `db:"tmpl"`
Ctime time.Time `db:"ctime"`
Mtime time.Time `db:"mtime"`
}
// ChannelYoutubeRT -
type ChannelYoutubeRT struct {
Channel string `db:"channel"`
Youtube string `db:"youtube"`
Tmpl string `db:"tmpl"`
Ctime time.Time `db:"ctime"`
Mtime time.Time `db:"mtime"`
}
// ChannelTwitchRT -
type ChannelTwitchRT struct {
Channel string `db:"channel"`
Twitch string `db:"twitch"`
Tmpl string `db:"tmpl"`
Ctime time.Time `db:"ctime"`
Mtime time.Time `db:"mtime"`
}
// CreateFacebookRT -
2019-07-14 07:04:14 +00:00
func CreateFacebookRT(channel, facebook, tmpl string) (rt *ChannelFacebookRT, err error) {
if len(channel) == 0 || len(facebook) == 0 {
return nil, errors.New("channel or fbid is empty")
}
rt = &ChannelFacebookRT{
Channel: channel,
Facebook: facebook,
Tmpl: tmpl,
}
return
}
// GetFacebookRT -
func GetFacebookRT(channel, facebook string) (rt *ChannelFacebookRT, err error) {
if len(channel) == 0 || len(facebook) == 0 {
return nil, errors.New("channel or fbid is empty")
}
rt = &ChannelFacebookRT{}
db := models.GetConn()
query := `select channel, facebook, tmpl, ctime, mtime where channel = $1 and facebook = $2`
err = db.Get(rt, query, channel, facebook)
if err != nil {
return nil, err
}
2019-07-13 09:44:31 +00:00
return
}
2019-07-22 12:54:25 +00:00
// Write -
func (p *ChannelFacebookRT) Write() (err error) {
db := models.GetConn()
query := `insert into discord.channel_facebook_rt ("channel", "facebook", "tmpl") values (:channel, :facebook, :tmpl) returning *`
row, err := db.NamedQuery(query, p)
if err != nil {
return err
}
defer row.Close()
if row.Next() {
err = row.StructScan(p)
if err != nil {
return err
}
}
return
}