RecordProxy work in progres... Initial test case for VertexProxy
This commit is contained in:
parent
126b95b454
commit
d7ae5e69ce
@ -8,8 +8,7 @@
|
||||
* well, only if you're editing the template file, that's ok :)
|
||||
*/
|
||||
|
||||
#ifndef MEMGRAPH_API_RESOURCES_INCLUDE_HPP
|
||||
#define MEMGRAPH_API_RESOURCES_INCLUDE_HPP
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
@ -47,5 +46,3 @@ void init(ioc::Container& container)
|
||||
// insert<Node>("/node/{id:\\d+}");
|
||||
<INIT>
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -19,18 +19,21 @@ public:
|
||||
auto& transaction = db->tx_engine.begin();
|
||||
|
||||
// insert a new vertex
|
||||
auto vertex = db->graph.vertices.insert(transaction);
|
||||
auto vertex_proxy = db->graph.vertices.insert(transaction);
|
||||
|
||||
// map fields
|
||||
for(auto it = req.json.MemberBegin(); it != req.json.MemberEnd(); ++it)
|
||||
{
|
||||
vertex->data.props.set<String>(it->name.GetString(), it->value.GetString());
|
||||
vertex_proxy.property<std::string, std::string>(
|
||||
it->name.GetString(),
|
||||
it->value.GetString()
|
||||
);
|
||||
}
|
||||
|
||||
// commit the transaction
|
||||
transaction.commit();
|
||||
|
||||
return vertex;
|
||||
return vertex_proxy.version();
|
||||
},
|
||||
[&req, &res](Vertex* node) {
|
||||
return res.send(properties_to_string(node));
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef MEMGRAPH_API_RESOURCES_RELATIONSHIP_HPP
|
||||
#define MEMGRAPH_API_RESOURCES_RELATIONSHIP_HPP
|
||||
#pragma once
|
||||
|
||||
#include "api/restful/resource.hpp"
|
||||
|
||||
@ -27,5 +26,3 @@ public:
|
||||
return res.send("GET /db/data/relationship");
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef MEMGRAPH_API_RESTFUL_RESOURCE_HPP
|
||||
#define MEMGRAPH_API_RESTFUL_RESOURCE_HPP
|
||||
#pragma once
|
||||
|
||||
#include "api/restful/restful_resource.hpp"
|
||||
|
||||
@ -49,5 +48,3 @@ protected:
|
||||
private:
|
||||
std::once_flag once_flag;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef MEMGRAPH_API_RESTFUL_RESTFUL_RESOURCE_HPP
|
||||
#define MEMGRAPH_API_RESTFUL_RESTFUL_RESOURCE_HPP
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
@ -155,5 +154,3 @@ public:
|
||||
Restful(T& resource, sp::Speedy& app, const std::string& path)
|
||||
: detail::Methods<T, Ms...>(resource, app, path) {}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -20,11 +20,6 @@ public:
|
||||
value.accept(*this);
|
||||
}
|
||||
|
||||
void handle(Null&)
|
||||
{
|
||||
buffer << "NULL";
|
||||
}
|
||||
|
||||
void handle(Bool& b)
|
||||
{
|
||||
buffer << (b.value() ? "true" : "false");
|
||||
|
@ -2,11 +2,32 @@
|
||||
|
||||
#include "transactions/transaction.hpp"
|
||||
#include "mvcc/version_list.hpp"
|
||||
#include "storage/model/properties/property.hpp"
|
||||
|
||||
template <class T, class Store, class Derived>
|
||||
template <typename T, typename Store, typename Derived>
|
||||
class RecordProxy
|
||||
{
|
||||
public:
|
||||
RecordProxy(T* record, Store *store, mvcc::VersionList<T> *version_list) :
|
||||
record(record), store(store), version_list(version_list)
|
||||
{
|
||||
}
|
||||
|
||||
RecordProxy(const RecordProxy& record_proxy) = delete;
|
||||
|
||||
RecordProxy(RecordProxy&& other) :
|
||||
record(other.record), store(other.store), version_list(other.version_list)
|
||||
{
|
||||
other.record = nullptr;
|
||||
other.store = nullptr;
|
||||
other.version_list = nullptr;
|
||||
}
|
||||
|
||||
~RecordProxy()
|
||||
{
|
||||
// TODO: implementation
|
||||
}
|
||||
|
||||
Derived update(tx::Transaction& transaction) const
|
||||
{
|
||||
// TODO: implementation
|
||||
@ -20,6 +41,24 @@ public:
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
template<typename K>
|
||||
Property* property(const K& key) const
|
||||
{
|
||||
return record->data.props.find(key);
|
||||
}
|
||||
|
||||
template<typename K, typename V>
|
||||
void property(const K& key, const V& value)
|
||||
{
|
||||
record->data.props.template set<String>(key, value);
|
||||
// TODO: update the index
|
||||
}
|
||||
|
||||
T* version()
|
||||
{
|
||||
return record;
|
||||
}
|
||||
|
||||
private:
|
||||
T* record;
|
||||
Store *store;
|
||||
|
@ -1,9 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "record_proxy.hpp"
|
||||
#include "vertices.hpp"
|
||||
|
||||
class Vertices;
|
||||
|
||||
class VertexProxy : public RecordProxy<Vertex, Vertices, VertexProxy>
|
||||
{
|
||||
// TODO: implementation
|
||||
using RecordProxy::RecordProxy;
|
||||
};
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "vertex.hpp"
|
||||
#include "common.hpp"
|
||||
#include "vertex_proxy.hpp"
|
||||
|
||||
class Vertices
|
||||
{
|
||||
@ -22,7 +23,7 @@ public:
|
||||
return vertex;
|
||||
}
|
||||
|
||||
Vertex* insert(tx::Transaction& transaction)
|
||||
VertexProxy insert(tx::Transaction& transaction)
|
||||
{
|
||||
// get next vertex id
|
||||
auto next = counter.next(std::memory_order_acquire);
|
||||
@ -39,7 +40,9 @@ public:
|
||||
auto vertex_accessor = inserted_vertex_record->second.access(transaction);
|
||||
auto vertex = vertex_accessor.insert();
|
||||
|
||||
return vertex;
|
||||
VertexProxy vertex_proxy(vertex, this, &inserted_vertex_record->second);
|
||||
|
||||
return vertex_proxy;
|
||||
}
|
||||
|
||||
Vertex* update(tx::Transaction& transaction, const Id& id)
|
||||
|
Loading…
Reference in New Issue
Block a user