gosora/query_gen/lib/micro_builders.go

243 lines
6.0 KiB
Go
Raw Normal View History

package qgen
type dateCutoff struct {
Column string
Quantity int
Unit string
}
2017-11-13 00:31:46 +00:00
type prebuilder struct {
adapter Adapter
}
func (build *prebuilder) Select(nlist ...string) *selectPrebuilder {
name := optString(nlist, "_builder")
return &selectPrebuilder{name, "", "", "", "", "", nil, nil, "", build.adapter}
2017-11-13 00:31:46 +00:00
}
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
where string
build Adapter
}
func (delete *deletePrebuilder) Table(table string) *deletePrebuilder {
delete.table = table
return delete
}
func (delete *deletePrebuilder) Where(where string) *deletePrebuilder {
Fixed a bug where it would use the wrong templates for Tempra Simple, Tempra Cursive, and Shadow Likes are now done over AJAX. Posts you have liked are now visually differentiated from those which you have not. Added support for OR to the where parser. || and && now get translated to OR and AND in the where parser. Added support for ( and ) in the where parser. Added an adapter and builder method for getting the database version. Multiple wheres can now be chained with the micro and accumulator builders. Added the In method to the accumulator select builder. Added the GetConn method to the builder. /uploads/ files should now get cached properly. Added more tooltips for topic titles and usernames. Fixed a bug in the runners where old stale templates would be served. Fixed a bug where liking topics didn't work. Began moving the database initialisation logic out of {adapter}.go and into querygen. Tweaked the alert direction to show the newest alerts rather than the oldest. Tweaked the WS JS to have it handle messages more efficiently. Partially fixed an issue where inline edited posts would lack newlines until the page is refreshed. Used arrow functions in a few places in global.js to save a few characters. Schema: Added the liked, oldestItemLikedCreatedAt and lastLiked columns to the users table. Added the createdAt column to the likes table. MySQL Update Queries: ALTER TABLE `users` ADD COLUMN `liked` INT NOT NULL DEFAULT '0' AFTER `topics`; ALTER TABLE `users` ADD COLUMN `oldestItemLikedCreatedAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `liked`; ALTER TABLE `users` ADD COLUMN `lastLiked` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `oldestItemLikedCreatedAt`; ALTER TABLE `likes` ADD COLUMN `createdAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `sentBy`; delete from `likes`; delete from `activity_stream` where `event` = 'like'; delete from `activity_stream_matches` where `asid` not in(select `asid` from `activity_stream`); update `topics` set `likeCount` = 0; update `replies` set `likeCount` = 0;
2018-03-31 05:25:27 +00:00
if delete.where != "" {
delete.where += " AND "
}
delete.where += where
return delete
}
func (delete *deletePrebuilder) Text() (string, error) {
return delete.build.SimpleDelete(delete.name, delete.table, delete.where)
}
func (delete *deletePrebuilder) Parse() {
delete.build.SimpleDelete(delete.name, delete.table, delete.where)
}
type updatePrebuilder struct {
name string
table string
set string
where string
build Adapter
}
func (update *updatePrebuilder) Table(table string) *updatePrebuilder {
update.table = table
return update
}
func (update *updatePrebuilder) Set(set string) *updatePrebuilder {
update.set = set
return update
}
func (update *updatePrebuilder) Where(where string) *updatePrebuilder {
Fixed a bug where it would use the wrong templates for Tempra Simple, Tempra Cursive, and Shadow Likes are now done over AJAX. Posts you have liked are now visually differentiated from those which you have not. Added support for OR to the where parser. || and && now get translated to OR and AND in the where parser. Added support for ( and ) in the where parser. Added an adapter and builder method for getting the database version. Multiple wheres can now be chained with the micro and accumulator builders. Added the In method to the accumulator select builder. Added the GetConn method to the builder. /uploads/ files should now get cached properly. Added more tooltips for topic titles and usernames. Fixed a bug in the runners where old stale templates would be served. Fixed a bug where liking topics didn't work. Began moving the database initialisation logic out of {adapter}.go and into querygen. Tweaked the alert direction to show the newest alerts rather than the oldest. Tweaked the WS JS to have it handle messages more efficiently. Partially fixed an issue where inline edited posts would lack newlines until the page is refreshed. Used arrow functions in a few places in global.js to save a few characters. Schema: Added the liked, oldestItemLikedCreatedAt and lastLiked columns to the users table. Added the createdAt column to the likes table. MySQL Update Queries: ALTER TABLE `users` ADD COLUMN `liked` INT NOT NULL DEFAULT '0' AFTER `topics`; ALTER TABLE `users` ADD COLUMN `oldestItemLikedCreatedAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `liked`; ALTER TABLE `users` ADD COLUMN `lastLiked` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `oldestItemLikedCreatedAt`; ALTER TABLE `likes` ADD COLUMN `createdAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `sentBy`; delete from `likes`; delete from `activity_stream` where `event` = 'like'; delete from `activity_stream_matches` where `asid` not in(select `asid` from `activity_stream`); update `topics` set `likeCount` = 0; update `replies` set `likeCount` = 0;
2018-03-31 05:25:27 +00:00
if update.where != "" {
update.where += " AND "
}
update.where += where
return update
}
func (update *updatePrebuilder) Text() (string, error) {
return update.build.SimpleUpdate(update.name, update.table, update.set, update.where)
}
func (update *updatePrebuilder) Parse() {
update.build.SimpleUpdate(update.name, update.table, update.set, update.where)
}
type selectPrebuilder struct {
name string
table string
columns string
where string
orderby string
limit string
dateCutoff *dateCutoff
inChain *selectPrebuilder
inColumn string // for inChain
build Adapter
}
func (selectItem *selectPrebuilder) Table(table string) *selectPrebuilder {
selectItem.table = table
return selectItem
}
func (selectItem *selectPrebuilder) Columns(columns string) *selectPrebuilder {
selectItem.columns = columns
return selectItem
}
func (selectItem *selectPrebuilder) Where(where string) *selectPrebuilder {
Fixed a bug where it would use the wrong templates for Tempra Simple, Tempra Cursive, and Shadow Likes are now done over AJAX. Posts you have liked are now visually differentiated from those which you have not. Added support for OR to the where parser. || and && now get translated to OR and AND in the where parser. Added support for ( and ) in the where parser. Added an adapter and builder method for getting the database version. Multiple wheres can now be chained with the micro and accumulator builders. Added the In method to the accumulator select builder. Added the GetConn method to the builder. /uploads/ files should now get cached properly. Added more tooltips for topic titles and usernames. Fixed a bug in the runners where old stale templates would be served. Fixed a bug where liking topics didn't work. Began moving the database initialisation logic out of {adapter}.go and into querygen. Tweaked the alert direction to show the newest alerts rather than the oldest. Tweaked the WS JS to have it handle messages more efficiently. Partially fixed an issue where inline edited posts would lack newlines until the page is refreshed. Used arrow functions in a few places in global.js to save a few characters. Schema: Added the liked, oldestItemLikedCreatedAt and lastLiked columns to the users table. Added the createdAt column to the likes table. MySQL Update Queries: ALTER TABLE `users` ADD COLUMN `liked` INT NOT NULL DEFAULT '0' AFTER `topics`; ALTER TABLE `users` ADD COLUMN `oldestItemLikedCreatedAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `liked`; ALTER TABLE `users` ADD COLUMN `lastLiked` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `oldestItemLikedCreatedAt`; ALTER TABLE `likes` ADD COLUMN `createdAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `sentBy`; delete from `likes`; delete from `activity_stream` where `event` = 'like'; delete from `activity_stream_matches` where `asid` not in(select `asid` from `activity_stream`); update `topics` set `likeCount` = 0; update `replies` set `likeCount` = 0;
2018-03-31 05:25:27 +00:00
if selectItem.where != "" {
selectItem.where += " AND "
}
selectItem.where += where
return selectItem
}
func (selectItem *selectPrebuilder) InQ(subBuilder *selectPrebuilder) *selectPrebuilder {
selectItem.inChain = subBuilder
return selectItem
}
func (selectItem *selectPrebuilder) Orderby(orderby string) *selectPrebuilder {
selectItem.orderby = orderby
return selectItem
}
func (selectItem *selectPrebuilder) Limit(limit string) *selectPrebuilder {
selectItem.limit = limit
return selectItem
}
// TODO: We probably want to avoid the double allocation of two builders somehow
func (selectItem *selectPrebuilder) FromAcc(accBuilder *accSelectBuilder) *selectPrebuilder {
selectItem.table = accBuilder.table
selectItem.columns = accBuilder.columns
selectItem.where = accBuilder.where
selectItem.orderby = accBuilder.orderby
selectItem.limit = accBuilder.limit
selectItem.dateCutoff = accBuilder.dateCutoff
if accBuilder.inChain != nil {
selectItem.inChain = &selectPrebuilder{"__builder", accBuilder.inChain.table, accBuilder.inChain.columns, accBuilder.inChain.where, accBuilder.inChain.orderby, accBuilder.inChain.limit, accBuilder.inChain.dateCutoff, nil, "", selectItem.build}
selectItem.inColumn = accBuilder.inColumn
}
return selectItem
}
// TODO: Add support for dateCutoff
func (selectItem *selectPrebuilder) Text() (string, error) {
return selectItem.build.SimpleSelect(selectItem.name, selectItem.table, selectItem.columns, selectItem.where, selectItem.orderby, selectItem.limit)
}
// TODO: Add support for dateCutoff
func (selectItem *selectPrebuilder) Parse() {
selectItem.build.SimpleSelect(selectItem.name, selectItem.table, selectItem.columns, selectItem.where, selectItem.orderby, selectItem.limit)
}
type insertPrebuilder struct {
name string
table string
columns string
fields string
build Adapter
}
func (insert *insertPrebuilder) Table(table string) *insertPrebuilder {
insert.table = table
return insert
}
func (insert *insertPrebuilder) Columns(columns string) *insertPrebuilder {
insert.columns = columns
return insert
}
func (insert *insertPrebuilder) Fields(fields string) *insertPrebuilder {
insert.fields = fields
return insert
}
func (insert *insertPrebuilder) Text() (string, error) {
return insert.build.SimpleInsert(insert.name, insert.table, insert.columns, insert.fields)
}
func (insert *insertPrebuilder) Parse() {
insert.build.SimpleInsert(insert.name, insert.table, insert.columns, insert.fields)
}
type countPrebuilder struct {
name string
table string
where string
limit string
build Adapter
}
func (count *countPrebuilder) Table(table string) *countPrebuilder {
count.table = table
return count
}
func (count *countPrebuilder) Where(where string) *countPrebuilder {
Fixed a bug where it would use the wrong templates for Tempra Simple, Tempra Cursive, and Shadow Likes are now done over AJAX. Posts you have liked are now visually differentiated from those which you have not. Added support for OR to the where parser. || and && now get translated to OR and AND in the where parser. Added support for ( and ) in the where parser. Added an adapter and builder method for getting the database version. Multiple wheres can now be chained with the micro and accumulator builders. Added the In method to the accumulator select builder. Added the GetConn method to the builder. /uploads/ files should now get cached properly. Added more tooltips for topic titles and usernames. Fixed a bug in the runners where old stale templates would be served. Fixed a bug where liking topics didn't work. Began moving the database initialisation logic out of {adapter}.go and into querygen. Tweaked the alert direction to show the newest alerts rather than the oldest. Tweaked the WS JS to have it handle messages more efficiently. Partially fixed an issue where inline edited posts would lack newlines until the page is refreshed. Used arrow functions in a few places in global.js to save a few characters. Schema: Added the liked, oldestItemLikedCreatedAt and lastLiked columns to the users table. Added the createdAt column to the likes table. MySQL Update Queries: ALTER TABLE `users` ADD COLUMN `liked` INT NOT NULL DEFAULT '0' AFTER `topics`; ALTER TABLE `users` ADD COLUMN `oldestItemLikedCreatedAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `liked`; ALTER TABLE `users` ADD COLUMN `lastLiked` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `oldestItemLikedCreatedAt`; ALTER TABLE `likes` ADD COLUMN `createdAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `sentBy`; delete from `likes`; delete from `activity_stream` where `event` = 'like'; delete from `activity_stream_matches` where `asid` not in(select `asid` from `activity_stream`); update `topics` set `likeCount` = 0; update `replies` set `likeCount` = 0;
2018-03-31 05:25:27 +00:00
if count.where != "" {
count.where += " AND "
}
count.where += where
return count
}
func (count *countPrebuilder) Limit(limit string) *countPrebuilder {
count.limit = limit
return count
}
func (count *countPrebuilder) Text() (string, error) {
return count.build.SimpleCount(count.name, count.table, count.where, count.limit)
}
func (count *countPrebuilder) Parse() {
count.build.SimpleCount(count.name, count.table, count.where, count.limit)
}
func optString(nlist []string, defaultStr string) string {
if len(nlist) == 0 {
return defaultStr
}
return nlist[0]
}