Skip to content

Commit f96a71e

Browse files
authored
add metadata to query request/response (#1215)
1 parent 698ffb5 commit f96a71e

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

state/azure/cosmosdb/cosmosdb_query.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (q *Query) setNextParameter(val string) string {
128128
return pname
129129
}
130130

131-
func (q *Query) execute(client *documentdb.DocumentDB, collection *documentdb.Collection) ([]state.QueryResult, string, error) {
131+
func (q *Query) execute(client *documentdb.DocumentDB, collection *documentdb.Collection) ([]state.QueryItem, string, error) {
132132
opts := []documentdb.CallOption{documentdb.CrossPartition()}
133133
if q.limit != 0 {
134134
opts = append(opts, documentdb.Limit(q.limit))
@@ -143,7 +143,7 @@ func (q *Query) execute(client *documentdb.DocumentDB, collection *documentdb.Co
143143
}
144144
token := resp.Header.Get(documentdb.HeaderContinuation)
145145

146-
ret := make([]state.QueryResult, len(items))
146+
ret := make([]state.QueryItem, len(items))
147147
for i := range items {
148148
ret[i].Key = items[i].ID
149149
ret[i].ETag = ptr.String(items[i].Etag)

state/mongodb/mongodb_query.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,19 @@ func (q *Query) Finalize(filters string, qq *query.Query) error {
128128
return nil
129129
}
130130

131-
func (q *Query) execute(ctx context.Context, collection *mongo.Collection) ([]state.QueryResult, string, error) {
131+
func (q *Query) execute(ctx context.Context, collection *mongo.Collection) ([]state.QueryItem, string, error) {
132132
cur, err := collection.Find(ctx, q.filter, []*options.FindOptions{q.opts}...)
133133
if err != nil {
134134
return nil, "", err
135135
}
136136
defer cur.Close(ctx)
137-
ret := []state.QueryResult{}
137+
ret := []state.QueryItem{}
138138
for cur.Next(ctx) {
139139
var item Item
140140
if err = cur.Decode(&item); err != nil {
141141
return nil, "", err
142142
}
143-
result := state.QueryResult{
143+
result := state.QueryItem{
144144
Key: item.Key,
145145
ETag: &item.Etag,
146146
}

state/requests.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,6 @@ type KeyInt interface {
9797
}
9898

9999
type QueryRequest struct {
100-
Query query.Query `json:"query"`
100+
Query query.Query `json:"query"`
101+
Metadata map[string]string `json:"metadata,omitempty"`
101102
}

state/responses.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ type BulkGetResponse struct {
2323

2424
// QueryResponse is the response object for querying state.
2525
type QueryResponse struct {
26-
Results []QueryResult `json:"results"`
27-
Token string `json:"token,omitempty"`
26+
Results []QueryItem `json:"results"`
27+
Token string `json:"token,omitempty"`
28+
Metadata map[string]string `json:"metadata,omitempty"`
2829
}
2930

30-
// QueryResult is an object representing a single entry in query result.
31-
type QueryResult struct {
31+
// QueryItem is an object representing a single entry in query results.
32+
type QueryItem struct {
3233
Key string `json:"key"`
3334
Data []byte `json:"data"`
3435
ETag *string `json:"etag,omitempty"`

tests/conformance/state/state.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type scenario struct {
3535

3636
type queryScenario struct {
3737
query string
38-
results []state.QueryResult
38+
results []state.QueryItem
3939
}
4040

4141
type TestConfig struct {
@@ -213,7 +213,7 @@ func ConformanceTests(t *testing.T, props map[string]string, statestore state.St
213213
}
214214
}
215215
`,
216-
results: []state.QueryResult{
216+
results: []state.QueryItem{
217217
{
218218
Key: fmt.Sprintf("%s-struct", key),
219219
Data: []byte(fmt.Sprintf("{\"message\":\"%s-test\"}", key)),

0 commit comments

Comments
 (0)