Add provision for enforced types, eg uuid

* Add enforced to column data
* Add enforced list to driver
* Fix bug in TitleCase (now uses regexp)
* Fix broken zero-value enforced type inserts by using RandomizeEnforcedStruct
This commit is contained in:
Patrick O'brien 2016-08-03 12:05:05 +10:00
parent 39fe91f2cb
commit c7c0fe5c0d
10 changed files with 69 additions and 20 deletions
bdb/drivers

View file

@ -17,6 +17,9 @@ type PostgresDriver struct {
dbConn *sql.DB
}
// enforcedTypes are types that cannot be zero values in the database.
var enforcedTypes = []string{"uuid"}
// NewPostgresDriver takes the database connection details as parameters and
// returns a pointer to a PostgresDriver object. Note that it is required to
// call PostgresDriver.Open() and PostgresDriver.Close() to open and close
@ -142,6 +145,7 @@ func (p *PostgresDriver) Columns(tableName string) ([]bdb.Column, error) {
Default: colDefault,
Nullable: nullable == "YES",
Unique: unique,
Enforced: isEnforced(colType),
}
columns = append(columns, column)
}
@ -293,3 +297,14 @@ func (p *PostgresDriver) TranslateColumnType(c bdb.Column) bdb.Column {
return c
}
// isEnforced checks if the database type is in the enforcedTypes list.
func isEnforced(typ string) bool {
for _, v := range enforcedTypes {
if v == typ {
return true
}
}
return false
}