8f2f47e8aa
Added the IsoCode field to phrase files. Rewrote a good portion of the widget system logic. Added some tests for the widget system. Added the Online Users widget. Added a few sealed incomplete widgets like the Search & Filter Widget. Added the AllUsers method to WsHubImpl for Online Users. Please don't abuse it. Added the optional *DBTableKey field to AddColumn. Added the panel_analytics_time_range template to reduce the amount of duplication. Failed registrations now show up in red in the registration logs for Nox. Failed logins now show up in red in the login logs for Nox. Added basic h2 CSS to the other themes. Added .show_on_block_edit and .hide_on_block_edit to the other themes. Updated contributing. Updated a bunch of dates to 2019. Replaced tblKey{} with nil where possible. Switched out some &s for &s to reduce the number of possible bugs. Fixed a bug with selector messages where the inspector would get really jittery due to unnecessary DOM updates. Moved header.Zone and associated fields to the bottom of ViewTopic to reduce the chances of problems arising. Added the ZoneData field to *Header. Added IDs to the items in the forum list template. Split the fetchPhrases function into the initPhrases and fetchPhrases functions in init.js Added .colstack_sub_head. Fixed the CSS in the menu list. Removed an inline style from the simple topic like and unlike buttons. Removed an inline style from the simple topic IP button. Simplified the LoginRequired error handler. Fixed a typo in the comment prior to DatabaseError() Reduce the number of false leaves for WebSocket page transitions. Added the error zone. De-duped the logic in WsHubImpl.getUsers. Fixed a potential widget security issue. Added twenty new phrases. Added the wid column to the widgets table. You will need to run the patcher / updater for this commit.
70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
// +build pgsql
|
|
|
|
/* Copyright Azareal 2016 - 2019 */
|
|
/* Super experimental and incomplete. DON'T USE IT YET! */
|
|
package main
|
|
|
|
import (
|
|
"database/sql"
|
|
"strings"
|
|
|
|
"github.com/Azareal/Gosora/common"
|
|
"github.com/Azareal/Gosora/query_gen"
|
|
_ "github.com/lib/pq"
|
|
)
|
|
|
|
// TODO: Add support for SSL for all database drivers, not just pgsql
|
|
var dbSslmode = "disable" // verify-full
|
|
|
|
func init() {
|
|
dbAdapter = "pgsql"
|
|
_initDatabase = initPgsql
|
|
}
|
|
|
|
func initPgsql() (err error) {
|
|
// TODO: Investigate connect_timeout to see what it does exactly and whether it's relevant to us
|
|
var _dbpassword string
|
|
if common.DbConfig.Password != "" {
|
|
_dbpassword = " password='" + _escape_bit(common.DbConfig.Password) + "'"
|
|
}
|
|
// TODO: Move this bit to the query gen lib
|
|
db, err = sql.Open("postgres", "host='"+_escape_bit(common.DbConfig.Host)+"' port='"+_escape_bit(common.DbConfig.Port)+"' user='"+_escape_bit(common.DbConfig.Username)+"' dbname='"+_escape_bit(common.DbConfig.Dbname)+"'"+_dbpassword+" sslmode='"+dbSslmode+"'")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Make sure that the connection is alive
|
|
err = db.Ping()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Set the number of max open connections. How many do we need? Might need to do some tests.
|
|
db.SetMaxOpenConns(64)
|
|
db.SetMaxIdleConns(32)
|
|
|
|
// Only hold connections open for five seconds to avoid accumulating a large number of stale connections
|
|
//db.SetConnMaxLifetime(5 * time.Second)
|
|
|
|
err = _gen_pgsql()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Ready the query builder
|
|
qgen.Builder.SetConn(db)
|
|
err = qgen.Builder.SetAdapter("pgsql")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// TO-DO Handle the queries which the query generator can't handle yet
|
|
|
|
return nil
|
|
}
|
|
|
|
func _escape_bit(bit string) string {
|
|
// TODO: Write a custom parser, so that backslashes work properly in the sql.Open string. Do something similar for the database driver, if possible?
|
|
return strings.Replace(bit, "'", "\\'", -1)
|
|
}
|