pr feedback

This commit is contained in:
Ari Lazier 2016-02-17 20:39:29 -08:00
parent 6374a04ed4
commit e578b05058
3 changed files with 20 additions and 24 deletions

View File

@ -6,8 +6,8 @@
#include "js_object.hpp"
#include "js_results.hpp"
#include "js_util.hpp"
#include "object_accessor.hpp"
#include "object_accessor.hpp"
#include "parser.hpp"
#include "query_builder.hpp"
@ -210,18 +210,8 @@ JSValueRef ListFiltered(JSContextRef ctx, JSObjectRef function, JSObjectRef this
RJSValidateArgumentCountIsAtLeast(argumentCount, 1);
SharedRealm sharedRealm = *RJSGetInternal<SharedRealm *>(thisObject);
std::string queryString = RJSValidatedStringForValue(ctx, arguments[0], "predicate");
std::vector<JSValueRef> args;
for (size_t i = 1; i < argumentCount; i++) {
args.push_back(arguments[i]);
}
parser::Predicate predicate = parser::parse(queryString);
query_builder::ArgumentConverter<JSValueRef, JSContextRef> arguments(ctx, args);
Query query = list->get_query();
query_builder::apply_predicate(query, predicate, arguments, *sharedRealm->config().schema, list->get_object_schema().name);
return RJSResultsCreate(ctx, sharedRealm, list->get_object_schema(), query);
return RJSResultsCreate(ctx, sharedRealm, list->get_object_schema(), query, argumentCount, arguments);
}
catch (std::exception &exp) {
if (jsException) {

View File

@ -125,19 +125,8 @@ JSValueRef ResultsFiltered(JSContextRef ctx, JSObjectRef function, JSObjectRef t
RJSValidateArgumentCountIsAtLeast(argumentCount, 1);
SharedRealm sharedRealm = *RJSGetInternal<SharedRealm *>(thisObject);
std::string queryString = RJSValidatedStringForValue(ctx, arguments[0], "predicate");
std::vector<JSValueRef> args;
for (size_t i = 1; i < argumentCount; i++) {
args.push_back(arguments[i]);
}
parser::Predicate predicate = parser::parse(queryString);
query_builder::ArgumentConverter<JSValueRef, JSContextRef> arguments(ctx, args);
Query query = results->get_query();
query_builder::apply_predicate(query, predicate, arguments, *sharedRealm->config().schema,
results->get_object_schema().name);
return RJSResultsCreate(ctx, sharedRealm, results->get_object_schema(), query);
return RJSResultsCreate(ctx, sharedRealm, results->get_object_schema(), query, argumentCount, arguments);
}
catch (std::exception &exp) {
if (jsException) {
@ -171,6 +160,21 @@ JSObjectRef RJSResultsCreate(JSContextRef ctx, SharedRealm realm, std::string cl
return RJSWrapObject<Results *>(ctx, RJSResultsClass(), new Results(realm, *object_schema, std::move(query)));
}
JSObjectRef RJSResultsCreate(JSContextRef ctx, realm::SharedRealm realm, const realm::ObjectSchema &objectSchema, realm::Query &query, size_t argumentCount, const JSValueRef arguments[]) {
std::string queryString = RJSValidatedStringForValue(ctx, arguments[0], "predicate");
std::vector<JSValueRef> args(argumentCount-1);
for (size_t i = 1; i < argumentCount; i++) {
args[i-1] = arguments[i];
}
parser::Predicate predicate = parser::parse(queryString);
query_builder::ArgumentConverter<JSValueRef, JSContextRef> queryArgs(ctx, args);
query_builder::apply_predicate(query, predicate, queryArgs, *realm->config().schema,
objectSchema.name);
return RJSResultsCreate(ctx, realm, objectSchema, query);
}
JSObjectRef RJSResultsCreate(JSContextRef ctx, SharedRealm realm, const ObjectSchema &objectSchema, const Query &query, bool live) {
Results *results = new Results(realm, objectSchema, query);
results->set_live(live);

View File

@ -16,4 +16,6 @@ namespace realm {
JSClassRef RJSResultsClass();
JSObjectRef RJSResultsCreate(JSContextRef ctx, realm::SharedRealm realm, std::string className);
JSObjectRef RJSResultsCreate(JSContextRef ctx, realm::SharedRealm realm, std::string className, std::string query, std::vector<JSValueRef> args);
JSObjectRef RJSResultsCreate(JSContextRef ctx, realm::SharedRealm realm, const realm::ObjectSchema &objectSchema, realm::Query &query, size_t argumentCount, const JSValueRef arguments[]);
JSObjectRef RJSResultsCreate(JSContextRef ctx, realm::SharedRealm realm, const realm::ObjectSchema &objectSchema, const realm::Query &query, bool live = true);