gosora/extend/guilds/lib/guild_store.go
Azareal 01a692ab5b Added the word filter store and moved the word filter routes into the route package.
Added tests for the word filter store.
Added qgen.NewAcc() to reduce the amount of boilerplate needed for creating an accumulator.
Exposed the RecordError method on the accumulator.
Added an Add method to PluginList and removed AddPlugin() in favour of that.

More panel buttons on Nox should be styled now.
Added the panel_update_button_text phrase for future use.

More errors might be caught in the thumbnailer now.
Removed ls from .travis.yml, it was there for debugging Code Climate.
2018-08-04 21:46:36 +10:00

45 lines
1.5 KiB
Go

package guilds
import "database/sql"
import "../../../query_gen/lib"
var Gstore GuildStore
type GuildStore interface {
Get(guildID int) (guild *Guild, err error)
Create(name string, desc string, active bool, privacy int, uid int, fid int) (int, error)
}
type SQLGuildStore struct {
get *sql.Stmt
create *sql.Stmt
}
func NewSQLGuildStore() (*SQLGuildStore, error) {
acc := qgen.NewAcc()
return &SQLGuildStore{
get: acc.Select("guilds").Columns("name, desc, active, privacy, joinable, owner, memberCount, mainForum, backdrop, createdAt, lastUpdateTime").Where("guildID = ?").Prepare(),
create: acc.Insert("guilds").Columns("name, desc, active, privacy, joinable, owner, memberCount, mainForum, backdrop, createdAt, lastUpdateTime").Fields("?,?,?,?,1,?,1,?,'',UTC_TIMESTAMP(),UTC_TIMESTAMP()").Prepare(),
}, acc.FirstError()
}
func (store *SQLGuildStore) Close() {
_ = store.get.Close()
_ = store.create.Close()
}
func (store *SQLGuildStore) Get(guildID int) (guild *Guild, err error) {
guild = &Guild{ID: guildID}
err = store.get.QueryRow(guildID).Scan(&guild.Name, &guild.Desc, &guild.Active, &guild.Privacy, &guild.Joinable, &guild.Owner, &guild.MemberCount, &guild.MainForumID, &guild.Backdrop, &guild.CreatedAt, &guild.LastUpdateTime)
return guild, err
}
func (store *SQLGuildStore) Create(name string, desc string, active bool, privacy int, uid int, fid int) (int, error) {
res, err := store.create.Exec(name, desc, active, privacy, uid, fid)
if err != nil {
return 0, err
}
lastID, err := res.LastInsertId()
return int(lastID), err
}