add metadata to query request/response (#1215)
This commit is contained in:
parent
698ffb5bfe
commit
f96a71e4d7
|
@ -128,7 +128,7 @@ func (q *Query) setNextParameter(val string) string {
|
|||
return pname
|
||||
}
|
||||
|
||||
func (q *Query) execute(client *documentdb.DocumentDB, collection *documentdb.Collection) ([]state.QueryResult, string, error) {
|
||||
func (q *Query) execute(client *documentdb.DocumentDB, collection *documentdb.Collection) ([]state.QueryItem, string, error) {
|
||||
opts := []documentdb.CallOption{documentdb.CrossPartition()}
|
||||
if q.limit != 0 {
|
||||
opts = append(opts, documentdb.Limit(q.limit))
|
||||
|
@ -143,7 +143,7 @@ func (q *Query) execute(client *documentdb.DocumentDB, collection *documentdb.Co
|
|||
}
|
||||
token := resp.Header.Get(documentdb.HeaderContinuation)
|
||||
|
||||
ret := make([]state.QueryResult, len(items))
|
||||
ret := make([]state.QueryItem, len(items))
|
||||
for i := range items {
|
||||
ret[i].Key = items[i].ID
|
||||
ret[i].ETag = ptr.String(items[i].Etag)
|
||||
|
|
|
@ -128,19 +128,19 @@ func (q *Query) Finalize(filters string, qq *query.Query) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (q *Query) execute(ctx context.Context, collection *mongo.Collection) ([]state.QueryResult, string, error) {
|
||||
func (q *Query) execute(ctx context.Context, collection *mongo.Collection) ([]state.QueryItem, string, error) {
|
||||
cur, err := collection.Find(ctx, q.filter, []*options.FindOptions{q.opts}...)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
defer cur.Close(ctx)
|
||||
ret := []state.QueryResult{}
|
||||
ret := []state.QueryItem{}
|
||||
for cur.Next(ctx) {
|
||||
var item Item
|
||||
if err = cur.Decode(&item); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
result := state.QueryResult{
|
||||
result := state.QueryItem{
|
||||
Key: item.Key,
|
||||
ETag: &item.Etag,
|
||||
}
|
||||
|
|
|
@ -97,5 +97,6 @@ type KeyInt interface {
|
|||
}
|
||||
|
||||
type QueryRequest struct {
|
||||
Query query.Query `json:"query"`
|
||||
Query query.Query `json:"query"`
|
||||
Metadata map[string]string `json:"metadata,omitempty"`
|
||||
}
|
||||
|
|
|
@ -23,12 +23,13 @@ type BulkGetResponse struct {
|
|||
|
||||
// QueryResponse is the response object for querying state.
|
||||
type QueryResponse struct {
|
||||
Results []QueryResult `json:"results"`
|
||||
Token string `json:"token,omitempty"`
|
||||
Results []QueryItem `json:"results"`
|
||||
Token string `json:"token,omitempty"`
|
||||
Metadata map[string]string `json:"metadata,omitempty"`
|
||||
}
|
||||
|
||||
// QueryResult is an object representing a single entry in query result.
|
||||
type QueryResult struct {
|
||||
// QueryItem is an object representing a single entry in query results.
|
||||
type QueryItem struct {
|
||||
Key string `json:"key"`
|
||||
Data []byte `json:"data"`
|
||||
ETag *string `json:"etag,omitempty"`
|
||||
|
|
|
@ -35,7 +35,7 @@ type scenario struct {
|
|||
|
||||
type queryScenario struct {
|
||||
query string
|
||||
results []state.QueryResult
|
||||
results []state.QueryItem
|
||||
}
|
||||
|
||||
type TestConfig struct {
|
||||
|
@ -213,7 +213,7 @@ func ConformanceTests(t *testing.T, props map[string]string, statestore state.St
|
|||
}
|
||||
}
|
||||
`,
|
||||
results: []state.QueryResult{
|
||||
results: []state.QueryItem{
|
||||
{
|
||||
Key: fmt.Sprintf("%s-struct", key),
|
||||
Data: []byte(fmt.Sprintf("{\"message\":\"%s-test\"}", key)),
|
||||
|
|
Loading…
Reference in New Issue