-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Deprecate CollectionDescription.Schema #1939
Changes from 27 commits
e337116
a9b989b
9bc9698
fbe58e5
1b0dbbb
a72e05f
1e0d5c2
d55c679
4185bb7
8f254ac
d90aa53
c2f96c7
a74d0ce
7377b55
3962eda
c17b367
62cda9c
2cd7d99
7ad61ca
2206d7e
84a8111
8ca2935
36d1b12
511b1bc
5617202
cf14555
ae291b3
81d8078
1fc3e0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ | |
ID uint32 | ||
|
||
// Schema contains the data type information that this Collection uses. | ||
// | ||
// This property is deprecated and should not be used. | ||
Schema SchemaDescription | ||
|
||
// Indexes contains the secondary indexes that this Collection has. | ||
|
@@ -41,12 +43,21 @@ | |
|
||
// GetFieldByID searches for a field with the given ID. If such a field is found it | ||
// will return it and true, if it is not found it will return false. | ||
func (col CollectionDescription) GetFieldByID(id FieldID) (FieldDescription, bool) { | ||
if !col.Schema.IsEmpty() { | ||
for _, field := range col.Schema.Fields { | ||
if field.ID == id { | ||
return field, true | ||
} | ||
func (col CollectionDescription) GetFieldByID(id FieldID, schema *SchemaDescription) (FieldDescription, bool) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: This and the couple other methods bellow no longer need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this and the others remain here as whilst they currently only access stuff on the schema, that is because the stuff they access is incorrectly on the schema. For example, in this case we are getting fields by their ID, FieldID is a local concept that should exist only on collection, not on schema. The function is located in the correct place, but for historical reasons the data structures are incorrect and need to be changed along with the implementation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for clarifying |
||
for _, field := range schema.Fields { | ||
if field.ID == id { | ||
return field, true | ||
} | ||
} | ||
return FieldDescription{}, false | ||
} | ||
|
||
// GetFieldByName returns the field for the given field name. If such a field is found it | ||
// will return it and true, if it is not found it will return false. | ||
func (col CollectionDescription) GetFieldByName(fieldName string, schema *SchemaDescription) (FieldDescription, bool) { | ||
for _, field := range schema.Fields { | ||
if field.Name == fieldName { | ||
return field, true | ||
} | ||
} | ||
return FieldDescription{}, false | ||
|
@@ -57,8 +68,9 @@ | |
relationName string, | ||
otherCollectionName string, | ||
otherFieldName string, | ||
schema *SchemaDescription, | ||
) (FieldDescription, bool) { | ||
for _, field := range col.Schema.Fields { | ||
for _, field := range schema.Fields { | ||
if field.RelationName == relationName && !(col.Name == otherCollectionName && otherFieldName == field.Name) { | ||
return field, true | ||
} | ||
|
@@ -93,28 +105,11 @@ | |
Fields []FieldDescription | ||
} | ||
|
||
// IsEmpty returns true if the SchemaDescription is empty and uninitialized | ||
func (sd SchemaDescription) IsEmpty() bool { | ||
return len(sd.Fields) == 0 | ||
} | ||
|
||
// GetFieldKey returns the field ID for the given field name. | ||
func (sd SchemaDescription) GetFieldKey(fieldName string) uint32 { | ||
for _, field := range sd.Fields { | ||
if field.Name == fieldName { | ||
return uint32(field.ID) | ||
} | ||
} | ||
return uint32(0) | ||
} | ||
|
||
// GetField returns the field of the given name. | ||
func (sd SchemaDescription) GetField(name string) (FieldDescription, bool) { | ||
if !sd.IsEmpty() { | ||
for _, field := range sd.Fields { | ||
if field.Name == name { | ||
return field, true | ||
} | ||
for _, field := range sd.Fields { | ||
if field.Name == name { | ||
return field, true | ||
} | ||
} | ||
return FieldDescription{}, false | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: I'm a little worried that the name is so close to
CollectionDescription
that it will be a source of confusion. What do you think ofCollectionInfo
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dislike
CollectionInfo
as it suffers from being a little ambiguous - could be read as containing info about what data is in the collection too (e.g. doc count),CollectionDefinition
suffers less from that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably think of something better then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried, and
CollectionDefinition
was the best I could come up with without spending an unreasonable amount of time on it. I'm fairly happy with it given the problem.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting here for future reference:
I feel like
client.SchemaDescription
should just beclient.Schema
andclient.CollectionDescription
should beclient.Collection
. The interface should have a different name. Probably something likeclient.CollectionAPI
orclient.CollectionHandler
.This way,
client.CollectionDefinition
would work.