Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

feat: Query method for new CouchDB storage implementation #47

Merged

Conversation

DRK3
Copy link
Contributor

@DRK3 DRK3 commented Jan 14, 2021

Signed-off-by: Derek Trider Derek.Trider@securekey.com

@codecov
Copy link

codecov bot commented Jan 14, 2021

Codecov Report

Merging #47 (a16ac6d) into main (3249594) will decrease coverage by 4.74%.
The diff coverage is 95.76%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #47      +/-   ##
==========================================
- Coverage   88.10%   83.36%   -4.75%     
==========================================
  Files           1        8       +7     
  Lines         227     1088     +861     
==========================================
+ Hits          200      907     +707     
- Misses         15      100      +85     
- Partials       12       81      +69     
Impacted Files Coverage Δ
component/newstorage/couchdb/store.go 90.03% <95.76%> (+1.92%) ⬆️
component/storage/mongodb/mongodb.go 84.76% <0.00%> (ø)
component/vdr/sidetree/client.go 83.39% <0.00%> (ø)
component/vdr/trustbloc/vdr.go 100.00% <0.00%> (ø)
component/didcomm/transport/amqp/inbound.go 82.55% <0.00%> (ø)
component/storage/couchdb/store.go 71.87% <0.00%> (ø)
component/vdr/sidetree/option.go 100.00% <0.00%> (ø)
component/storage/mysql/store.go 78.63% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3249594...a16ac6d. Read the comment docs.

@DRK3 DRK3 force-pushed the QueryNewCouchDBStorageImplementation branch 2 times, most recently from f4f5e00 to f2b4c71 Compare January 14, 2021 18:29
return nil, fmt.Errorf(failSendRequestToFindEndpoint, err)
}

queryWithPageSizeAndBookmarkPlaceholders := `{"selector":{"` +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above you are using Sprintf for generating the query and here you're using concatenation. Should be consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to use concatenation for the "placeholders" once since it itself actually contains formatting directives that I need passed into the iterator. The iterator has to generate new queries dynamically after the initial one for paging.

case expressionTagNameOnlyLength:
expressionTagName := expressionSplit[0]

findQuery := fmt.Sprintf(`{"selector":{"%s":{"$exists":true}},"limit":%d}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe create a const for the template.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done - added consts for both types of queries.

findQuery := fmt.Sprintf(`{"selector":{"%s":{"$exists":true}},"limit":%d}`,
expressionTagName, queryOptions.PageSize)

resultRows, err := s.db.Find(context.Background(), findQuery)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing that kind of bothers me is the use of context.Background (same with your last PR). I'm wondering if context should actually be passed in the API by the client. Not for this PR though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct - context should be passed in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a follow-up issue: #48

Signed-off-by: Derek Trider <Derek.Trider@securekey.com>
@DRK3 DRK3 force-pushed the QueryNewCouchDBStorageImplementation branch from f2b4c71 to a16ac6d Compare January 14, 2021 19:53
@DRK3 DRK3 requested a review from troyronda January 14, 2021 19:58
@troyronda troyronda merged commit ab74010 into hyperledger-aries:main Jan 14, 2021
option(&queryOptions)
}

if queryOptions.PageSize == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: you can set defaults before calling options - that way you don't need if statements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I've fixed this in #49

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants