Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the capability of createIndex to take index expression in N1QL (i… #1175

Merged
merged 4 commits into from
Jun 2, 2021

Conversation

jianminzhao
Copy link
Contributor

…n addition to JSON). #CBL-1939

Copy link
Collaborator

@snej snej left a comment

Choose a reason for hiding this comment

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

We need some more tests, too --

  • of regular value indexes
  • of using the C API.

@@ -242,7 +261,7 @@ static C4SliceResult getIndexes(C4Database* database, bool fullInfo, C4Error* ou
enc.beginDictionary();
enc.writeKey("name"); enc.writeString(spec.name);
enc.writeKey("type"); enc.writeInt(spec.type);
enc.writeKey("expr"); enc.writeString(spec.expressionJSON);
enc.writeKey("expr"); enc.writeString(spec.expression);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It'd be easy to add a language key with the language, so let's do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do I write an enum (integer) or string, "n1ql" or "json" ?

_doc = Doc::fromJSON(expressionJSON);
} catch (const FleeceException &) {
error::_throw(error::InvalidQuery, "Invalid JSON in index expression");
if (queryLanguage == QueryLanguage::kJSON) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is cleaner as a switch. Leave out the default: label, so the compiler will warn if any extra enum value is added in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, will do it.

slice expressionJSON,
IndexSpec::Type type,
const IndexSpec::Options* options)
bool KeyStore::createIndex2(slice name,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I'd prefer this be named just createIndex, since C++ allows overloading.

Copy link
Member

Choose a reason for hiding this comment

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

Same for me! This method already has some default parameters, the query language could be another so it doesn't even have to be overloaded if you add it at the end. Overloading works too though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed accordingly.

slice expressionJSON,
IndexSpec::Type type,
const IndexSpec::Options* options)
bool KeyStore::createIndex2(slice name,
Copy link
Member

Choose a reason for hiding this comment

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

Same for me! This method already has some default parameters, the query language could be another so it doesn't even have to be overloaded if you add it at the end. Overloading works too though.

Copy link
Collaborator

@pasin pasin left a comment

Choose a reason for hiding this comment

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

I don't have additional comments.

@jianminzhao jianminzhao requested review from snej and borrrden June 2, 2021 00:13
@jianminzhao jianminzhao merged commit 63d918b into master Jun 2, 2021
@jianminzhao jianminzhao deleted the query/index/cbl-1939 branch June 2, 2021 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants