8f2f47e8aa
Added the IsoCode field to phrase files. Rewrote a good portion of the widget system logic. Added some tests for the widget system. Added the Online Users widget. Added a few sealed incomplete widgets like the Search & Filter Widget. Added the AllUsers method to WsHubImpl for Online Users. Please don't abuse it. Added the optional *DBTableKey field to AddColumn. Added the panel_analytics_time_range template to reduce the amount of duplication. Failed registrations now show up in red in the registration logs for Nox. Failed logins now show up in red in the login logs for Nox. Added basic h2 CSS to the other themes. Added .show_on_block_edit and .hide_on_block_edit to the other themes. Updated contributing. Updated a bunch of dates to 2019. Replaced tblKey{} with nil where possible. Switched out some &s for &s to reduce the number of possible bugs. Fixed a bug with selector messages where the inspector would get really jittery due to unnecessary DOM updates. Moved header.Zone and associated fields to the bottom of ViewTopic to reduce the chances of problems arising. Added the ZoneData field to *Header. Added IDs to the items in the forum list template. Split the fetchPhrases function into the initPhrases and fetchPhrases functions in init.js Added .colstack_sub_head. Fixed the CSS in the menu list. Removed an inline style from the simple topic like and unlike buttons. Removed an inline style from the simple topic IP button. Simplified the LoginRequired error handler. Fixed a typo in the comment prior to DatabaseError() Reduce the number of false leaves for WebSocket page transitions. Added the error zone. De-duped the logic in WsHubImpl.getUsers. Fixed a potential widget security issue. Added twenty new phrases. Added the wid column to the widgets table. You will need to run the patcher / updater for this commit.
216 lines
7.7 KiB
Go
216 lines
7.7 KiB
Go
/* WIP Under Construction */
|
|
package qgen
|
|
|
|
import (
|
|
"database/sql"
|
|
"log"
|
|
)
|
|
|
|
var Builder *builder
|
|
|
|
func init() {
|
|
Builder = &builder{conn: nil}
|
|
}
|
|
|
|
// A set of wrappers around the generator methods, so that we can use this inline in Gosora
|
|
type builder struct {
|
|
conn *sql.DB
|
|
adapter Adapter
|
|
}
|
|
|
|
func (build *builder) Accumulator() *Accumulator {
|
|
return &Accumulator{build.conn, build.adapter, nil}
|
|
}
|
|
|
|
// TODO: Move this method out of builder?
|
|
func (build *builder) Init(adapter string, config map[string]string) error {
|
|
err := build.SetAdapter(adapter)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
conn, err := build.adapter.BuildConn(config)
|
|
build.conn = conn
|
|
log.Print("err: ", err) // Is the problem here somehow?
|
|
return err
|
|
}
|
|
|
|
func (build *builder) SetConn(conn *sql.DB) {
|
|
build.conn = conn
|
|
}
|
|
|
|
func (build *builder) GetConn() *sql.DB {
|
|
return build.conn
|
|
}
|
|
|
|
func (build *builder) SetAdapter(name string) error {
|
|
adap, err := GetAdapter(name)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
build.adapter = adap
|
|
return nil
|
|
}
|
|
|
|
func (build *builder) GetAdapter() Adapter {
|
|
return build.adapter
|
|
}
|
|
|
|
func (build *builder) DbVersion() (dbVersion string) {
|
|
build.conn.QueryRow(build.adapter.DbVersion()).Scan(&dbVersion)
|
|
return dbVersion
|
|
}
|
|
|
|
func (build *builder) Begin() (*sql.Tx, error) {
|
|
return build.conn.Begin()
|
|
}
|
|
|
|
func (build *builder) Tx(handler func(*TransactionBuilder) error) error {
|
|
tx, err := build.conn.Begin()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = handler(&TransactionBuilder{tx, build.adapter, nil})
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return err
|
|
}
|
|
return tx.Commit()
|
|
}
|
|
|
|
func (build *builder) prepare(res string, err error) (*sql.Stmt, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return build.conn.Prepare(res)
|
|
}
|
|
|
|
func (build *builder) SimpleSelect(table string, columns string, where string, orderby string, limit string) (stmt *sql.Stmt, err error) {
|
|
return build.prepare(build.adapter.SimpleSelect("", table, columns, where, orderby, limit))
|
|
}
|
|
|
|
func (build *builder) SimpleCount(table string, where string, limit string) (stmt *sql.Stmt, err error) {
|
|
return build.prepare(build.adapter.SimpleCount("", table, where, limit))
|
|
}
|
|
|
|
func (build *builder) SimpleLeftJoin(table1 string, table2 string, columns string, joiners string, where string, orderby string, limit string) (stmt *sql.Stmt, err error) {
|
|
return build.prepare(build.adapter.SimpleLeftJoin("", table1, table2, columns, joiners, where, orderby, limit))
|
|
}
|
|
|
|
func (build *builder) SimpleInnerJoin(table1 string, table2 string, columns string, joiners string, where string, orderby string, limit string) (stmt *sql.Stmt, err error) {
|
|
return build.prepare(build.adapter.SimpleInnerJoin("", table1, table2, columns, joiners, where, orderby, limit))
|
|
}
|
|
|
|
func (build *builder) DropTable(table string) (stmt *sql.Stmt, err error) {
|
|
return build.prepare(build.adapter.DropTable("", table))
|
|
}
|
|
|
|
func (build *builder) CreateTable(table string, charset string, collation string, columns []DBTableColumn, keys []DBTableKey) (stmt *sql.Stmt, err error) {
|
|
return build.prepare(build.adapter.CreateTable("", table, charset, collation, columns, keys))
|
|
}
|
|
|
|
func (build *builder) AddColumn(table string, column DBTableColumn, key *DBTableKey) (stmt *sql.Stmt, err error) {
|
|
return build.prepare(build.adapter.AddColumn("", table, column, key))
|
|
}
|
|
|
|
func (build *builder) AddIndex(table string, iname string, colname string) (stmt *sql.Stmt, err error) {
|
|
return build.prepare(build.adapter.AddIndex("", table, iname, colname))
|
|
}
|
|
|
|
func (build *builder) SimpleInsert(table string, columns string, fields string) (stmt *sql.Stmt, err error) {
|
|
return build.prepare(build.adapter.SimpleInsert("", table, columns, fields))
|
|
}
|
|
|
|
func (build *builder) SimpleInsertSelect(ins DBInsert, sel DBSelect) (stmt *sql.Stmt, err error) {
|
|
return build.prepare(build.adapter.SimpleInsertSelect("", ins, sel))
|
|
}
|
|
|
|
func (build *builder) SimpleInsertLeftJoin(ins DBInsert, sel DBJoin) (stmt *sql.Stmt, err error) {
|
|
return build.prepare(build.adapter.SimpleInsertLeftJoin("", ins, sel))
|
|
}
|
|
|
|
func (build *builder) SimpleInsertInnerJoin(ins DBInsert, sel DBJoin) (stmt *sql.Stmt, err error) {
|
|
return build.prepare(build.adapter.SimpleInsertInnerJoin("", ins, sel))
|
|
}
|
|
|
|
func (build *builder) SimpleUpdate(table string, set string, where string) (stmt *sql.Stmt, err error) {
|
|
return build.prepare(build.adapter.SimpleUpdate(qUpdate(table, set, where)))
|
|
}
|
|
|
|
func (build *builder) SimpleDelete(table string, where string) (stmt *sql.Stmt, err error) {
|
|
return build.prepare(build.adapter.SimpleDelete("", table, where))
|
|
}
|
|
|
|
// I don't know why you need this, but here it is x.x
|
|
func (build *builder) Purge(table string) (stmt *sql.Stmt, err error) {
|
|
return build.prepare(build.adapter.Purge("", table))
|
|
}
|
|
|
|
func (build *builder) prepareTx(tx *sql.Tx, res string, err error) (*sql.Stmt, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return tx.Prepare(res)
|
|
}
|
|
|
|
// These ones support transactions
|
|
func (build *builder) SimpleSelectTx(tx *sql.Tx, table string, columns string, where string, orderby string, limit string) (stmt *sql.Stmt, err error) {
|
|
res, err := build.adapter.SimpleSelect("", table, columns, where, orderby, limit)
|
|
return build.prepareTx(tx, res, err)
|
|
}
|
|
|
|
func (build *builder) SimpleCountTx(tx *sql.Tx, table string, where string, limit string) (stmt *sql.Stmt, err error) {
|
|
res, err := build.adapter.SimpleCount("", table, where, limit)
|
|
return build.prepareTx(tx, res, err)
|
|
}
|
|
|
|
func (build *builder) SimpleLeftJoinTx(tx *sql.Tx, table1 string, table2 string, columns string, joiners string, where string, orderby string, limit string) (stmt *sql.Stmt, err error) {
|
|
res, err := build.adapter.SimpleLeftJoin("", table1, table2, columns, joiners, where, orderby, limit)
|
|
return build.prepareTx(tx, res, err)
|
|
}
|
|
|
|
func (build *builder) SimpleInnerJoinTx(tx *sql.Tx, table1 string, table2 string, columns string, joiners string, where string, orderby string, limit string) (stmt *sql.Stmt, err error) {
|
|
res, err := build.adapter.SimpleInnerJoin("", table1, table2, columns, joiners, where, orderby, limit)
|
|
return build.prepareTx(tx, res, err)
|
|
}
|
|
|
|
func (build *builder) CreateTableTx(tx *sql.Tx, table string, charset string, collation string, columns []DBTableColumn, keys []DBTableKey) (stmt *sql.Stmt, err error) {
|
|
res, err := build.adapter.CreateTable("", table, charset, collation, columns, keys)
|
|
return build.prepareTx(tx, res, err)
|
|
}
|
|
|
|
func (build *builder) SimpleInsertTx(tx *sql.Tx, table string, columns string, fields string) (stmt *sql.Stmt, err error) {
|
|
res, err := build.adapter.SimpleInsert("", table, columns, fields)
|
|
return build.prepareTx(tx, res, err)
|
|
}
|
|
|
|
func (build *builder) SimpleInsertSelectTx(tx *sql.Tx, ins DBInsert, sel DBSelect) (stmt *sql.Stmt, err error) {
|
|
res, err := build.adapter.SimpleInsertSelect("", ins, sel)
|
|
return build.prepareTx(tx, res, err)
|
|
}
|
|
|
|
func (build *builder) SimpleInsertLeftJoinTx(tx *sql.Tx, ins DBInsert, sel DBJoin) (stmt *sql.Stmt, err error) {
|
|
res, err := build.adapter.SimpleInsertLeftJoin("", ins, sel)
|
|
return build.prepareTx(tx, res, err)
|
|
}
|
|
|
|
func (build *builder) SimpleInsertInnerJoinTx(tx *sql.Tx, ins DBInsert, sel DBJoin) (stmt *sql.Stmt, err error) {
|
|
res, err := build.adapter.SimpleInsertInnerJoin("", ins, sel)
|
|
return build.prepareTx(tx, res, err)
|
|
}
|
|
|
|
func (build *builder) SimpleUpdateTx(tx *sql.Tx, table string, set string, where string) (stmt *sql.Stmt, err error) {
|
|
res, err := build.adapter.SimpleUpdate(qUpdate(table, set, where))
|
|
return build.prepareTx(tx, res, err)
|
|
}
|
|
|
|
func (build *builder) SimpleDeleteTx(tx *sql.Tx, table string, where string) (stmt *sql.Stmt, err error) {
|
|
res, err := build.adapter.SimpleDelete("", table, where)
|
|
return build.prepareTx(tx, res, err)
|
|
}
|
|
|
|
// I don't know why you need this, but here it is x.x
|
|
func (build *builder) PurgeTx(tx *sql.Tx, table string) (stmt *sql.Stmt, err error) {
|
|
res, err := build.adapter.Purge("", table)
|
|
return build.prepareTx(tx, res, err)
|
|
}
|