Remove ‘url’ and ‘color’ SQL field types

This commit is contained in:
Tobie Morgan Hitchcock 2018-04-05 00:35:08 +01:00
parent b8972ae2c2
commit b988b2c890
3 changed files with 7 additions and 37 deletions

View file

@ -34,12 +34,11 @@ const (
var (
allowedTypes = []string{
"array", "boolean", "circle",
"color", "datetime", "domain",
"double", "email", "latitude",
"longitude", "number", "object",
"password", "phone", "point",
"polygon", "record", "string",
"url", "uuid",
"datetime", "domain", "double",
"email", "latitude", "longitude",
"number", "object", "password",
"phone", "point", "polygon",
"record", "string", "uuid",
}
allowedAlgorithms = []string{

View file

@ -2694,20 +2694,11 @@ func Test_Parse_Queries_Define(t *testing.T) {
},
{
sql: `DEFINE FIELD temp ON person TYPE`,
err: "Found `` but expected `array, boolean, circle, color, datetime, domain, double, email, latitude, longitude, number, object, password, phone, point, polygon, record, string, url, uuid`",
err: "Found `` but expected `array, boolean, circle, datetime, domain, double, email, latitude, longitude, number, object, password, phone, point, polygon, record, string, uuid`",
},
{
sql: `DEFINE FIELD temp ON person TYPE something`,
err: "Found `something` but expected `array, boolean, circle, color, datetime, domain, double, email, latitude, longitude, number, object, password, phone, point, polygon, record, string, url, uuid`",
},
{
sql: `DEFINE FIELD temp ON person TYPE url`,
res: &Query{Statements: []Statement{&DefineFieldStatement{
KV: "*", NS: "*", DB: "*",
Name: &Ident{"temp"},
What: Tables{&Table{"person"}},
Type: "url",
}}},
err: "Found `something` but expected `array, boolean, circle, datetime, domain, double, email, latitude, longitude, number, object, password, phone, point, polygon, record, string, uuid`",
},
{
sql: `DEFINE FIELD temp ON person TYPE email`,

View file

@ -87,12 +87,8 @@ func ConvertTo(t, k string, obj interface{}) (val interface{}, err error) {
switch t {
default:
return obj, nil
case "url":
return ConvertToUrl(obj)
case "uuid":
return ConvertToUuid(obj)
case "color":
return ConvertToColor(obj)
case "email":
return ConvertToEmail(obj)
case "phone":
@ -124,14 +120,6 @@ func ConvertTo(t, k string, obj interface{}) (val interface{}, err error) {
}
}
func ConvertToUrl(obj interface{}) (val string, err error) {
val = fmt.Sprintf("%v", obj)
if !govalidator.IsURL(val) {
err = fmt.Errorf("Expected a URL, but found '%v'", obj)
}
return
}
func ConvertToUuid(obj interface{}) (val string, err error) {
val = fmt.Sprintf("%v", obj)
if !govalidator.IsUUID(val) {
@ -156,14 +144,6 @@ func ConvertToPhone(obj interface{}) (val string, err error) {
return
}
func ConvertToColor(obj interface{}) (val string, err error) {
val = fmt.Sprintf("%v", obj)
if !govalidator.IsHexcolor(val) && !govalidator.IsRGBcolor(val) {
err = fmt.Errorf("Expected a HEX or RGB color, but found '%v'", obj)
}
return
}
func ConvertToArray(obj interface{}) (val []interface{}, err error) {
if now, ok := obj.([]interface{}); ok {
val = now