Skip to content

Commit

Permalink
Implementation of filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajmasar committed Dec 23, 2013
1 parent 5268302 commit 351e3c6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
21 changes: 17 additions & 4 deletions example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ int main(int argc, char* argv) {
responses = vector<shared_ptr<Response>>();
std::cout << endl;
std::cout << "========================================================================" << endl;
std::cout << " Possible actions:" << endl;
std::cout << " db_create db_drop db_list use" << endl;
std::cout << " table table_create table_drop table_list" << endl;
std::cout << " get insert remove update" << endl;
std::cout << " ACCESSING REQL: use" << endl;
std::cout << " MANIPULATING DATABASES: db_create db_drop db_list use" << endl;
std::cout << " MANIPULATING TABLES: table_create table_drop table_list" << endl;
std::cout << " WRITING DATA: insert remove update" << endl;
std::cout << " SELECTING DATA: filter get table" << endl;
std::cout << " exit" << endl;
std::cout << "========================================================================" << endl << endl;
std::cout << endl;
Expand Down Expand Up @@ -133,6 +134,18 @@ int main(int argc, char* argv) {
responses = table->insert(RQL_Array(objects))->run();
}
}
else if (action == "filter") {
string db_name = ask("db_name (leave empty for '" + conn->database + "')");
shared_ptr<RQL_Table> table;

if (db_name == "") {
table = conn->r()->table(ask("table_name"));
}
else {
table = conn->r()->db(db_name)->table(ask("table_name"));
}
responses = table->filter(RQL_Object(ask("key (string)"), RQL_String(ask("value (string)"))))->run();
}
else if (action == "get") {
string db_name = ask("db_name (leave empty for '" + conn->database + "')");
shared_ptr<RQL_Table> table;
Expand Down
35 changes: 27 additions & 8 deletions rql.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ namespace com {

};

class RQL_Function : public RQL {};
class RQL_Ordering : public RQL {};
class RQL_Pathspec : public RQL {};

class RQL_Sequence : public virtual RQL {};
class RQL_Stream : public RQL_Sequence {};


class RQL_Datum : public virtual RQL {};

class RQL_Object : public RQL_Datum {
Expand All @@ -77,6 +69,33 @@ namespace com {
}
};

class RQL_Function : public RQL {};
class RQL_Ordering : public RQL {};
class RQL_Pathspec : public RQL {};

class RQL_Sequence : public virtual RQL {
public:

shared_ptr<RQL_Sequence> filter(const RQL_Function& object) {
shared_ptr<RQL_Sequence> sequence(new RQL_Sequence());
sequence->term.set_type(Term::TermType::Term_TermType_FILTER);
*(sequence->term.add_args()) = this->term;
*(sequence->term.add_args()) = object.term;
sequence->conn = this->conn;
return sequence;
}

shared_ptr<RQL_Sequence> filter(const RQL_Object& object) {
shared_ptr<RQL_Sequence> sequence(new RQL_Sequence());
sequence->term.set_type(Term::TermType::Term_TermType_FILTER);
*(sequence->term.add_args()) = this->term;
*(sequence->term.add_args()) = object.term;
sequence->conn = this->conn;
return sequence;
}
};
class RQL_Stream : public RQL_Sequence {};

class RQL_Stream_Selection : public RQL_Stream {
public:
// "delete" is a reserved word in C++ :-(
Expand Down

0 comments on commit 351e3c6

Please sign in to comment.