{"action":"created","comment":{"url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/pulls/comments/70143999","id":70143999,"diff_hunk":"@@ -0,0 +1,166 @@\n+// Copyright 2016 MongoDB Inc.\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+// http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+#include \"catch.hpp\"\n+\n+#include <iostream>\n+\n+#include <bsoncxx/builder/stream/document.hpp>\n+#include <mongocxx/client.hpp>\n+#include <mongocxx/instance.hpp>\n+#include <mongocxx/pipeline.hpp>\n+#include <mongocxx/stdx.hpp>\n+\n+#include <mongo_odm/model.hpp>\n+#include <mongo_odm/odm_collection.hpp>\n+#include <mongo_odm/query_builder.hpp>\n+\n+using namespace mongocxx;\n+using namespace mongo_odm;\n+\n+class Bar : public mongo_odm::model<Bar> {\n+   public:\n+    int64_t w;\n+    int x1;\n+    int x2;\n+    bool y;\n+    std::string z;\n+    MONGO_ODM_MAKE_KEYS_MODEL(Bar, NVP(w), NVP(x1), NVP(x2), NVP(y), NVP(z))\n+\n+    Bar(int64_t w, int x1, int x2, bool y, std::string z) : w(w), x1(x1), x2(x2), y(y), z(z) {\n+        _id = bsoncxx::oid{bsoncxx::oid::init_tag_t{}};\n+    }\n+\n+    // default constructor\n+    Bar() {\n+        _id = bsoncxx::oid{bsoncxx::oid::init_tag_t{}};\n+    }\n+\n+    bsoncxx::oid getID() {\n+        return _id;\n+    }\n+};\n+\n+// Test ODM on class that does not rely on model\n+class Point {\n+   public:\n+    int x;\n+    int y;\n+    MONGO_ODM_MAKE_KEYS(Point, NVP(x), NVP(y));\n+};\n+\n+TEST_CASE(\"Query Builder\", \"[mongo_odm::query_builder]\") {\n+    instance::current();\n+    client conn{uri{}};\n+    collection coll = conn[\"testdb\"][\"testcollection\"];\n+    coll.delete_many({});\n+\n+    Bar::setCollection(coll);\n+    Bar(444, 1, 2, false, \"hello\").save();\n+    Bar(444, 1, 3, false, \"hello\").save();\n+    Bar(555, 10, 2, true, \"goodbye\").save();\n+\n+    SECTION(\"Test == comparison.\", \"[mongo_odm::ComparisonExpr]\") {\n+        auto res = Bar::find_one(MONGO_ODM_KEY(Bar::x1) == 1);\n+        REQUIRE(res);\n+        REQUIRE(res.value().x1 == 1);\n+\n+        res = Bar::find_one(MONGO_ODM_KEY(Bar::z) == \"hello\");\n+        REQUIRE(res);\n+        REQUIRE(res.value().z == \"hello\");\n+    }\n+\n+    SECTION(\"Test > comparison.\", \"[mongo_odm::ComparisonExpr]\") {\n+        auto res = Bar::find_one(MONGO_ODM_KEY(Bar::x1) > 1);\n+        REQUIRE(res);\n+        REQUIRE(res.value().x1 > 1);\n+    }\n+\n+    SECTION(\"Test >= comparison.\", \"[mongo_odm::ComparisonExpr]\") {\n+        auto res = Bar::find_one(MONGO_ODM_KEY(Bar::x1) >= 10);\n+        REQUIRE(res);\n+        REQUIRE(res.value().x1 >= 10);\n+    }\n+\n+    SECTION(\"Test < comparison.\", \"[mongo_odm::ComparisonExpr]\") {\n+        auto res = Bar::find_one(MONGO_ODM_KEY(Bar::x1) < 10);\n+        REQUIRE(res);\n+        REQUIRE(res.value().x1 < 10);\n+    }\n+\n+    SECTION(\"Test <= comparison.\", \"[mongo_odm::ComparisonExpr]\") {\n+        auto res = Bar::find_one(MONGO_ODM_KEY(Bar::x1) <= 1);\n+        REQUIRE(res);\n+        REQUIRE(res.value().x1 <= 1);\n+    }\n+\n+    SECTION(\"Test != comparison.\", \"[mongo_odm::ComparisonExpr]\") {\n+        auto res = Bar::find_one(MONGO_ODM_KEY(Bar::x1) != 1);\n+        REQUIRE(res);\n+        REQUIRE(res.value().x1 != 1);\n+\n+        res = Bar::find_one(MONGO_ODM_KEY(Bar::z) != \"hello\");\n+        REQUIRE(res);\n+        REQUIRE(res.value().z == \"goodbye\");\n+    }\n+\n+    SECTION(\"Test $not expression, with operator!.\", \"[mongo_odm::NotExpr]\") {\n+        auto res = Bar::find_one(!(MONGO_ODM_KEY(Bar::x1) < 10));\n+        REQUIRE(res);\n+        REQUIRE(res.value().x1 >= 10);\n+\n+        res = Bar::find_one(!(MONGO_ODM_KEY(Bar::z) == \"hello\"));\n+        REQUIRE(res);\n+        REQUIRE(res.value().z == \"goodbye\");\n+    }\n+\n+    SECTION(\"Test expression list.\", \"[mongo_odm::ExpressionList]\") {\n+        auto res = Bar::find_one((MONGO_ODM_KEY(Bar::x1) == 1, MONGO_ODM_KEY(Bar::x2) == 2,","path":"src/mongo_odm/test/query_builder.cpp","position":129,"original_position":129,"commit_id":"db9714bfb7cb1c25c2776c6b86c5f2b1e5f8db71","original_commit_id":"db9714bfb7cb1c25c2776c6b86c5f2b1e5f8db71","user":{"login":"hanumantmk","id":150922,"avatar_url":"https://avatars.githubusercontent.com/u/150922?v=3","gravatar_id":"","url":"https://api.github.com/users/hanumantmk","html_url":"https://github.com/hanumantmk","followers_url":"https://api.github.com/users/hanumantmk/followers","following_url":"https://api.github.com/users/hanumantmk/following{/other_user}","gists_url":"https://api.github.com/users/hanumantmk/gists{/gist_id}","starred_url":"https://api.github.com/users/hanumantmk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hanumantmk/subscriptions","organizations_url":"https://api.github.com/users/hanumantmk/orgs","repos_url":"https://api.github.com/users/hanumantmk/repos","events_url":"https://api.github.com/users/hanumantmk/events{/privacy}","received_events_url":"https://api.github.com/users/hanumantmk/received_events","type":"User","site_admin":false},"body":"I wonder if we shouldn't just skip the expression list version?  it's the same semantics as &&, right?","created_at":"2016-07-08T21:30:37Z","updated_at":"2016-07-08T21:30:37Z","html_url":"https://github.com/mongodb/mongo-cxx-odm/pull/8#discussion_r70143999","pull_request_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/pulls/8","_links":{"self":{"href":"https://api.github.com/repos/mongodb/mongo-cxx-odm/pulls/comments/70143999"},"html":{"href":"https://github.com/mongodb/mongo-cxx-odm/pull/8#discussion_r70143999"},"pull_request":{"href":"https://api.github.com/repos/mongodb/mongo-cxx-odm/pulls/8"}}},"pull_request":{"url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/pulls/8","id":76318299,"html_url":"https://github.com/mongodb/mongo-cxx-odm/pull/8","diff_url":"https://github.com/mongodb/mongo-cxx-odm/pull/8.diff","patch_url":"https://github.com/mongodb/mongo-cxx-odm/pull/8.patch","issue_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/issues/8","number":8,"state":"open","locked":false,"title":"Query Builder","user":{"login":"rkargon","id":5818015,"avatar_url":"https://avatars.githubusercontent.com/u/5818015?v=3","gravatar_id":"","url":"https://api.github.com/users/rkargon","html_url":"https://github.com/rkargon","followers_url":"https://api.github.com/users/rkargon/followers","following_url":"https://api.github.com/users/rkargon/following{/other_user}","gists_url":"https://api.github.com/users/rkargon/gists{/gist_id}","starred_url":"https://api.github.com/users/rkargon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkargon/subscriptions","organizations_url":"https://api.github.com/users/rkargon/orgs","repos_url":"https://api.github.com/users/rkargon/repos","events_url":"https://api.github.com/users/rkargon/events{/privacy}","received_events_url":"https://api.github.com/users/rkargon/received_events","type":"User","site_admin":false},"body":"A static expression builder for MongoDB queries that allows compile-time type and syntax checking. \r\n\r\nNote: right now this involves a macro to register members and their names, separate from Cereal's `serialize` function, which could seem redundant to users. Perhaps we'd be able to make a macro that does both at once?","created_at":"2016-07-05T18:14:52Z","updated_at":"2016-07-08T21:30:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2da1da3b67d1a8f2cb7e93c9a572bed04fa74008","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/pulls/8/commits","review_comments_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/pulls/8/comments","review_comment_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/issues/8/comments","statuses_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/statuses/db9714bfb7cb1c25c2776c6b86c5f2b1e5f8db71","head":{"label":"mongodb:query_builder","ref":"query_builder","sha":"db9714bfb7cb1c25c2776c6b86c5f2b1e5f8db71","user":{"login":"mongodb","id":45120,"avatar_url":"https://avatars.githubusercontent.com/u/45120?v=3","gravatar_id":"","url":"https://api.github.com/users/mongodb","html_url":"https://github.com/mongodb","followers_url":"https://api.github.com/users/mongodb/followers","following_url":"https://api.github.com/users/mongodb/following{/other_user}","gists_url":"https://api.github.com/users/mongodb/gists{/gist_id}","starred_url":"https://api.github.com/users/mongodb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mongodb/subscriptions","organizations_url":"https://api.github.com/users/mongodb/orgs","repos_url":"https://api.github.com/users/mongodb/repos","events_url":"https://api.github.com/users/mongodb/events{/privacy}","received_events_url":"https://api.github.com/users/mongodb/received_events","type":"Organization","site_admin":false},"repo":{"id":60376659,"name":"mongo-cxx-odm","full_name":"mongodb/mongo-cxx-odm","owner":{"login":"mongodb","id":45120,"avatar_url":"https://avatars.githubusercontent.com/u/45120?v=3","gravatar_id":"","url":"https://api.github.com/users/mongodb","html_url":"https://github.com/mongodb","followers_url":"https://api.github.com/users/mongodb/followers","following_url":"https://api.github.com/users/mongodb/following{/other_user}","gists_url":"https://api.github.com/users/mongodb/gists{/gist_id}","starred_url":"https://api.github.com/users/mongodb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mongodb/subscriptions","organizations_url":"https://api.github.com/users/mongodb/orgs","repos_url":"https://api.github.com/users/mongodb/repos","events_url":"https://api.github.com/users/mongodb/events{/privacy}","received_events_url":"https://api.github.com/users/mongodb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mongodb/mongo-cxx-odm","description":"","fork":false,"url":"https://api.github.com/repos/mongodb/mongo-cxx-odm","forks_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/forks","keys_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/teams","hooks_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/hooks","issue_events_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/issues/events{/number}","events_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/events","assignees_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/assignees{/user}","branches_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/branches{/branch}","tags_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/tags","blobs_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/git/refs{/sha}","trees_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/statuses/{sha}","languages_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/languages","stargazers_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/stargazers","contributors_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/contributors","subscribers_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/subscribers","subscription_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/subscription","commits_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/commits{/sha}","git_commits_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/git/commits{/sha}","comments_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/comments{/number}","issue_comment_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/issues/comments{/number}","contents_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/contents/{+path}","compare_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/merges","archive_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/downloads","issues_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/issues{/number}","pulls_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/pulls{/number}","milestones_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/milestones{/number}","notifications_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/labels{/name}","releases_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/releases{/id}","deployments_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/deployments","created_at":"2016-06-03T20:45:42Z","updated_at":"2016-06-21T21:43:30Z","pushed_at":"2016-07-08T21:01:33Z","git_url":"git://github.com/mongodb/mongo-cxx-odm.git","ssh_url":"git@github.com:mongodb/mongo-cxx-odm.git","clone_url":"https://github.com/mongodb/mongo-cxx-odm.git","svn_url":"https://github.com/mongodb/mongo-cxx-odm","homepage":null,"size":491,"stargazers_count":1,"watchers_count":1,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":1,"default_branch":"master"}},"base":{"label":"mongodb:master","ref":"master","sha":"9b02d4216a75a984a484c016d7a8641078b12f8f","user":{"login":"mongodb","id":45120,"avatar_url":"https://avatars.githubusercontent.com/u/45120?v=3","gravatar_id":"","url":"https://api.github.com/users/mongodb","html_url":"https://github.com/mongodb","followers_url":"https://api.github.com/users/mongodb/followers","following_url":"https://api.github.com/users/mongodb/following{/other_user}","gists_url":"https://api.github.com/users/mongodb/gists{/gist_id}","starred_url":"https://api.github.com/users/mongodb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mongodb/subscriptions","organizations_url":"https://api.github.com/users/mongodb/orgs","repos_url":"https://api.github.com/users/mongodb/repos","events_url":"https://api.github.com/users/mongodb/events{/privacy}","received_events_url":"https://api.github.com/users/mongodb/received_events","type":"Organization","site_admin":false},"repo":{"id":60376659,"name":"mongo-cxx-odm","full_name":"mongodb/mongo-cxx-odm","owner":{"login":"mongodb","id":45120,"avatar_url":"https://avatars.githubusercontent.com/u/45120?v=3","gravatar_id":"","url":"https://api.github.com/users/mongodb","html_url":"https://github.com/mongodb","followers_url":"https://api.github.com/users/mongodb/followers","following_url":"https://api.github.com/users/mongodb/following{/other_user}","gists_url":"https://api.github.com/users/mongodb/gists{/gist_id}","starred_url":"https://api.github.com/users/mongodb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mongodb/subscriptions","organizations_url":"https://api.github.com/users/mongodb/orgs","repos_url":"https://api.github.com/users/mongodb/repos","events_url":"https://api.github.com/users/mongodb/events{/privacy}","received_events_url":"https://api.github.com/users/mongodb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mongodb/mongo-cxx-odm","description":"","fork":false,"url":"https://api.github.com/repos/mongodb/mongo-cxx-odm","forks_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/forks","keys_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/teams","hooks_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/hooks","issue_events_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/issues/events{/number}","events_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/events","assignees_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/assignees{/user}","branches_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/branches{/branch}","tags_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/tags","blobs_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/git/refs{/sha}","trees_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/statuses/{sha}","languages_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/languages","stargazers_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/stargazers","contributors_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/contributors","subscribers_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/subscribers","subscription_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/subscription","commits_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/commits{/sha}","git_commits_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/git/commits{/sha}","comments_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/comments{/number}","issue_comment_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/issues/comments{/number}","contents_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/contents/{+path}","compare_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/merges","archive_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/downloads","issues_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/issues{/number}","pulls_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/pulls{/number}","milestones_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/milestones{/number}","notifications_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/labels{/name}","releases_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/releases{/id}","deployments_url":"https://api.github.com/repos/mongodb/mongo-cxx-odm/deployments","created_at":"2016-06-03T20:45:42Z","updated_at":"2016-06-21T21:43:30Z","pushed_at":"2016-07-08T21:01:33Z","git_url":"git://github.com/mongodb/mongo-cxx-odm.git","ssh_url":"git@github.com:mongodb/mongo-cxx-odm.git","clone_url":"https://github.com/mongodb/mongo-cxx-odm.git","svn_url":"https://github.com/mongodb/mongo-cxx-odm","homepage":null,"size":491,"stargazers_count":1,"watchers_count":1,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mongodb/mongo-cxx-odm/pulls/8"},"html":{"href":"https://github.com/mongodb/mongo-cxx-odm/pull/8"},"issue":{"href":"https://api.github.com/repos/mongodb/mongo-cxx-odm/issues/8"},"comments":{"href":"https://api.github.com/repos/mongodb/mongo-cxx-odm/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/mongodb/mongo-cxx-odm/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/mongodb/mongo-cxx-odm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mongodb/mongo-cxx-odm/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/mongodb/mongo-cxx-odm/statuses/db9714bfb7cb1c25c2776c6b86c5f2b1e5f8db71"}}}}
{"actor":{"display_login":"hanumantmk"}}