9075798128
Tweaked some bits to make them more 32-bit friendly for GopherJS, but this might not be necessary now. Added notice.html Added an alerts package to fix the import cycles, more things may be moved here soon. Saved a few lines of accumulator code in a few stores. Moved the AccountEditCriticalSubmit, AccountEditAvatar, AccountEditAvatarSubmit, AccountEditUsername, and AccountEditUsernameSubmit routes into the routes package. Added a QueryRow method to AccSelectBuilder. Tweaked the indentation in the generated templates. Simplified the template render in the AccountEditUsernameSubmit route into a redirect back to the previous page. Run the update script / patcher to replace the route names in the viewchunks table.
49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
package common
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
"../query_gen/lib"
|
|
)
|
|
|
|
var Prstore ProfileReplyStore
|
|
|
|
type ProfileReplyStore interface {
|
|
Get(id int) (*ProfileReply, error)
|
|
Create(profileID int, content string, createdBy int, ipaddress string) (id int, err error)
|
|
}
|
|
|
|
// TODO: Refactor this to stop using the global stmt store
|
|
// TODO: Add more methods to this like Create()
|
|
type SQLProfileReplyStore struct {
|
|
get *sql.Stmt
|
|
create *sql.Stmt
|
|
}
|
|
|
|
func NewSQLProfileReplyStore(acc *qgen.Accumulator) (*SQLProfileReplyStore, error) {
|
|
return &SQLProfileReplyStore{
|
|
get: acc.Select("users_replies").Columns("uid, content, createdBy, createdAt, lastEdit, lastEditBy, ipaddress").Where("rid = ?").Prepare(),
|
|
create: acc.Insert("users_replies").Columns("uid, content, parsed_content, createdAt, createdBy, ipaddress").Fields("?,?,?,UTC_TIMESTAMP(),?,?").Prepare(),
|
|
}, acc.FirstError()
|
|
}
|
|
|
|
func (store *SQLProfileReplyStore) Get(id int) (*ProfileReply, error) {
|
|
reply := ProfileReply{ID: id}
|
|
err := store.get.QueryRow(id).Scan(&reply.ParentID, &reply.Content, &reply.CreatedBy, &reply.CreatedAt, &reply.LastEdit, &reply.LastEditBy, &reply.IPAddress)
|
|
return &reply, err
|
|
}
|
|
|
|
func (store *SQLProfileReplyStore) Create(profileID int, content string, createdBy int, ipaddress string) (id int, err error) {
|
|
res, err := store.create.Exec(profileID, content, ParseMessage(content, 0, ""), createdBy, ipaddress)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
lastID, err := res.LastInsertId()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
// Should we reload the user?
|
|
return int(lastID), err
|
|
}
|