gosora/query_gen/lib/querygen.go
Azareal 23a686fe96 UNSTABLE: Began work on the Nox Theme.
Removed the Tempra Cursive Theme.
You can now do bulk moderation actions with Shadow.

Added:
Argon2 as a dependency.
The EmailStore.
The ReportStore.
The Copy method to *Setting.
The AddColumn method to the query builder and adapters.
The textarea setting type.
More logging to better debug issues.
The GetOffset method to the UserStore.

Removed:
Sortable from Code Climate's Analysis.
MemberCheck and memberCheck as they're obsolete now.
The obsolete url_tags setting.
The BcryptGeneratePasswordNoSalt function.
Some redundant fields from some of the page structs.

Revamped:
The Control Panel Setting List and Editor.

Refactored:
The password hashing logic to make it more amenable to multiple hashing algorithms.
The email portion of the Account Manager.
The Control Panel User List.
The report system.
simplePanelUserCheck and simpleUserCheck to remove the duplicated logic as the two do the exact same thing.

Fixed:
Missing slugs in the profile links in the User Manager.
A few template initialisers potentially reducing the number of odd template edge cases.
Some problems with the footer.
Custom selection colour not applying to images on Shadow.
The avatars of the bottom row of the topic list on Conflux leaking out.

Other:
Moved the startTime variable into package common and exported it.
Moved the password hashing logic from user.go to auth.go
Split common/themes.go into common/theme.go and common/theme_list.go
Replaced the SettingLabels phrase category with the more generic SettingPhrases category.
Moved a load of routes, including panel ones into the routes and panel packages.
Hid the notifications link from the Account Menu.
Moved more inline CSS into the CSS files and made things a little more flexible here and there.
Continued work on PgSQL, still a ways away.
Guests now have a default avatar like everyone else.
Tweaked some of the font sizes on Cosora to make the text look a little nicer.
Partially implemented the theme dock override logic.
Partially implemented a "symlink" like feature for theme directories.
... And a bunch of other things I might have missed.

You will need to run this update script / patcher for this commit.
Warning: This is an "unstable commit", therefore some things may be a little less stable than I'd like. For instance, the Shadow Theme is a little broken in this commit.
2018-05-27 19:36:35 +10:00

212 lines
4.9 KiB
Go

/* WIP Under Construction */
package qgen
import (
"database/sql"
"errors"
"strconv"
"strings"
)
var Registry []Adapter
var ErrNoAdapter = errors.New("This adapter doesn't exist")
type DBTableColumn struct {
Name string
Type string
Size int
Null bool
AutoIncrement bool
Default string
}
type DBTableKey struct {
Columns string
Type string
}
type DBSelect struct {
Table string
Columns string
Where string
Orderby string
Limit string
}
type DBJoin struct {
Table1 string
Table2 string
Columns string
Joiners string
Where string
Orderby string
Limit string
}
type DBInsert struct {
Table string
Columns string
Fields string
}
type DBColumn struct {
Table string
Left string // Could be a function or a column, so I'm naming this Left
Alias string // aka AS Blah, if it's present
Type string // function or column
}
type DBField struct {
Name string
Type string
}
type DBWhere struct {
Expr []DBToken // Simple expressions, the innards of functions are opaque for now.
}
type DBJoiner struct {
LeftTable string
LeftColumn string
RightTable string
RightColumn string
Operator string
}
type DBOrder struct {
Column string
Order string
}
type DBToken struct {
Contents string
Type string // function, operator, column, number, string, substitute
}
type DBSetter struct {
Column string
Expr []DBToken // Simple expressions, the innards of functions are opaque for now.
}
type DBLimit struct {
Offset string // ? or int
MaxCount string // ? or int
}
type DBStmt struct {
Contents string
Type string // create-table, insert, update, delete
}
// TODO: Add the DropTable, TableExists, AddColumn, ColumnExists, and RemoveColumn methods
type Adapter interface {
GetName() string
BuildConn(config map[string]string) (*sql.DB, error)
DbVersion() string
DropTable(name string, table string) (string, error)
CreateTable(name string, table string, charset string, collation string, columns []DBTableColumn, keys []DBTableKey) (string, error)
// TODO: Some way to add indices and keys
// TODO: Test this
AddColumn(name string, table string, column DBTableColumn) (string, error)
SimpleInsert(name string, table string, columns string, fields string) (string, error)
SimpleUpdate(name string, table string, set string, where string) (string, error)
SimpleDelete(name string, table string, where string) (string, error)
Purge(name string, table string) (string, error)
SimpleSelect(name string, table string, columns string, where string, orderby string, limit string) (string, error)
SimpleLeftJoin(name string, table1 string, table2 string, columns string, joiners string, where string, orderby string, limit string) (string, error)
SimpleInnerJoin(string, string, string, string, string, string, string, string) (string, error)
SimpleInsertSelect(string, DBInsert, DBSelect) (string, error)
SimpleInsertLeftJoin(string, DBInsert, DBJoin) (string, error)
SimpleInsertInnerJoin(string, DBInsert, DBJoin) (string, error)
SimpleCount(string, string, string, string) (string, error)
ComplexSelect(*selectPrebuilder) (string, error)
Builder() *prebuilder
Write() error
}
func GetAdapter(name string) (adap Adapter, err error) {
for _, adapter := range Registry {
if adapter.GetName() == name {
return adapter, nil
}
}
return adap, ErrNoAdapter
}
type QueryPlugin interface {
Hook(name string, args ...interface{}) error
Write() error
}
type MySQLUpsertCallback struct {
stmt *sql.Stmt
}
func (double *MySQLUpsertCallback) Exec(args ...interface{}) (res sql.Result, err error) {
if len(args) < 2 {
return res, errors.New("Need two or more arguments")
}
args = args[:len(args)-1]
return double.stmt.Exec(append(args, args...)...)
}
func PrepareMySQLUpsertCallback(db *sql.DB, query string) (*MySQLUpsertCallback, error) {
stmt, err := db.Prepare(query)
return &MySQLUpsertCallback{stmt}, err
}
type LitStr string
// TODO: Test this
func InterfaceMapToInsertStrings(data map[string]interface{}, order string) (cols string, values string) {
var done = make(map[string]bool)
var addValue = func(value interface{}) {
switch value := value.(type) {
case string:
values += "'" + strings.Replace(value, "'", "\\'", -1) + "',"
case int:
values += strconv.Itoa(value) + ","
case LitStr:
values += string(value) + ","
case bool:
if value {
values += "1,"
} else {
values += "0,"
}
}
}
// Add the ordered items
for _, col := range strings.Split(order, ",") {
col = strings.TrimSpace(col)
value, ok := data[col]
if ok {
cols += col + ","
addValue(value)
done[col] = true
}
}
// Go over any unordered items and add them at the end
if len(data) > len(done) {
for col, value := range data {
_, ok := done[col]
if ok {
continue
}
cols += col + ","
addValue(value)
}
}
if cols != "" {
cols = cols[:len(cols)-1]
values = values[:len(values)-1]
}
return cols, values
}