Refactored the query generator.
This commit is contained in:
parent
8ec0534299
commit
f907b2f80c
|
@ -1,5 +1,29 @@
|
|||
package qgen
|
||||
|
||||
type prebuilder struct {
|
||||
adapter Adapter
|
||||
}
|
||||
|
||||
func (build *prebuilder) Select(nlist ...string) *selectPrebuilder {
|
||||
name := optString(nlist, "_builder")
|
||||
return &selectPrebuilder{name, "", "", "", "", "", build.adapter}
|
||||
}
|
||||
|
||||
func (build *prebuilder) Insert(nlist ...string) *insertPrebuilder {
|
||||
name := optString(nlist, "_builder")
|
||||
return &insertPrebuilder{name, "", "", "", build.adapter}
|
||||
}
|
||||
|
||||
func (build *prebuilder) Update(nlist ...string) *updatePrebuilder {
|
||||
name := optString(nlist, "_builder")
|
||||
return &updatePrebuilder{name, "", "", "", build.adapter}
|
||||
}
|
||||
|
||||
func (build *prebuilder) Delete(nlist ...string) *deletePrebuilder {
|
||||
name := optString(nlist, "_builder")
|
||||
return &deletePrebuilder{name, "", "", build.adapter}
|
||||
}
|
||||
|
||||
type deletePrebuilder struct {
|
||||
name string
|
||||
table string
|
||||
|
|
|
@ -1066,24 +1066,8 @@ func (adapter *MssqlAdapter) SimpleCount(name string, table string, where string
|
|||
return querystr, nil
|
||||
}
|
||||
|
||||
func (adapter *MssqlAdapter) Select(nlist ...string) *selectPrebuilder {
|
||||
name := optString(nlist, "_builder")
|
||||
return &selectPrebuilder{name, "", "", "", "", "", adapter}
|
||||
}
|
||||
|
||||
func (adapter *MssqlAdapter) Insert(nlist ...string) *insertPrebuilder {
|
||||
name := optString(nlist, "_builder")
|
||||
return &insertPrebuilder{name, "", "", "", adapter}
|
||||
}
|
||||
|
||||
func (adapter *MssqlAdapter) Update(nlist ...string) *updatePrebuilder {
|
||||
name := optString(nlist, "_builder")
|
||||
return &updatePrebuilder{name, "", "", "", adapter}
|
||||
}
|
||||
|
||||
func (adapter *MssqlAdapter) Delete(nlist ...string) *deletePrebuilder {
|
||||
name := optString(nlist, "_builder")
|
||||
return &deletePrebuilder{name, "", "", adapter}
|
||||
func (adapter *MssqlAdapter) Builder() *prebuilder {
|
||||
return &prebuilder{adapter}
|
||||
}
|
||||
|
||||
func (adapter *MssqlAdapter) Write() error {
|
||||
|
|
|
@ -552,24 +552,8 @@ func (adapter *MysqlAdapter) SimpleCount(name string, table string, where string
|
|||
return querystr, nil
|
||||
}
|
||||
|
||||
func (adapter *MysqlAdapter) Select(nlist ...string) *selectPrebuilder {
|
||||
name := optString(nlist, "_builder")
|
||||
return &selectPrebuilder{name, "", "", "", "", "", adapter}
|
||||
}
|
||||
|
||||
func (adapter *MysqlAdapter) Insert(nlist ...string) *insertPrebuilder {
|
||||
name := optString(nlist, "_builder")
|
||||
return &insertPrebuilder{name, "", "", "", adapter}
|
||||
}
|
||||
|
||||
func (adapter *MysqlAdapter) Update(nlist ...string) *updatePrebuilder {
|
||||
name := optString(nlist, "_builder")
|
||||
return &updatePrebuilder{name, "", "", "", adapter}
|
||||
}
|
||||
|
||||
func (adapter *MysqlAdapter) Delete(nlist ...string) *deletePrebuilder {
|
||||
name := optString(nlist, "_builder")
|
||||
return &deletePrebuilder{name, "", "", adapter}
|
||||
func (adapter *MysqlAdapter) Builder() *prebuilder {
|
||||
return &prebuilder{adapter}
|
||||
}
|
||||
|
||||
func (adapter *MysqlAdapter) Write() error {
|
||||
|
|
|
@ -318,24 +318,8 @@ func (adapter *PgsqlAdapter) SimpleCount(name string, table string, where string
|
|||
return "", nil
|
||||
}
|
||||
|
||||
func (adapter *PgsqlAdapter) Select(nlist ...string) *selectPrebuilder {
|
||||
name := optString(nlist, "_builder")
|
||||
return &selectPrebuilder{name, "", "", "", "", "", adapter}
|
||||
}
|
||||
|
||||
func (adapter *PgsqlAdapter) Insert(nlist ...string) *insertPrebuilder {
|
||||
name := optString(nlist, "_builder")
|
||||
return &insertPrebuilder{name, "", "", "", adapter}
|
||||
}
|
||||
|
||||
func (adapter *PgsqlAdapter) Update(nlist ...string) *updatePrebuilder {
|
||||
name := optString(nlist, "_builder")
|
||||
return &updatePrebuilder{name, "", "", "", adapter}
|
||||
}
|
||||
|
||||
func (adapter *PgsqlAdapter) Delete(nlist ...string) *deletePrebuilder {
|
||||
name := optString(nlist, "_builder")
|
||||
return &deletePrebuilder{name, "", "", adapter}
|
||||
func (adapter *PgsqlAdapter) Builder() *prebuilder {
|
||||
return &prebuilder{adapter}
|
||||
}
|
||||
|
||||
func (adapter *PgsqlAdapter) Write() error {
|
||||
|
|
|
@ -116,11 +116,7 @@ type Adapter interface {
|
|||
SimpleInsertInnerJoin(string, DBInsert, DBJoin) (string, error)
|
||||
SimpleCount(string, string, string, string) (string, error)
|
||||
|
||||
Select(name ...string) *selectPrebuilder
|
||||
Insert(name ...string) *insertPrebuilder
|
||||
Update(name ...string) *updatePrebuilder
|
||||
Delete(name ...string) *deletePrebuilder
|
||||
|
||||
Builder() *prebuilder
|
||||
Write() error
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ func processJoiner(joinstr string) (joiner []DBJoiner) {
|
|||
return joiner
|
||||
}
|
||||
|
||||
func parseNumber(tmpWhere *DBWhere, segment string, i int) int {
|
||||
func (where *DBWhere) parseNumber(segment string, i int) int {
|
||||
var buffer string
|
||||
for ; i < len(segment); i++ {
|
||||
char := segment[i]
|
||||
|
@ -101,83 +101,95 @@ func parseNumber(tmpWhere *DBWhere, segment string, i int) int {
|
|||
buffer += string(char)
|
||||
} else {
|
||||
i--
|
||||
tmpWhere.Expr = append(tmpWhere.Expr, DBToken{buffer, "number"})
|
||||
where.Expr = append(where.Expr, DBToken{buffer, "number"})
|
||||
return i
|
||||
}
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
func parseColumn(tmpWhere *DBWhere, segment string, i int) int {
|
||||
func (where *DBWhere) parseColumn(segment string, i int) int {
|
||||
var buffer string
|
||||
for ; i < len(segment); i++ {
|
||||
char := segment[i]
|
||||
if ('a' <= char && char <= 'z') || ('A' <= char && char <= 'Z') || char == '.' || char == '_' {
|
||||
buffer += string(char)
|
||||
} else if char == '(' {
|
||||
return parseFunction(tmpWhere, segment, buffer, i)
|
||||
return where.parseFunction(segment, buffer, i)
|
||||
} else {
|
||||
i--
|
||||
tmpWhere.Expr = append(tmpWhere.Expr, DBToken{buffer, "column"})
|
||||
where.Expr = append(where.Expr, DBToken{buffer, "column"})
|
||||
return i
|
||||
}
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
func parseFunction(tmpWhere *DBWhere, segment string, buffer string, i int) int {
|
||||
func (where *DBWhere) parseFunction(segment string, buffer string, i int) int {
|
||||
var preI = i
|
||||
i = skipFunctionCall(segment, i-1)
|
||||
buffer += segment[preI:i] + string(segment[i])
|
||||
tmpWhere.Expr = append(tmpWhere.Expr, DBToken{buffer, "function"})
|
||||
where.Expr = append(where.Expr, DBToken{buffer, "function"})
|
||||
return i
|
||||
}
|
||||
|
||||
func (where *DBWhere) parseString(segment string, i int) int {
|
||||
var buffer string
|
||||
i++
|
||||
for ; i < len(segment); i++ {
|
||||
char := segment[i]
|
||||
if char != '\'' {
|
||||
buffer += string(char)
|
||||
} else {
|
||||
where.Expr = append(where.Expr, DBToken{buffer, "string"})
|
||||
return i
|
||||
}
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
func (where *DBWhere) parseOperator(segment string, i int) int {
|
||||
var buffer string
|
||||
for ; i < len(segment); i++ {
|
||||
char := segment[i]
|
||||
if isOpByte(char) {
|
||||
buffer += string(char)
|
||||
} else {
|
||||
i--
|
||||
where.Expr = append(where.Expr, DBToken{buffer, "operator"})
|
||||
return i
|
||||
}
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// TODO: Make this case insensitive
|
||||
func normalizeAnd(in string) string {
|
||||
return strings.Replace(in, " and ", " AND ", -1)
|
||||
}
|
||||
|
||||
// TODO: Write tests for this
|
||||
func processWhere(wherestr string) (where []DBWhere) {
|
||||
if wherestr == "" {
|
||||
return where
|
||||
}
|
||||
wherestr = strings.Replace(wherestr, " and ", " AND ", -1)
|
||||
wherestr = normalizeAnd(wherestr)
|
||||
|
||||
var buffer string
|
||||
var optype int // 0: None, 1: Number, 2: Column, 3: Function, 4: String, 5: Operator
|
||||
for _, segment := range strings.Split(wherestr, " AND ") {
|
||||
var tmpWhere = &DBWhere{[]DBToken{}}
|
||||
segment += ")"
|
||||
for i := 0; i < len(segment); i++ {
|
||||
char := segment[i]
|
||||
switch optype {
|
||||
case 0: // unknown
|
||||
if '0' <= char && char <= '9' {
|
||||
i = parseNumber(tmpWhere, segment, i)
|
||||
} else if ('a' <= char && char <= 'z') || ('A' <= char && char <= 'Z') || char == '_' {
|
||||
i = parseColumn(tmpWhere, segment, i)
|
||||
} else if char == '\'' {
|
||||
optype = 4
|
||||
buffer = ""
|
||||
} else if isOpByte(char) {
|
||||
optype = 5
|
||||
buffer = string(char)
|
||||
} else if char == '?' {
|
||||
tmpWhere.Expr = append(tmpWhere.Expr, DBToken{"?", "substitute"})
|
||||
}
|
||||
case 4: // string
|
||||
if char != '\'' {
|
||||
buffer += string(char)
|
||||
} else {
|
||||
optype = 0
|
||||
tmpWhere.Expr = append(tmpWhere.Expr, DBToken{buffer, "string"})
|
||||
}
|
||||
case 5: // operator
|
||||
if isOpByte(char) {
|
||||
buffer += string(char)
|
||||
} else {
|
||||
optype = 0
|
||||
i--
|
||||
tmpWhere.Expr = append(tmpWhere.Expr, DBToken{buffer, "operator"})
|
||||
}
|
||||
default:
|
||||
panic("Bad optype in processWhere")
|
||||
if '0' <= char && char <= '9' {
|
||||
i = tmpWhere.parseNumber(segment, i)
|
||||
} else if ('a' <= char && char <= 'z') || ('A' <= char && char <= 'Z') || char == '_' {
|
||||
i = tmpWhere.parseColumn(segment, i)
|
||||
} else if char == '\'' {
|
||||
i = tmpWhere.parseString(segment, i)
|
||||
} else if isOpByte(char) {
|
||||
i = tmpWhere.parseOperator(segment, i)
|
||||
} else if char == '?' {
|
||||
tmpWhere.Expr = append(tmpWhere.Expr, DBToken{"?", "substitute"})
|
||||
}
|
||||
}
|
||||
where = append(where, *tmpWhere)
|
||||
|
@ -185,6 +197,75 @@ func processWhere(wherestr string) (where []DBWhere) {
|
|||
return where
|
||||
}
|
||||
|
||||
func (setter *DBSetter) parseNumber(segment string, i int) int {
|
||||
var buffer string
|
||||
for ; i < len(segment); i++ {
|
||||
char := segment[i]
|
||||
if '0' <= char && char <= '9' {
|
||||
buffer += string(char)
|
||||
} else {
|
||||
setter.Expr = append(setter.Expr, DBToken{buffer, "number"})
|
||||
return i
|
||||
}
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
func (setter *DBSetter) parseColumn(segment string, i int) int {
|
||||
var buffer string
|
||||
for ; i < len(segment); i++ {
|
||||
char := segment[i]
|
||||
if ('a' <= char && char <= 'z') || ('A' <= char && char <= 'Z') || char == '_' {
|
||||
buffer += string(char)
|
||||
} else if char == '(' {
|
||||
return setter.parseFunction(segment, buffer, i)
|
||||
} else {
|
||||
i--
|
||||
setter.Expr = append(setter.Expr, DBToken{buffer, "column"})
|
||||
return i
|
||||
}
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
func (setter *DBSetter) parseFunction(segment string, buffer string, i int) int {
|
||||
var preI = i
|
||||
i = skipFunctionCall(segment, i-1)
|
||||
buffer += segment[preI:i] + string(segment[i])
|
||||
setter.Expr = append(setter.Expr, DBToken{buffer, "function"})
|
||||
return i
|
||||
}
|
||||
|
||||
func (setter *DBSetter) parseString(segment string, i int) int {
|
||||
var buffer string
|
||||
i++
|
||||
for ; i < len(segment); i++ {
|
||||
char := segment[i]
|
||||
if char != '\'' {
|
||||
buffer += string(char)
|
||||
} else {
|
||||
setter.Expr = append(setter.Expr, DBToken{buffer, "string"})
|
||||
return i
|
||||
}
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
func (setter *DBSetter) parseOperator(segment string, i int) int {
|
||||
var buffer string
|
||||
for ; i < len(segment); i++ {
|
||||
char := segment[i]
|
||||
if isOpByte(char) {
|
||||
buffer += string(char)
|
||||
} else {
|
||||
i--
|
||||
setter.Expr = append(setter.Expr, DBToken{buffer, "operator"})
|
||||
return i
|
||||
}
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
func processSet(setstr string) (setter []DBSetter) {
|
||||
if setstr == "" {
|
||||
return setter
|
||||
|
@ -211,84 +292,29 @@ func processSet(setstr string) (setter []DBSetter) {
|
|||
}
|
||||
|
||||
// Second pass. Break this setitem into manageable chunks
|
||||
buffer = ""
|
||||
for _, setitem := range setset {
|
||||
var tmpSetter DBSetter
|
||||
halves := strings.Split(setitem, "=")
|
||||
if len(halves) != 2 {
|
||||
continue
|
||||
}
|
||||
tmpSetter.Column = strings.TrimSpace(halves[0])
|
||||
tmpSetter := &DBSetter{Column: strings.TrimSpace(halves[0])}
|
||||
segment := halves[1] + ")"
|
||||
|
||||
var optype int // 0: None, 1: Number, 2: Column, 3: Function, 4: String, 5: Operator
|
||||
//fmt.Println("segment", segment)
|
||||
for i := 0; i < len(segment); i++ {
|
||||
char := segment[i]
|
||||
//fmt.Println("optype",optype)
|
||||
//fmt.Println("Expr:",buffer)
|
||||
switch optype {
|
||||
case 0: // unknown
|
||||
if '0' <= char && char <= '9' {
|
||||
optype = 1
|
||||
buffer = string(char)
|
||||
} else if ('a' <= char && char <= 'z') || ('A' <= char && char <= 'Z') || char == '_' {
|
||||
optype = 2
|
||||
buffer = string(char)
|
||||
} else if char == '\'' {
|
||||
optype = 4
|
||||
buffer = ""
|
||||
} else if isOpByte(char) {
|
||||
optype = 5
|
||||
buffer = string(char)
|
||||
} else if char == '?' {
|
||||
tmpSetter.Expr = append(tmpSetter.Expr, DBToken{"?", "substitute"})
|
||||
}
|
||||
case 1: // number
|
||||
if '0' <= char && char <= '9' {
|
||||
buffer += string(char)
|
||||
} else {
|
||||
optype = 0
|
||||
i--
|
||||
tmpSetter.Expr = append(tmpSetter.Expr, DBToken{buffer, "number"})
|
||||
}
|
||||
case 2: // column
|
||||
if ('a' <= char && char <= 'z') || ('A' <= char && char <= 'Z') || char == '_' {
|
||||
buffer += string(char)
|
||||
} else if char == '(' {
|
||||
optype = 3
|
||||
i--
|
||||
} else {
|
||||
optype = 0
|
||||
i--
|
||||
tmpSetter.Expr = append(tmpSetter.Expr, DBToken{buffer, "column"})
|
||||
}
|
||||
case 3: // function
|
||||
var preI = i
|
||||
i = skipFunctionCall(segment, i-1)
|
||||
buffer += segment[preI:i] + string(segment[i])
|
||||
tmpSetter.Expr = append(tmpSetter.Expr, DBToken{buffer, "function"})
|
||||
optype = 0
|
||||
case 4: // string
|
||||
if char != '\'' {
|
||||
buffer += string(char)
|
||||
} else {
|
||||
optype = 0
|
||||
tmpSetter.Expr = append(tmpSetter.Expr, DBToken{buffer, "string"})
|
||||
}
|
||||
case 5: // operator
|
||||
if isOpByte(char) {
|
||||
buffer += string(char)
|
||||
} else {
|
||||
optype = 0
|
||||
i--
|
||||
tmpSetter.Expr = append(tmpSetter.Expr, DBToken{buffer, "operator"})
|
||||
}
|
||||
default:
|
||||
panic("Bad optype in processSet")
|
||||
if '0' <= char && char <= '9' {
|
||||
i = tmpSetter.parseNumber(segment, i)
|
||||
} else if ('a' <= char && char <= 'z') || ('A' <= char && char <= 'Z') || char == '_' {
|
||||
i = tmpSetter.parseColumn(segment, i)
|
||||
} else if char == '\'' {
|
||||
i = tmpSetter.parseString(segment, i)
|
||||
} else if isOpByte(char) {
|
||||
i = tmpSetter.parseOperator(segment, i)
|
||||
} else if char == '?' {
|
||||
tmpSetter.Expr = append(tmpSetter.Expr, DBToken{"?", "substitute"})
|
||||
}
|
||||
}
|
||||
setter = append(setter, tmpSetter)
|
||||
setter = append(setter, *tmpSetter)
|
||||
}
|
||||
return setter
|
||||
}
|
||||
|
|
|
@ -220,49 +220,51 @@ func seedTables(adapter qgen.Adapter) error {
|
|||
}
|
||||
|
||||
func writeSelects(adapter qgen.Adapter) error {
|
||||
build := adapter.Builder()
|
||||
|
||||
// Looking for getTopic? Your statement is in another castle
|
||||
|
||||
adapter.Select("getPassword").Table("users").Columns("password, salt").Where("uid = ?").Parse()
|
||||
build.Select("getPassword").Table("users").Columns("password, salt").Where("uid = ?").Parse()
|
||||
|
||||
adapter.Select("getSettings").Table("settings").Columns("name, content, type").Parse()
|
||||
build.Select("getSettings").Table("settings").Columns("name, content, type").Parse()
|
||||
|
||||
adapter.Select("getSetting").Table("settings").Columns("content, type").Where("name = ?").Parse()
|
||||
build.Select("getSetting").Table("settings").Columns("content, type").Where("name = ?").Parse()
|
||||
|
||||
adapter.Select("getFullSetting").Table("settings").Columns("name, type, constraints").Where("name = ?").Parse()
|
||||
build.Select("getFullSetting").Table("settings").Columns("name, type, constraints").Where("name = ?").Parse()
|
||||
|
||||
adapter.Select("isPluginActive").Table("plugins").Columns("active").Where("uname = ?").Parse()
|
||||
build.Select("isPluginActive").Table("plugins").Columns("active").Where("uname = ?").Parse()
|
||||
|
||||
//adapter.Select("isPluginInstalled").Table("plugins").Columns("installed").Where("uname = ?").Parse()
|
||||
//build.Select("isPluginInstalled").Table("plugins").Columns("installed").Where("uname = ?").Parse()
|
||||
|
||||
adapter.Select("getUsersOffset").Table("users").Columns("uid, name, group, active, is_super_admin, avatar").Orderby("uid ASC").Limit("?,?").Parse()
|
||||
build.Select("getUsersOffset").Table("users").Columns("uid, name, group, active, is_super_admin, avatar").Orderby("uid ASC").Limit("?,?").Parse()
|
||||
|
||||
adapter.Select("isThemeDefault").Table("themes").Columns("default").Where("uname = ?").Parse()
|
||||
build.Select("isThemeDefault").Table("themes").Columns("default").Where("uname = ?").Parse()
|
||||
|
||||
adapter.Select("getModlogs").Table("moderation_logs").Columns("action, elementID, elementType, ipaddress, actorID, doneAt").Parse()
|
||||
build.Select("getModlogs").Table("moderation_logs").Columns("action, elementID, elementType, ipaddress, actorID, doneAt").Parse()
|
||||
|
||||
adapter.Select("getModlogsOffset").Table("moderation_logs").Columns("action, elementID, elementType, ipaddress, actorID, doneAt").Orderby("doneAt DESC").Limit("?,?").Parse()
|
||||
build.Select("getModlogsOffset").Table("moderation_logs").Columns("action, elementID, elementType, ipaddress, actorID, doneAt").Orderby("doneAt DESC").Limit("?,?").Parse()
|
||||
|
||||
adapter.Select("getReplyTID").Table("replies").Columns("tid").Where("rid = ?").Parse()
|
||||
build.Select("getReplyTID").Table("replies").Columns("tid").Where("rid = ?").Parse()
|
||||
|
||||
adapter.Select("getTopicFID").Table("topics").Columns("parentID").Where("tid = ?").Parse()
|
||||
build.Select("getTopicFID").Table("topics").Columns("parentID").Where("tid = ?").Parse()
|
||||
|
||||
adapter.Select("getUserReplyUID").Table("users_replies").Columns("uid").Where("rid = ?").Parse()
|
||||
build.Select("getUserReplyUID").Table("users_replies").Columns("uid").Where("rid = ?").Parse()
|
||||
|
||||
adapter.Select("getUserName").Table("users").Columns("name").Where("uid = ?").Parse()
|
||||
build.Select("getUserName").Table("users").Columns("name").Where("uid = ?").Parse()
|
||||
|
||||
adapter.Select("getEmailsByUser").Table("emails").Columns("email, validated, token").Where("uid = ?").Parse()
|
||||
build.Select("getEmailsByUser").Table("emails").Columns("email, validated, token").Where("uid = ?").Parse()
|
||||
|
||||
adapter.Select("getTopicBasic").Table("topics").Columns("title, content").Where("tid = ?").Parse()
|
||||
build.Select("getTopicBasic").Table("topics").Columns("title, content").Where("tid = ?").Parse()
|
||||
|
||||
adapter.Select("getActivityEntry").Table("activity_stream").Columns("actor, targetUser, event, elementType, elementID").Where("asid = ?").Parse()
|
||||
build.Select("getActivityEntry").Table("activity_stream").Columns("actor, targetUser, event, elementType, elementID").Where("asid = ?").Parse()
|
||||
|
||||
adapter.Select("forumEntryExists").Table("forums").Columns("fid").Where("name = ''").Orderby("fid ASC").Limit("0,1").Parse()
|
||||
build.Select("forumEntryExists").Table("forums").Columns("fid").Where("name = ''").Orderby("fid ASC").Limit("0,1").Parse()
|
||||
|
||||
adapter.Select("groupEntryExists").Table("users_groups").Columns("gid").Where("name = ''").Orderby("gid ASC").Limit("0,1").Parse()
|
||||
build.Select("groupEntryExists").Table("users_groups").Columns("gid").Where("name = ''").Orderby("gid ASC").Limit("0,1").Parse()
|
||||
|
||||
adapter.Select("getForumTopicsOffset").Table("topics").Columns("tid, title, content, createdBy, is_closed, sticky, createdAt, lastReplyAt, lastReplyBy, parentID, postCount, likeCount").Where("parentID = ?").Orderby("sticky DESC, lastReplyAt DESC, createdBy DESC").Limit("?,?").Parse()
|
||||
build.Select("getForumTopicsOffset").Table("topics").Columns("tid, title, content, createdBy, is_closed, sticky, createdAt, lastReplyAt, lastReplyBy, parentID, postCount, likeCount").Where("parentID = ?").Orderby("sticky DESC, lastReplyAt DESC, createdBy DESC").Limit("?,?").Parse()
|
||||
|
||||
adapter.Select("getAttachment").Table("attachments").Columns("sectionID, sectionTable, originID, originTable, uploadedBy, path").Where("path = ? AND sectionID = ? AND sectionTable = ?").Parse()
|
||||
build.Select("getAttachment").Table("attachments").Columns("sectionID, sectionTable, originID, originTable, uploadedBy, path").Where("path = ? AND sectionID = ? AND sectionTable = ?").Parse()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -291,25 +293,27 @@ func writeInnerJoins(adapter qgen.Adapter) (err error) {
|
|||
}
|
||||
|
||||
func writeInserts(adapter qgen.Adapter) error {
|
||||
adapter.Insert("createReport").Table("topics").Columns("title, content, parsed_content, createdAt, lastReplyAt, createdBy, lastReplyBy, data, parentID, css_class").Fields("?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),?,?,?,1,'report'").Parse()
|
||||
build := adapter.Builder()
|
||||
|
||||
adapter.Insert("addActivity").Table("activity_stream").Columns("actor, targetUser, event, elementType, elementID").Fields("?,?,?,?,?").Parse()
|
||||
build.Insert("createReport").Table("topics").Columns("title, content, parsed_content, createdAt, lastReplyAt, createdBy, lastReplyBy, data, parentID, css_class").Fields("?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),?,?,?,1,'report'").Parse()
|
||||
|
||||
adapter.Insert("notifyOne").Table("activity_stream_matches").Columns("watcher, asid").Fields("?,?").Parse()
|
||||
build.Insert("addActivity").Table("activity_stream").Columns("actor, targetUser, event, elementType, elementID").Fields("?,?,?,?,?").Parse()
|
||||
|
||||
adapter.Insert("addEmail").Table("emails").Columns("email, uid, validated, token").Fields("?,?,?,?").Parse()
|
||||
build.Insert("notifyOne").Table("activity_stream_matches").Columns("watcher, asid").Fields("?,?").Parse()
|
||||
|
||||
adapter.Insert("addSubscription").Table("activity_subscriptions").Columns("user, targetID, targetType, level").Fields("?,?,?,2").Parse()
|
||||
build.Insert("addEmail").Table("emails").Columns("email, uid, validated, token").Fields("?,?,?,?").Parse()
|
||||
|
||||
adapter.Insert("addForumPermsToForum").Table("forums_permissions").Columns("gid,fid,preset,permissions").Fields("?,?,?,?").Parse()
|
||||
build.Insert("addSubscription").Table("activity_subscriptions").Columns("user, targetID, targetType, level").Fields("?,?,?,2").Parse()
|
||||
|
||||
adapter.Insert("addPlugin").Table("plugins").Columns("uname, active, installed").Fields("?,?,?").Parse()
|
||||
build.Insert("addForumPermsToForum").Table("forums_permissions").Columns("gid,fid,preset,permissions").Fields("?,?,?,?").Parse()
|
||||
|
||||
adapter.Insert("addTheme").Table("themes").Columns("uname, default").Fields("?,?").Parse()
|
||||
build.Insert("addPlugin").Table("plugins").Columns("uname, active, installed").Fields("?,?,?").Parse()
|
||||
|
||||
adapter.Insert("addAttachment").Table("attachments").Columns("sectionID, sectionTable, originID, originTable, uploadedBy, path").Fields("?,?,?,?,?,?").Parse()
|
||||
build.Insert("addTheme").Table("themes").Columns("uname, default").Fields("?,?").Parse()
|
||||
|
||||
adapter.Insert("createWordFilter").Table("word_filters").Columns("find, replacement").Fields("?,?").Parse()
|
||||
build.Insert("addAttachment").Table("attachments").Columns("sectionID, sectionTable, originID, originTable, uploadedBy, path").Fields("?,?,?,?,?,?").Parse()
|
||||
|
||||
build.Insert("createWordFilter").Table("word_filters").Columns("find, replacement").Fields("?,?").Parse()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -334,48 +338,52 @@ func writeReplaces(adapter qgen.Adapter) (err error) {
|
|||
}*/
|
||||
|
||||
func writeUpdates(adapter qgen.Adapter) error {
|
||||
adapter.Update("editReply").Table("replies").Set("content = ?, parsed_content = ?").Where("rid = ?").Parse()
|
||||
build := adapter.Builder()
|
||||
|
||||
adapter.Update("editProfileReply").Table("users_replies").Set("content = ?, parsed_content = ?").Where("rid = ?").Parse()
|
||||
build.Update("editReply").Table("replies").Set("content = ?, parsed_content = ?").Where("rid = ?").Parse()
|
||||
|
||||
adapter.Update("updateSetting").Table("settings").Set("content = ?").Where("name = ?").Parse()
|
||||
build.Update("editProfileReply").Table("users_replies").Set("content = ?, parsed_content = ?").Where("rid = ?").Parse()
|
||||
|
||||
adapter.Update("updatePlugin").Table("plugins").Set("active = ?").Where("uname = ?").Parse()
|
||||
build.Update("updateSetting").Table("settings").Set("content = ?").Where("name = ?").Parse()
|
||||
|
||||
adapter.Update("updatePluginInstall").Table("plugins").Set("installed = ?").Where("uname = ?").Parse()
|
||||
build.Update("updatePlugin").Table("plugins").Set("active = ?").Where("uname = ?").Parse()
|
||||
|
||||
adapter.Update("updateTheme").Table("themes").Set("default = ?").Where("uname = ?").Parse()
|
||||
build.Update("updatePluginInstall").Table("plugins").Set("installed = ?").Where("uname = ?").Parse()
|
||||
|
||||
adapter.Update("updateForum").Table("forums").Set("name = ?, desc = ?, active = ?, preset = ?").Where("fid = ?").Parse()
|
||||
build.Update("updateTheme").Table("themes").Set("default = ?").Where("uname = ?").Parse()
|
||||
|
||||
adapter.Update("updateUser").Table("users").Set("name = ?, email = ?, group = ?").Where("uid = ?").Parse()
|
||||
build.Update("updateForum").Table("forums").Set("name = ?, desc = ?, active = ?, preset = ?").Where("fid = ?").Parse()
|
||||
|
||||
adapter.Update("updateGroupPerms").Table("users_groups").Set("permissions = ?").Where("gid = ?").Parse()
|
||||
build.Update("updateUser").Table("users").Set("name = ?, email = ?, group = ?").Where("uid = ?").Parse()
|
||||
|
||||
adapter.Update("updateGroup").Table("users_groups").Set("name = ?, tag = ?").Where("gid = ?").Parse()
|
||||
build.Update("updateGroupPerms").Table("users_groups").Set("permissions = ?").Where("gid = ?").Parse()
|
||||
|
||||
adapter.Update("updateEmail").Table("emails").Set("email = ?, uid = ?, validated = ?, token = ?").Where("email = ?").Parse()
|
||||
build.Update("updateGroup").Table("users_groups").Set("name = ?, tag = ?").Where("gid = ?").Parse()
|
||||
|
||||
adapter.Update("verifyEmail").Table("emails").Set("validated = 1, token = ''").Where("email = ?").Parse() // Need to fix this: Empty string isn't working, it gets set to 1 instead x.x -- Has this been fixed?
|
||||
build.Update("updateEmail").Table("emails").Set("email = ?, uid = ?, validated = ?, token = ?").Where("email = ?").Parse()
|
||||
|
||||
adapter.Update("setTempGroup").Table("users").Set("temp_group = ?").Where("uid = ?").Parse()
|
||||
build.Update("verifyEmail").Table("emails").Set("validated = 1, token = ''").Where("email = ?").Parse() // Need to fix this: Empty string isn't working, it gets set to 1 instead x.x -- Has this been fixed?
|
||||
|
||||
adapter.Update("updateWordFilter").Table("word_filters").Set("find = ?, replacement = ?").Where("wfid = ?").Parse()
|
||||
build.Update("setTempGroup").Table("users").Set("temp_group = ?").Where("uid = ?").Parse()
|
||||
|
||||
adapter.Update("bumpSync").Table("sync").Set("last_update = UTC_TIMESTAMP()").Parse()
|
||||
build.Update("updateWordFilter").Table("word_filters").Set("find = ?, replacement = ?").Where("wfid = ?").Parse()
|
||||
|
||||
build.Update("bumpSync").Table("sync").Set("last_update = UTC_TIMESTAMP()").Parse()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func writeDeletes(adapter qgen.Adapter) error {
|
||||
adapter.Delete("deleteProfileReply").Table("users_replies").Where("rid = ?").Parse()
|
||||
build := adapter.Builder()
|
||||
|
||||
//adapter.Delete("deleteForumPermsByForum").Table("forums_permissions").Where("fid = ?").Parse()
|
||||
build.Delete("deleteProfileReply").Table("users_replies").Where("rid = ?").Parse()
|
||||
|
||||
adapter.Delete("deleteActivityStreamMatch").Table("activity_stream_matches").Where("watcher = ? AND asid = ?").Parse()
|
||||
//adapter.Delete("deleteActivityStreamMatchesByWatcher").Table("activity_stream_matches").Where("watcher = ?").Parse()
|
||||
//build.Delete("deleteForumPermsByForum").Table("forums_permissions").Where("fid = ?").Parse()
|
||||
|
||||
adapter.Delete("deleteWordFilter").Table("word_filters").Where("wfid = ?").Parse()
|
||||
build.Delete("deleteActivityStreamMatch").Table("activity_stream_matches").Where("watcher = ? AND asid = ?").Parse()
|
||||
//build.Delete("deleteActivityStreamMatchesByWatcher").Table("activity_stream_matches").Where("watcher = ?").Parse()
|
||||
|
||||
build.Delete("deleteWordFilter").Table("word_filters").Where("wfid = ?").Parse()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue