Skip to content

Commit

Permalink
FIXUP/WIP - collId first
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Mar 29, 2022
1 parent c74c836 commit dd263e4
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions core/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ type Key interface {
}

type DataStoreKey struct {
InstanceType InstanceType
CollectionId string
InstanceType InstanceType
DocKey string
FieldId string
}
Expand Down Expand Up @@ -100,7 +100,7 @@ var _ Key = (*SequenceKey)(nil)
// splitting the input using '/' as a field deliminater. It assumes
// that the input string is in the following format:
//
// /[InstanceType]/[CollectionId]/[DocKey]/[FieldId]
// /[CollectionId]/[InstanceType]/[DocKey]/[FieldId]
//
// Any properties before the above (assuming a '/' deliminator) are ignored
func NewDataStoreKey(key string) DataStoreKey {
Expand All @@ -113,8 +113,8 @@ func NewDataStoreKey(key string) DataStoreKey {
numberOfElements := len(elements)

return DataStoreKey{
InstanceType: InstanceType(elements[numberOfElements-4]),
CollectionId: elements[numberOfElements-3],
CollectionId: elements[numberOfElements-4],
InstanceType: InstanceType(elements[numberOfElements-3]),
DocKey: elements[numberOfElements-2],
FieldId: elements[numberOfElements-1],
}
Expand Down Expand Up @@ -232,12 +232,12 @@ func (k HeadStoreKey) WithFieldId(fieldId string) HeadStoreKey {
func (k DataStoreKey) ToString() string {
var result string

if k.InstanceType != "" {
result = result + "/" + string(k.InstanceType)
}
if k.CollectionId != "" {
result = result + "/" + k.CollectionId
}
if k.InstanceType != "" {
result = result + "/" + string(k.InstanceType)
}
if k.DocKey != "" {
result = result + "/" + k.DocKey
}
Expand Down Expand Up @@ -402,14 +402,14 @@ func (k DataStoreKey) PrefixEnd() DataStoreKey {
newKey.DocKey = string(bytesPrefixEnd([]byte(k.DocKey)))
return newKey
}
if k.CollectionId != "" {
newKey.CollectionId = string(bytesPrefixEnd([]byte(k.CollectionId)))
return newKey
}
if k.InstanceType != "" {
newKey.InstanceType = InstanceType(bytesPrefixEnd([]byte(k.InstanceType)))
return newKey
}
if k.CollectionId != "" {
newKey.CollectionId = string(bytesPrefixEnd([]byte(k.CollectionId)))
return newKey
}
return newKey
}

Expand Down

0 comments on commit dd263e4

Please sign in to comment.