-
Notifications
You must be signed in to change notification settings - Fork 22
feat: Query method for new CouchDB storage implementation #47
feat: Query method for new CouchDB storage implementation #47
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
f4f5e00
to
f2b4c71
Compare
return nil, fmt.Errorf(failSendRequestToFindEndpoint, err) | ||
} | ||
|
||
queryWithPageSizeAndBookmarkPlaceholders := `{"selector":{"` + |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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}`, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
f2b4c71
to
a16ac6d
Compare
option(&queryOptions) | ||
} | ||
|
||
if queryOptions.PageSize == 0 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Signed-off-by: Derek Trider Derek.Trider@securekey.com