gosora/extend/guilds/lib/guild_store.go
Azareal 0e9c459446 Adjust convo permissions.
Speed up convo_view.html
Make ContentLines in ConvoViewRow an int as it should be.
Shorten common. in the generated templates.
Fix the page titles for the convo panes.
Stop non-present users from editing their convo posts but still allow them to delete them, if they somehow have a way to do that.
Reduce the amount of boilerplate in the currently broken guilds plugin.
2019-08-21 08:32:10 +10:00

45 lines
1.5 KiB
Go

package guilds
import "database/sql"
import "github.com/Azareal/Gosora/query_gen"
var Gstore GuildStore
type GuildStore interface {
Get(id 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 (s *SQLGuildStore) Close() {
_ = s.get.Close()
_ = s.create.Close()
}
func (s *SQLGuildStore) Get(id int) (guild *Guild, err error) {
g = &Guild{ID: id}
err = s.get.QueryRow(guildID).Scan(&g.Name, &g.Desc, &g.Active, &g.Privacy, &g.Joinable, &g.Owner, &g.MemberCount, &g.MainForumID, &g.Backdrop, &g.CreatedAt, &g.LastUpdateTime)
return g, err
}
func (s *SQLGuildStore) Create(name string, desc string, active bool, privacy int, uid int, fid int) (int, error) {
res, err := s.create.Exec(name, desc, active, privacy, uid, fid)
if err != nil {
return 0, err
}
lastID, err := res.LastInsertId()
return int(lastID), err
}