diff --git a/api/resources/relationship.hpp b/api/resources/relationship.hpp index 5fa8389c2..110ee03dc 100644 --- a/api/resources/relationship.hpp +++ b/api/resources/relationship.hpp @@ -25,4 +25,14 @@ public: { return res.send("GET /db/data/relationship"); } + + void put(sp::Request& req, sp::Response& res) + { + return res.send("PUT /db/data/relationship"); + } + + void del(sp::Request& req, sp::Response& res) + { + return res.send("DELETE /db/data/relationship"); + } }; diff --git a/cypher/parser.cpp b/cypher/parser.cpp index b06e4d50c..7af4d2cf9 100644 --- a/cypher/parser.cpp +++ b/cypher/parser.cpp @@ -6,6 +6,7 @@ #include "debug/tree_print.hpp" #include "codegen/cppgen.hpp" #include "utils/command_line/arguments.hpp" +#include "utils/string/filereader.hpp" using std::cout; using std::endl; @@ -18,15 +19,28 @@ using std::endl; // * INPUT ARGUMENTS * // -q -> query // -v -> visitor +// -f -> file + +std::string extract_query(const vector_str& arguments) +{ + if (contain_argument(arguments, "-q")) + return get_argument(arguments, "-q", "CREATE (n {a:1, b:2}) RETURN n"); + auto default_file = "query/read/match/match-where.cypher"; + auto file = get_argument(arguments, "-f", default_file); + // TODO: error handling + return read_file(file.c_str()); +} int main(int argc, char *argv[]) { // arguments parsing auto arguments = all_arguments(argc, argv); - auto cypher_query = get_argument(arguments, "-q", "CREATE (n {name: 'Domko', age: 24}) return n"); - auto traverser = get_argument(arguments, "-t", "code"); + + // query extraction + auto cypher_query = extract_query(arguments); // traversers + auto traverser = get_argument(arguments, "-t", "code"); auto print_traverser = Traverser::sptr(new PrintVisitor(cout)); auto cppgen_traverser = Traverser::sptr(new CppGen()); std::map traversers = { diff --git a/cypher/query/read/match/match-n-m.cypher b/cypher/query/read/match/match-n-m.cypher new file mode 100644 index 000000000..b789f4b13 --- /dev/null +++ b/cypher/query/read/match/match-n-m.cypher @@ -0,0 +1 @@ +MATCH (n)-->(m) diff --git a/cypher/query/read/match/match-optional.cypher b/cypher/query/read/match/match-optional.cypher new file mode 100644 index 000000000..acf18260a --- /dev/null +++ b/cypher/query/read/match/match-optional.cypher @@ -0,0 +1 @@ +OPTIONAL MATCH (n)-[r]->(m) diff --git a/cypher/query/read/match/match-path.cypher b/cypher/query/read/match/match-path.cypher new file mode 100644 index 000000000..f7daa6166 --- /dev/null +++ b/cypher/query/read/match/match-path.cypher @@ -0,0 +1 @@ +MATCH p = (n)-->(m) diff --git a/cypher/query/read/match/match-property.cypher b/cypher/query/read/match/match-property.cypher new file mode 100644 index 000000000..72a617c34 --- /dev/null +++ b/cypher/query/read/match/match-property.cypher @@ -0,0 +1 @@ +MATCH (n {name:'Alice'})-->(m) diff --git a/cypher/query/read/match/match-where.cypher b/cypher/query/read/match/match-where.cypher new file mode 100644 index 000000000..5014ff2c1 --- /dev/null +++ b/cypher/query/read/match/match-where.cypher @@ -0,0 +1 @@ +MATCH (n:Person)-[:KNOWS]->(m:Person) WHERE n.name="Alice" diff --git a/cypher/query/read/where/where.cypher b/cypher/query/read/where/where.cypher new file mode 100644 index 000000000..41e1aadbe --- /dev/null +++ b/cypher/query/read/where/where.cypher @@ -0,0 +1 @@ +WHERE n.property <> {value} diff --git a/cypher/query/read/with/match-with-order-skip-limit.cypher b/cypher/query/read/with/match-with-order-skip-limit.cypher new file mode 100644 index 000000000..9f0dd85c0 --- /dev/null +++ b/cypher/query/read/with/match-with-order-skip-limit.cypher @@ -0,0 +1 @@ +MATCH (user)-[:FRIEND]-(friend) WITH user, count(friend) AS friends ORDER BY friends DESC SKIP 1 LIMIT 3 RETURN user diff --git a/cypher/query/read/with/match-with-where.cypher b/cypher/query/read/with/match-with-where.cypher new file mode 100644 index 000000000..ffb5371e4 --- /dev/null +++ b/cypher/query/read/with/match-with-where.cypher @@ -0,0 +1 @@ +MATCH (user)-[:FRIEND]-(friend) WHERE user.name = {name} WITH user, count(friend) AS friends WHERE friends > 10 RETURN user diff --git a/cypher/query/write/create-return.cypher b/cypher/query/write/create-return.cypher new file mode 100644 index 000000000..26b6308aa --- /dev/null +++ b/cypher/query/write/create-return.cypher @@ -0,0 +1 @@ +CREATE (n {name: 'Domko', age: 24}) RETURN n diff --git a/cypher/query/write/create.cypher b/cypher/query/write/create.cypher new file mode 100644 index 000000000..de91f83c4 --- /dev/null +++ b/cypher/query/write/create.cypher @@ -0,0 +1 @@ +CREATE (n {name: {value}}) diff --git a/mvcc/version_list.hpp b/mvcc/version_list.hpp index 45a7c9568..af7d6beb2 100644 --- a/mvcc/version_list.hpp +++ b/mvcc/version_list.hpp @@ -223,18 +223,15 @@ private: if(!record) return false; - // TODO-buda: what is this? lock_and_validate(record, t); return remove(record, t), true; } - // TODO-buda: this whole part is questionable bool remove(T* record, tx::Transaction& t) { assert(record != nullptr); lock_and_validate(record, t); record->mark_deleted(t); - // TODO-buda: is this ok, at least for now? return true; } diff --git a/storage/edge.hpp b/storage/edge.hpp index 24311c3aa..5cc4e76d4 100644 --- a/storage/edge.hpp +++ b/storage/edge.hpp @@ -1,14 +1,14 @@ #pragma once -#include "model/properties/jsonwriter.hpp" -#include "model/edge_model.hpp" #include "mvcc/record.hpp" - -class Edge; +#include "model/edge_model.hpp" +#include "model/properties/jsonwriter.hpp" class Edge : public mvcc::Record { public: + class Accessor; + Edge() = default; Edge(const EdgeModel& data) : data(data) {} Edge(EdgeModel&& data) : data(std::move(data)) {} diff --git a/storage/edge_accessor.hpp b/storage/edge_accessor.hpp new file mode 100644 index 000000000..f2018e08a --- /dev/null +++ b/storage/edge_accessor.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include "storage/edge.hpp" +#include "storage/record_accessor.hpp" + +class Edges; + +class Edge::Accessor : public RecordAccessor +{ +public: + using RecordAccessor::RecordAccessor; +}; diff --git a/storage/edges.hpp b/storage/edges.hpp index 1d044ef7f..19b7da4ca 100644 --- a/storage/edges.hpp +++ b/storage/edges.hpp @@ -1,12 +1,20 @@ #pragma once -#include "edge.hpp" #include "common.hpp" +#include "edge_accessor.hpp" class Edges { public: - // TODO: implementation + Edge::Accessor find(tx::Transaction& t, const Id& id) + { + throw std::runtime_error("not implemented"); + } + + Edge::Accessor insert(tx::Transaction& t) + { + throw std::runtime_error("not implemented"); + } private: SkipList edges; diff --git a/utils/command_line/arguments.hpp b/utils/command_line/arguments.hpp index c5d6ce618..1b3094b5d 100644 --- a/utils/command_line/arguments.hpp +++ b/utils/command_line/arguments.hpp @@ -20,15 +20,23 @@ decltype(auto) all_arguments(int argc, char *argv[]) return args; } +bool contain_argument(const vector_str& all, const string& flag) +{ + // TODO: optimize this implementation + auto it = std::find(all.begin(), all.end(), flag); + if (it == all.end()) + return false; + return true; +} + decltype(auto) get_argument(const vector_str& all, const std::string& flag, const std::string& default_value) { // TODO: optimize this implementation auto it = std::find(all.begin(), all.end(), flag); - if (it == all.end()) { + if (it == all.end()) return default_value; - } auto pos = std::distance(all.begin(), it); return all[pos + 1]; } diff --git a/utils/string/filereader.hpp b/utils/string/filereader.hpp new file mode 100644 index 000000000..0d1efc0b8 --- /dev/null +++ b/utils/string/filereader.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include +#include +#include +#include + +std::string read_file(const char *filename) +{ + std::ifstream in(filename, std::ios::in | std::ios::binary); + if (in) + return std::string(std::istreambuf_iterator(in), + std::istreambuf_iterator()); + throw(errno); +}