Skip to content

Commit

Permalink
refactor: Unify Field Kind and Schema properties (#2414)
Browse files Browse the repository at this point in the history
## Relevant issue(s)

Resolves #2409

## Description

Unifies the Field Kind and Schema properties.
  • Loading branch information
AndrewSisley authored Mar 19, 2024
1 parent d1b1a76 commit 85eca12
Show file tree
Hide file tree
Showing 66 changed files with 721 additions and 1,184 deletions.
5 changes: 0 additions & 5 deletions client/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ type FieldDefinition struct {
// Must contain a valid value. It is currently immutable.
Kind FieldKind

// Schema contains the schema name of the type this field contains if this field is
// a relation field. Otherwise this will be empty.
Schema string

// RelationName the name of the relationship that this field represents if this field is
// a relation field. Otherwise this will be empty.
RelationName string
Expand All @@ -102,7 +98,6 @@ func NewFieldDefinition(local CollectionFieldDescription, global SchemaFieldDesc
Name: global.Name,
ID: local.ID,
Kind: global.Kind,
Schema: global.Schema,
RelationName: global.RelationName,
Typ: global.Typ,
IsPrimaryRelation: global.IsPrimaryRelation,
Expand Down
14 changes: 8 additions & 6 deletions client/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ func validateFieldSchema(val any, field SchemaFieldDescription) (any, error) {
}
}

if field.Kind.IsObjectArray() {
return nil, NewErrFieldOrAliasToFieldNotExist(field.Name)
}

if field.Kind.IsObject() {
return getString(val)
}

switch field.Kind {
case FieldKind_DocID, FieldKind_NILLABLE_STRING, FieldKind_NILLABLE_BLOB:
return getString(val)
Expand Down Expand Up @@ -238,12 +246,6 @@ func validateFieldSchema(val any, field SchemaFieldDescription) (any, error) {
case FieldKind_NILLABLE_INT_ARRAY:
return getNillableArray(val, getInt64)

case FieldKind_FOREIGN_OBJECT:
return getString(val)

case FieldKind_FOREIGN_OBJECT_ARRAY:
return nil, NewErrFieldOrAliasToFieldNotExist(field.Name)

case FieldKind_NILLABLE_JSON:
return getJSON(val)
}
Expand Down
Loading

0 comments on commit 85eca12

Please sign in to comment.