Remove ‘url’ and ‘color’ SQL field types
This commit is contained in:
parent
b8972ae2c2
commit
b988b2c890
3 changed files with 7 additions and 37 deletions
11
sql/sql.go
11
sql/sql.go
|
@ -34,12 +34,11 @@ const (
|
||||||
var (
|
var (
|
||||||
allowedTypes = []string{
|
allowedTypes = []string{
|
||||||
"array", "boolean", "circle",
|
"array", "boolean", "circle",
|
||||||
"color", "datetime", "domain",
|
"datetime", "domain", "double",
|
||||||
"double", "email", "latitude",
|
"email", "latitude", "longitude",
|
||||||
"longitude", "number", "object",
|
"number", "object", "password",
|
||||||
"password", "phone", "point",
|
"phone", "point", "polygon",
|
||||||
"polygon", "record", "string",
|
"record", "string", "uuid",
|
||||||
"url", "uuid",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
allowedAlgorithms = []string{
|
allowedAlgorithms = []string{
|
||||||
|
|
|
@ -2694,20 +2694,11 @@ func Test_Parse_Queries_Define(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sql: `DEFINE FIELD temp ON person TYPE`,
|
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`,
|
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`",
|
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 url`,
|
|
||||||
res: &Query{Statements: []Statement{&DefineFieldStatement{
|
|
||||||
KV: "*", NS: "*", DB: "*",
|
|
||||||
Name: &Ident{"temp"},
|
|
||||||
What: Tables{&Table{"person"}},
|
|
||||||
Type: "url",
|
|
||||||
}}},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sql: `DEFINE FIELD temp ON person TYPE email`,
|
sql: `DEFINE FIELD temp ON person TYPE email`,
|
||||||
|
|
|
@ -87,12 +87,8 @@ func ConvertTo(t, k string, obj interface{}) (val interface{}, err error) {
|
||||||
switch t {
|
switch t {
|
||||||
default:
|
default:
|
||||||
return obj, nil
|
return obj, nil
|
||||||
case "url":
|
|
||||||
return ConvertToUrl(obj)
|
|
||||||
case "uuid":
|
case "uuid":
|
||||||
return ConvertToUuid(obj)
|
return ConvertToUuid(obj)
|
||||||
case "color":
|
|
||||||
return ConvertToColor(obj)
|
|
||||||
case "email":
|
case "email":
|
||||||
return ConvertToEmail(obj)
|
return ConvertToEmail(obj)
|
||||||
case "phone":
|
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) {
|
func ConvertToUuid(obj interface{}) (val string, err error) {
|
||||||
val = fmt.Sprintf("%v", obj)
|
val = fmt.Sprintf("%v", obj)
|
||||||
if !govalidator.IsUUID(val) {
|
if !govalidator.IsUUID(val) {
|
||||||
|
@ -156,14 +144,6 @@ func ConvertToPhone(obj interface{}) (val string, err error) {
|
||||||
return
|
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) {
|
func ConvertToArray(obj interface{}) (val []interface{}, err error) {
|
||||||
if now, ok := obj.([]interface{}); ok {
|
if now, ok := obj.([]interface{}); ok {
|
||||||
val = now
|
val = now
|
||||||
|
|
Loading…
Reference in a new issue