2017-08-06 15:22:18 +00:00
|
|
|
/* WIP Under Really Heavy Construction */
|
2017-07-12 11:05:18 +00:00
|
|
|
package qgen
|
|
|
|
|
2018-03-31 05:25:27 +00:00
|
|
|
import (
|
2022-02-21 03:53:13 +00:00
|
|
|
"database/sql"
|
|
|
|
"errors"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
2018-03-31 05:25:27 +00:00
|
|
|
)
|
2017-07-12 11:05:18 +00:00
|
|
|
|
|
|
|
func init() {
|
2022-02-21 03:32:53 +00:00
|
|
|
Registry = append(Registry,
|
|
|
|
&PgsqlAdapter{Name: "pgsql", Buffer: make(map[string]DBStmt)},
|
|
|
|
)
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 09:57:08 +00:00
|
|
|
type PgsqlAdapter struct {
|
2022-02-21 03:32:53 +00:00
|
|
|
Name string // ? - Do we really need this? Can't we hard-code this?
|
|
|
|
Buffer map[string]DBStmt
|
|
|
|
BufferOrder []string // Map iteration order is random, so we need this to track the order, so we don't get huge diffs every commit
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
// GetName gives you the name of the database adapter. In this case, it's pgsql
|
2019-10-31 07:25:56 +00:00
|
|
|
func (a *PgsqlAdapter) GetName() string {
|
2022-02-21 03:32:53 +00:00
|
|
|
return a.Name
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 07:25:56 +00:00
|
|
|
func (a *PgsqlAdapter) GetStmt(name string) DBStmt {
|
2022-02-21 03:32:53 +00:00
|
|
|
return a.Buffer[name]
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 07:25:56 +00:00
|
|
|
func (a *PgsqlAdapter) GetStmts() map[string]DBStmt {
|
2022-02-21 03:32:53 +00:00
|
|
|
return a.Buffer
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
2018-03-31 05:25:27 +00:00
|
|
|
// TODO: Implement this
|
2019-10-31 07:25:56 +00:00
|
|
|
func (a *PgsqlAdapter) BuildConn(config map[string]string) (*sql.DB, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
return nil, nil
|
2018-03-31 05:25:27 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 07:25:56 +00:00
|
|
|
func (a *PgsqlAdapter) DbVersion() string {
|
2022-02-21 03:32:53 +00:00
|
|
|
return "SELECT version()"
|
2018-05-11 05:41:51 +00:00
|
|
|
}
|
|
|
|
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
func (a *PgsqlAdapter) DropTable(name, table string) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if table == "" {
|
|
|
|
return "", errors.New("You need a name for this table")
|
|
|
|
}
|
|
|
|
q := "DROP TABLE IF EXISTS \"" + table + "\";"
|
|
|
|
a.pushStatement(name, "drop-table", q)
|
|
|
|
return q, nil
|
2018-03-31 05:25:27 +00:00
|
|
|
}
|
|
|
|
|
2017-09-10 16:57:22 +00:00
|
|
|
// TODO: Implement this
|
2017-07-12 11:05:18 +00:00
|
|
|
// We may need to change the CreateTable API to better suit PGSQL and the other database drivers which are coming up
|
2020-02-20 23:55:45 +00:00
|
|
|
func (a *PgsqlAdapter) CreateTable(name, table, charset, collation string, cols []DBTableColumn, keys []DBTableKey) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if table == "" {
|
|
|
|
return "", errors.New("You need a name for this table")
|
|
|
|
}
|
|
|
|
if len(cols) == 0 {
|
|
|
|
return "", errors.New("You can't have a table with no columns")
|
|
|
|
}
|
|
|
|
|
|
|
|
q := "CREATE TABLE \"" + table + "\" ("
|
|
|
|
for _, col := range cols {
|
|
|
|
if col.AutoIncrement {
|
|
|
|
col.Type = "serial"
|
|
|
|
} else if col.Type == "createdAt" {
|
|
|
|
col.Type = "timestamp"
|
|
|
|
} else if col.Type == "datetime" {
|
|
|
|
col.Type = "timestamp"
|
|
|
|
}
|
|
|
|
|
|
|
|
var size string
|
|
|
|
if col.Size > 0 {
|
|
|
|
size = " (" + strconv.Itoa(col.Size) + ")"
|
|
|
|
}
|
|
|
|
|
|
|
|
var end string
|
|
|
|
if col.Default != "" {
|
|
|
|
end = " DEFAULT "
|
|
|
|
if a.stringyType(col.Type) && col.Default != "''" {
|
|
|
|
end += "'" + col.Default + "'"
|
|
|
|
} else {
|
|
|
|
end += col.Default
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !col.Null {
|
|
|
|
end += " not null"
|
|
|
|
}
|
|
|
|
|
|
|
|
q += "\n\t`" + col.Name + "` " + col.Type + size + end + ","
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(keys) > 0 {
|
|
|
|
for _, key := range keys {
|
|
|
|
q += "\n\t" + key.Type
|
|
|
|
if key.Type != "unique" {
|
|
|
|
q += " key"
|
|
|
|
}
|
|
|
|
q += "("
|
|
|
|
for _, column := range strings.Split(key.Columns, ",") {
|
|
|
|
q += "`" + column + "`,"
|
|
|
|
}
|
|
|
|
q = q[0:len(q)-1] + "),"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
q = q[0:len(q)-1] + "\n);"
|
|
|
|
a.pushStatement(name, "create-table", q)
|
|
|
|
return q, nil
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
2017-09-10 16:57:22 +00:00
|
|
|
// TODO: Implement this
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
func (a *PgsqlAdapter) AddColumn(name, table string, column DBTableColumn, key *DBTableKey) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if table == "" {
|
|
|
|
return "", errors.New("You need a name for this table")
|
|
|
|
}
|
|
|
|
return "", nil
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
// TODO: Implement this
|
|
|
|
func (a *PgsqlAdapter) DropColumn(name, table, colName string) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
return "", errors.New("not implemented")
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Implement this
|
|
|
|
func (a *PgsqlAdapter) RenameColumn(name, table, oldName, newName string) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
return "", errors.New("not implemented")
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Implement this
|
|
|
|
func (a *PgsqlAdapter) ChangeColumn(name, table, colName string, col DBTableColumn) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
return "", errors.New("not implemented")
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Implement this
|
|
|
|
func (a *PgsqlAdapter) SetDefaultColumn(name, table, colName, colType, defaultStr string) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if colType == "text" {
|
|
|
|
return "", errors.New("text fields cannot have default values")
|
|
|
|
}
|
|
|
|
return "", errors.New("not implemented")
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
}
|
|
|
|
|
2018-12-31 09:03:49 +00:00
|
|
|
// TODO: Implement this
|
|
|
|
// TODO: Test to make sure everything works here
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
func (a *PgsqlAdapter) AddIndex(name, table, iname, colname string) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if table == "" {
|
|
|
|
return "", errors.New("You need a name for this table")
|
|
|
|
}
|
|
|
|
if iname == "" {
|
|
|
|
return "", errors.New("You need a name for the index")
|
|
|
|
}
|
|
|
|
if colname == "" {
|
|
|
|
return "", errors.New("You need a name for the column")
|
|
|
|
}
|
|
|
|
return "", errors.New("not implemented")
|
2018-12-31 09:03:49 +00:00
|
|
|
}
|
|
|
|
|
2019-02-23 06:29:19 +00:00
|
|
|
// TODO: Implement this
|
|
|
|
// TODO: Test to make sure everything works here
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
func (a *PgsqlAdapter) AddKey(name, table, column string, key DBTableKey) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if table == "" {
|
|
|
|
return "", errors.New("You need a name for this table")
|
|
|
|
}
|
|
|
|
if column == "" {
|
|
|
|
return "", errors.New("You need a name for the column")
|
|
|
|
}
|
|
|
|
return "", errors.New("not implemented")
|
2019-02-23 06:29:19 +00:00
|
|
|
}
|
|
|
|
|
2020-02-20 23:55:45 +00:00
|
|
|
// TODO: Implement this
|
|
|
|
// TODO: Test to make sure everything works here
|
|
|
|
func (a *PgsqlAdapter) RemoveIndex(name, table, iname string) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if table == "" {
|
|
|
|
return "", errors.New("You need a name for this table")
|
|
|
|
}
|
|
|
|
if iname == "" {
|
|
|
|
return "", errors.New("You need a name for the index")
|
|
|
|
}
|
|
|
|
return "", errors.New("not implemented")
|
2020-02-20 23:55:45 +00:00
|
|
|
}
|
|
|
|
|
2019-05-06 04:04:00 +00:00
|
|
|
// TODO: Implement this
|
|
|
|
// TODO: Test to make sure everything works here
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
func (a *PgsqlAdapter) AddForeignKey(name, table, column, ftable, fcolumn string, cascade bool) (out string, e error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
var c = func(str string, val bool) {
|
|
|
|
if e != nil || !val {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
e = errors.New("You need a " + str + " for this table")
|
|
|
|
}
|
|
|
|
c("name", table == "")
|
|
|
|
c("column", column == "")
|
|
|
|
c("ftable", ftable == "")
|
|
|
|
c("fcolumn", fcolumn == "")
|
|
|
|
if e != nil {
|
|
|
|
return "", e
|
|
|
|
}
|
|
|
|
return "", errors.New("not implemented")
|
2019-05-06 04:04:00 +00:00
|
|
|
}
|
|
|
|
|
2018-05-27 09:36:35 +00:00
|
|
|
// TODO: Test this
|
|
|
|
// ! We need to get the last ID out of this somehow, maybe add returning to every query? Might require some sort of wrapper over the sql statements
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
func (a *PgsqlAdapter) SimpleInsert(name, table, columns, fields string) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if table == "" {
|
|
|
|
return "", errors.New("You need a name for this table")
|
|
|
|
}
|
|
|
|
|
|
|
|
q := "INSERT INTO \"" + table + "\"("
|
|
|
|
if columns != "" {
|
|
|
|
q += a.buildColumns(columns) + ") VALUES ("
|
|
|
|
for _, field := range processFields(fields) {
|
|
|
|
nameLen := len(field.Name)
|
|
|
|
if field.Name[0] == '"' && field.Name[nameLen-1] == '"' && nameLen >= 3 {
|
|
|
|
field.Name = "'" + field.Name[1:nameLen-1] + "'"
|
|
|
|
}
|
|
|
|
if field.Name[0] == '\'' && field.Name[nameLen-1] == '\'' && nameLen >= 3 {
|
|
|
|
field.Name = "'" + strings.Replace(field.Name[1:nameLen-1], "'", "''", -1) + "'"
|
|
|
|
}
|
|
|
|
q += field.Name + ","
|
|
|
|
}
|
|
|
|
q = q[0 : len(q)-1]
|
|
|
|
} else {
|
|
|
|
q += ") VALUES ("
|
|
|
|
}
|
|
|
|
q += ")"
|
|
|
|
|
|
|
|
a.pushStatement(name, "insert", q)
|
|
|
|
return q, nil
|
2018-05-27 09:36:35 +00:00
|
|
|
}
|
|
|
|
|
2020-02-24 11:15:17 +00:00
|
|
|
// TODO: Implement this
|
|
|
|
func (a *PgsqlAdapter) SimpleBulkInsert(name, table, columns string, fieldSet []string) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
return "", nil
|
2020-02-24 11:15:17 +00:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func (a *PgsqlAdapter) buildColumns(cols string) (q string) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if cols == "" {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
// Escape the column names, just in case we've used a reserved keyword
|
|
|
|
for _, col := range processColumns(cols) {
|
|
|
|
if col.Type == TokenFunc {
|
|
|
|
q += col.Left + ","
|
|
|
|
} else {
|
|
|
|
q += "\"" + col.Left + "\","
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return q[0 : len(q)-1]
|
2018-05-27 09:36:35 +00:00
|
|
|
}
|
|
|
|
|
2017-09-10 16:57:22 +00:00
|
|
|
// TODO: Implement this
|
2019-12-31 21:57:54 +00:00
|
|
|
func (a *PgsqlAdapter) SimpleReplace(name, table, columns, fields string) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if table == "" {
|
|
|
|
return "", errors.New("You need a name for this table")
|
|
|
|
}
|
|
|
|
if len(columns) == 0 {
|
|
|
|
return "", errors.New("No columns found for SimpleInsert")
|
|
|
|
}
|
|
|
|
if len(fields) == 0 {
|
|
|
|
return "", errors.New("No input data found for SimpleInsert")
|
|
|
|
}
|
|
|
|
return "", nil
|
2017-10-16 07:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Implement this
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
func (a *PgsqlAdapter) SimpleUpsert(name, table, columns, fields, where string) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if table == "" {
|
|
|
|
return "", errors.New("You need a name for this table")
|
|
|
|
}
|
|
|
|
if len(columns) == 0 {
|
|
|
|
return "", errors.New("No columns found for SimpleInsert")
|
|
|
|
}
|
|
|
|
if len(fields) == 0 {
|
|
|
|
return "", errors.New("No input data found for SimpleInsert")
|
|
|
|
}
|
|
|
|
return "", nil
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
2017-09-10 16:57:22 +00:00
|
|
|
// TODO: Implemented, but we need CreateTable and a better installer to *test* it
|
2019-10-31 07:25:56 +00:00
|
|
|
func (a *PgsqlAdapter) SimpleUpdate(up *updatePrebuilder) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if up.table == "" {
|
|
|
|
return "", errors.New("You need a name for this table")
|
|
|
|
}
|
|
|
|
if up.set == "" {
|
|
|
|
return "", errors.New("You need to set data in this update statement")
|
|
|
|
}
|
|
|
|
|
|
|
|
q := "UPDATE \"" + up.table + "\" SET "
|
|
|
|
for _, item := range processSet(up.set) {
|
|
|
|
q += "`" + item.Column + "`="
|
|
|
|
for _, token := range item.Expr {
|
|
|
|
switch token.Type {
|
|
|
|
case TokenFunc:
|
|
|
|
// TODO: Write a more sophisticated function parser on the utils side.
|
|
|
|
if strings.ToUpper(token.Contents) == "UTC_TIMESTAMP()" {
|
|
|
|
token.Contents = "LOCALTIMESTAMP()"
|
|
|
|
}
|
|
|
|
q += " " + token.Contents
|
|
|
|
case TokenOp, TokenNumber, TokenSub, TokenOr:
|
|
|
|
q += " " + token.Contents
|
|
|
|
case TokenColumn:
|
|
|
|
q += " `" + token.Contents + "`"
|
|
|
|
case TokenString:
|
|
|
|
q += " '" + token.Contents + "'"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
q += ","
|
|
|
|
}
|
|
|
|
q = q[0 : len(q)-1]
|
|
|
|
|
|
|
|
// Add support for BETWEEN x.x
|
|
|
|
if len(up.where) != 0 {
|
|
|
|
q += " WHERE"
|
|
|
|
for _, loc := range processWhere(up.where) {
|
|
|
|
for _, token := range loc.Expr {
|
|
|
|
switch token.Type {
|
|
|
|
case TokenFunc:
|
|
|
|
// TODO: Write a more sophisticated function parser on the utils side. What's the situation in regards to case sensitivity?
|
|
|
|
if strings.ToUpper(token.Contents) == "UTC_TIMESTAMP()" {
|
|
|
|
token.Contents = "LOCALTIMESTAMP()"
|
|
|
|
}
|
|
|
|
q += " " + token.Contents
|
|
|
|
case TokenOp, TokenNumber, TokenSub, TokenOr, TokenNot, TokenLike:
|
|
|
|
q += " " + token.Contents
|
|
|
|
case TokenColumn:
|
|
|
|
q += " `" + token.Contents + "`"
|
|
|
|
case TokenString:
|
|
|
|
q += " '" + token.Contents + "'"
|
|
|
|
default:
|
|
|
|
panic("This token doesn't exist o_o")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
q += " AND"
|
|
|
|
}
|
|
|
|
q = q[0 : len(q)-4]
|
|
|
|
}
|
|
|
|
|
|
|
|
a.pushStatement(up.name, "update", q)
|
|
|
|
return q, nil
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-27 05:42:41 +00:00
|
|
|
// TODO: Implement this
|
2019-10-31 07:25:56 +00:00
|
|
|
func (a *PgsqlAdapter) SimpleUpdateSelect(up *updatePrebuilder) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
return "", errors.New("not implemented")
|
2018-12-27 05:42:41 +00:00
|
|
|
}
|
|
|
|
|
2017-09-10 16:57:22 +00:00
|
|
|
// TODO: Implement this
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
func (a *PgsqlAdapter) SimpleDelete(name, table, where string) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if table == "" {
|
|
|
|
return "", errors.New("You need a name for this table")
|
|
|
|
}
|
|
|
|
if where == "" {
|
|
|
|
return "", errors.New("You need to specify what data you want to delete")
|
|
|
|
}
|
|
|
|
return "", nil
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 04:57:10 +00:00
|
|
|
// TODO: Implement this
|
2019-10-31 07:25:56 +00:00
|
|
|
func (a *PgsqlAdapter) ComplexDelete(b *deletePrebuilder) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if b.table == "" {
|
|
|
|
return "", errors.New("You need a name for this table")
|
|
|
|
}
|
|
|
|
if b.where == "" {
|
|
|
|
return "", errors.New("You need to specify what data you want to delete")
|
|
|
|
}
|
|
|
|
return "", nil
|
2019-06-05 04:57:10 +00:00
|
|
|
}
|
|
|
|
|
2017-09-10 16:57:22 +00:00
|
|
|
// TODO: Implement this
|
2017-10-30 09:57:08 +00:00
|
|
|
// We don't want to accidentally wipe tables, so we'll have a separate method for purging tables instead
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
func (a *PgsqlAdapter) Purge(name, table string) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if table == "" {
|
|
|
|
return "", errors.New("You need a name for this table")
|
|
|
|
}
|
|
|
|
return "", nil
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
2017-09-10 16:57:22 +00:00
|
|
|
// TODO: Implement this
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
func (a *PgsqlAdapter) SimpleSelect(name, table, columns, where, orderby, limit string) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if table == "" {
|
|
|
|
return "", errors.New("You need a name for this table")
|
|
|
|
}
|
|
|
|
if len(columns) == 0 {
|
|
|
|
return "", errors.New("No columns found for SimpleSelect")
|
|
|
|
}
|
|
|
|
return "", nil
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
2018-01-03 07:46:18 +00:00
|
|
|
// TODO: Implement this
|
2019-10-31 07:25:56 +00:00
|
|
|
func (a *PgsqlAdapter) ComplexSelect(prebuilder *selectPrebuilder) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if prebuilder.table == "" {
|
|
|
|
return "", errors.New("You need a name for this table")
|
|
|
|
}
|
|
|
|
if len(prebuilder.columns) == 0 {
|
|
|
|
return "", errors.New("No columns found for ComplexSelect")
|
|
|
|
}
|
|
|
|
return "", nil
|
2018-01-03 07:46:18 +00:00
|
|
|
}
|
|
|
|
|
2017-09-10 16:57:22 +00:00
|
|
|
// TODO: Implement this
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
func (a *PgsqlAdapter) SimpleLeftJoin(name, table1, table2, columns, joiners, where, orderby, limit string) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if table1 == "" {
|
|
|
|
return "", errors.New("You need a name for the left table")
|
|
|
|
}
|
|
|
|
if table2 == "" {
|
|
|
|
return "", errors.New("You need a name for the right table")
|
|
|
|
}
|
|
|
|
if len(columns) == 0 {
|
|
|
|
return "", errors.New("No columns found for SimpleLeftJoin")
|
|
|
|
}
|
|
|
|
if len(joiners) == 0 {
|
|
|
|
return "", errors.New("No joiners found for SimpleLeftJoin")
|
|
|
|
}
|
|
|
|
return "", nil
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
2017-09-10 16:57:22 +00:00
|
|
|
// TODO: Implement this
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
func (a *PgsqlAdapter) SimpleInnerJoin(name, table1, table2, columns, joiners, where, orderby, limit string) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if table1 == "" {
|
|
|
|
return "", errors.New("You need a name for the left table")
|
|
|
|
}
|
|
|
|
if table2 == "" {
|
|
|
|
return "", errors.New("You need a name for the right table")
|
|
|
|
}
|
|
|
|
if len(columns) == 0 {
|
|
|
|
return "", errors.New("No columns found for SimpleInnerJoin")
|
|
|
|
}
|
|
|
|
if len(joiners) == 0 {
|
|
|
|
return "", errors.New("No joiners found for SimpleInnerJoin")
|
|
|
|
}
|
|
|
|
return "", nil
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
2017-09-10 16:57:22 +00:00
|
|
|
// TODO: Implement this
|
2019-10-31 07:25:56 +00:00
|
|
|
func (a *PgsqlAdapter) SimpleInsertSelect(name string, ins DBInsert, sel DBSelect) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
return "", nil
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
2017-09-10 16:57:22 +00:00
|
|
|
// TODO: Implement this
|
2019-10-31 07:25:56 +00:00
|
|
|
func (a *PgsqlAdapter) SimpleInsertLeftJoin(name string, ins DBInsert, sel DBJoin) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
return "", nil
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
2017-09-10 16:57:22 +00:00
|
|
|
// TODO: Implement this
|
2019-10-31 07:25:56 +00:00
|
|
|
func (a *PgsqlAdapter) SimpleInsertInnerJoin(name string, ins DBInsert, sel DBJoin) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
return "", nil
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
2017-09-10 16:57:22 +00:00
|
|
|
// TODO: Implement this
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
func (a *PgsqlAdapter) SimpleCount(name, table, where, limit string) (string, error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if table == "" {
|
|
|
|
return "", errors.New("You need a name for this table")
|
|
|
|
}
|
|
|
|
return "", nil
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 07:25:56 +00:00
|
|
|
func (a *PgsqlAdapter) Builder() *prebuilder {
|
2022-02-21 03:32:53 +00:00
|
|
|
return &prebuilder{a}
|
2017-11-12 11:29:23 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 07:25:56 +00:00
|
|
|
func (a *PgsqlAdapter) Write() error {
|
2022-02-21 03:32:53 +00:00
|
|
|
var stmts, body string
|
|
|
|
for _, name := range a.BufferOrder {
|
|
|
|
if name[0] == '_' {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
stmt := a.Buffer[name]
|
|
|
|
// TODO: Add support for create-table? Table creation might be a little complex for Go to do outside a SQL file :(
|
|
|
|
if stmt.Type != "create-table" {
|
|
|
|
stmts += "\t" + name + " *sql.Stmt\n"
|
|
|
|
body += `
|
|
|
|
common.DebugLog("Preparing ` + name + ` statement.")
|
|
|
|
stmts.` + name + `, err = db.Prepare("` + strings.Replace(stmt.Contents, "\"", "\\\"", -1) + `")
|
|
|
|
if err != nil {
|
|
|
|
log.Print("Error in ` + name + ` statement.")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Move these custom queries out of this file
|
|
|
|
out := `// +build pgsql
|
2017-07-12 11:05:18 +00:00
|
|
|
|
|
|
|
// This file was generated by Gosora's Query Generator. Please try to avoid modifying this file, as it might change at any time.
|
|
|
|
package main
|
|
|
|
|
|
|
|
import "log"
|
|
|
|
import "database/sql"
|
2022-02-21 03:53:13 +00:00
|
|
|
import "git.tuxpa.in/a/gosora/common"
|
2017-07-12 11:05:18 +00:00
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
// nolint
|
2017-11-05 09:55:34 +00:00
|
|
|
type Stmts struct {
|
2017-07-12 11:05:18 +00:00
|
|
|
` + stmts + `
|
2022-02-21 03:32:53 +00:00
|
|
|
getActivityFeedByWatcher *sql.Stmt
|
|
|
|
getActivityCountByWatcher *sql.Stmt
|
2017-11-05 09:55:34 +00:00
|
|
|
|
2022-02-21 03:32:53 +00:00
|
|
|
Mocks bool
|
2017-11-05 09:55:34 +00:00
|
|
|
}
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
// nolint
|
2017-07-12 11:05:18 +00:00
|
|
|
func _gen_pgsql() (err error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
common.DebugLog("Building the generated statements")
|
2017-07-12 11:05:18 +00:00
|
|
|
` + body + `
|
2022-02-21 03:32:53 +00:00
|
|
|
return nil
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
`
|
2022-02-21 03:32:53 +00:00
|
|
|
return writeFile("./gen_pgsql.go", out)
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Internal methods, not exposed in the interface
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
func (a *PgsqlAdapter) pushStatement(name, stype, q string) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if name == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
a.Buffer[name] = DBStmt{q, stype}
|
|
|
|
a.BufferOrder = append(a.BufferOrder, name)
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 07:25:56 +00:00
|
|
|
func (a *PgsqlAdapter) stringyType(ctype string) bool {
|
2022-02-21 03:32:53 +00:00
|
|
|
ctype = strings.ToLower(ctype)
|
|
|
|
return ctype == "char" || ctype == "varchar" || ctype == "timestamp" || ctype == "text"
|
2017-07-12 11:05:18 +00:00
|
|
|
}
|