Skip to content

Commit

Permalink
feat(documents/firestore): Add key return to gets and queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjholm committed Jul 19, 2021
1 parent fd418ff commit a60dff8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/plugins/document/firestore/firestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ package firestore_service
import (
"context"
"fmt"
"github.com/nitric-dev/membrane/pkg/plugins/document"
"strings"

"github.com/nitric-dev/membrane/pkg/plugins/document"

"cloud.google.com/go/firestore"
"cloud.google.com/go/pubsub"
"github.com/nitric-dev/membrane/pkg/sdk"
Expand Down Expand Up @@ -49,6 +50,7 @@ func (s *FirestoreDocService) Get(key *sdk.Key) (*sdk.Document, error) {
}

return &sdk.Document{
Key: key,
Content: value.Data(),
}, nil
}
Expand Down Expand Up @@ -155,7 +157,13 @@ func (s *FirestoreDocService) Query(collection *sdk.Collection, expressions []sd
if err != nil {
return nil, fmt.Errorf("error querying value: %v", err)
}
sdkDoc := sdk.Document{Content: docSnp.Data()}
sdkDoc := sdk.Document{
Content: docSnp.Data(),
Key: &sdk.Key{
Collection: collection,
Id: docSnp.Ref.ID,
},
}
queryResult.Documents = append(queryResult.Documents, sdkDoc)

// If query limit configured determine continue tokens
Expand Down Expand Up @@ -220,14 +228,12 @@ func (s *FirestoreDocService) getQueryRoot(collection *sdk.Collection) firestore

if parentKey == nil {
return s.client.Collection(collection.Name).Offset(0)

} else {
if parentKey.Id != "" {
return s.client.Collection(parentKey.Collection.Name).
Doc(parentKey.Id).
Collection(collection.Name).
Offset(0)

} else {
// Note there is a risk of subcollection name collison
// TODO: future YAML validation could help mitigate this
Expand Down

0 comments on commit a60dff8

Please sign in to comment.