1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2024-12-26 07:33:21 -05:00

Fix gorp to internally lowercase fields for Postgres

Postgres folds all unquoted column names to lowercase, and doing this
allows that to work nicely without screwing up the queries for the other
database engines.
This commit is contained in:
Aaron Lindsay 2017-11-17 21:01:06 -05:00
parent d5ca4395ac
commit 04d85cd681
3 changed files with 6 additions and 4 deletions

View File

@ -3,12 +3,12 @@ package db
import ( import (
"database/sql" "database/sql"
"fmt" "fmt"
"github.com/aclindsa/gorp"
"github.com/aclindsa/moneygo/internal/config" "github.com/aclindsa/moneygo/internal/config"
"github.com/aclindsa/moneygo/internal/handlers" "github.com/aclindsa/moneygo/internal/handlers"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq" _ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"gopkg.in/gorp.v2"
"log" "log"
"strings" "strings"
) )
@ -25,7 +25,9 @@ func GetDbMap(db *sql.DB, dbtype config.DbType) (*gorp.DbMap, error) {
Encoding: "UTF8", Encoding: "UTF8",
} }
} else if dbtype == config.Postgres { } else if dbtype == config.Postgres {
dialect = gorp.PostgresDialect{} dialect = gorp.PostgresDialect{
LowercaseFields: true,
}
} else { } else {
return nil, fmt.Errorf("Don't know gorp dialect to go with '%s' DB type", dbtype.String()) return nil, fmt.Errorf("Don't know gorp dialect to go with '%s' DB type", dbtype.String())
} }

View File

@ -1,7 +1,7 @@
package handlers package handlers
import ( import (
"gopkg.in/gorp.v2" "github.com/aclindsa/gorp"
"log" "log"
"net/http" "net/http"
"path" "path"

View File

@ -2,7 +2,7 @@ package handlers
import ( import (
"database/sql" "database/sql"
"gopkg.in/gorp.v2" "github.com/aclindsa/gorp"
"strings" "strings"
) )