Move globals away so we can make mysql driver

This commit is contained in:
Aaron L 2016-09-08 20:41:50 -07:00
parent 1c8a9d2e39
commit 6224b1c463

View file

@ -19,7 +19,7 @@ type PostgresDriver struct {
} }
// validatedTypes are types that cannot be zero values in the database. // validatedTypes are types that cannot be zero values in the database.
var validatedTypes = []string{"uuid"} var psqlValidatedTypes = []string{"uuid"}
// NewPostgresDriver takes the database connection details as parameters and // NewPostgresDriver takes the database connection details as parameters and
// returns a pointer to a PostgresDriver object. Note that it is required to // returns a pointer to a PostgresDriver object. Note that it is required to
@ -27,14 +27,14 @@ var validatedTypes = []string{"uuid"}
// the database connection once an object has been obtained. // the database connection once an object has been obtained.
func NewPostgresDriver(user, pass, dbname, host string, port int, sslmode string) *PostgresDriver { func NewPostgresDriver(user, pass, dbname, host string, port int, sslmode string) *PostgresDriver {
driver := PostgresDriver{ driver := PostgresDriver{
connStr: BuildQueryString(user, pass, dbname, host, port, sslmode), connStr: PostgresBuildQueryString(user, pass, dbname, host, port, sslmode),
} }
return &driver return &driver
} }
// BuildQueryString for Postgres // PostgresBuildQueryString builds a query string.
func BuildQueryString(user, pass, dbname, host string, port int, sslmode string) string { func PostgresBuildQueryString(user, pass, dbname, host string, port int, sslmode string) string {
parts := []string{} parts := []string{}
if len(user) != 0 { if len(user) != 0 {
parts = append(parts, fmt.Sprintf("user=%s", user)) parts = append(parts, fmt.Sprintf("user=%s", user))
@ -163,7 +163,7 @@ func (p *PostgresDriver) Columns(schema, tableName string) ([]bdb.Column, error)
Default: colDefault, Default: colDefault,
Nullable: nullable == "YES", Nullable: nullable == "YES",
Unique: unique, Unique: unique,
Validated: isValidated(colType), Validated: psqlIsValidated(colType),
} }
columns = append(columns, column) columns = append(columns, column)
} }
@ -323,8 +323,8 @@ func (p *PostgresDriver) TranslateColumnType(c bdb.Column) bdb.Column {
} }
// isValidated checks if the database type is in the validatedTypes list. // isValidated checks if the database type is in the validatedTypes list.
func isValidated(typ string) bool { func psqlIsValidated(typ string) bool {
for _, v := range validatedTypes { for _, v := range psqlValidatedTypes {
if v == typ { if v == typ {
return true return true
} }