From a60dff8f6034842316fa34f6ca0fe6b017866343 Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Mon, 19 Jul 2021 15:01:10 +1000 Subject: [PATCH] feat(documents/firestore): Add key return to gets and queries. --- pkg/plugins/document/firestore/firestore.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/plugins/document/firestore/firestore.go b/pkg/plugins/document/firestore/firestore.go index 5d51d77c8..6f889db7b 100644 --- a/pkg/plugins/document/firestore/firestore.go +++ b/pkg/plugins/document/firestore/firestore.go @@ -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" @@ -49,6 +50,7 @@ func (s *FirestoreDocService) Get(key *sdk.Key) (*sdk.Document, error) { } return &sdk.Document{ + Key: key, Content: value.Data(), }, nil } @@ -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 @@ -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