Commit 511eab1e authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

started Unqlite backend

parent d26b43b8
......@@ -2,9 +2,13 @@
#define __SONATA_BACKEND_HPP
#include <sonata/RequestResult.hpp>
#include <unordered_map>
#include <functional>
#include <json/json.h>
template<typename BackendType>
class __SonataBackendRegistration;
namespace sonata {
class Backend {
......@@ -65,6 +69,9 @@ class Backend {
class BackendFactory {
template<typename BackendType>
friend class ::__SonataBackendRegistration;
public:
BackendFactory() = delete;
......@@ -78,23 +85,23 @@ class BackendFactory {
std::function<std::unique_ptr<Backend>(const Json::Value&)>> factories;
};
} // namespace sonata
#define SONATA_REGISTER_BACKEND(__backend_name, __backend_type) \
static __BackendRegistration<__backend_type> __sonata ## __backend_name ## _backend( #__backend_name );
static __SonataBackendRegistration<__backend_type> __sonata ## __backend_name ## _backend( #__backend_name )
template<typename BackendType>
class __BackendRegistration {
class __SonataBackendRegistration {
public:
template<typename FactoryType>
__BackendRegistration(const std::string& backend_name)
__SonataBackendRegistration(const std::string& backend_name)
{
BackendFactory::factories[backend_name] = [](const Json::Value& config) {
return BackendType::New(config);
sonata::BackendFactory::factories[backend_name] = [](const Json::Value& config) {
return std::make_unique<BackendType>(config);
};
}
};
}
#endif
#ifndef __REQUEST_RESULT_HPP
#define __REQUEST_RESULT_HPP
#include <string>
namespace sonata {
template<typename T>
......
# list of source files
set(sonata-client-src Client.cpp Database.cpp Collection.cpp)
set(sonata-server-src Provider.cpp)
set(sonata-server-src Provider.cpp UnQLiteBackend.cpp)
set(sonata-admin-src Admin.cpp)
# load package helper for generating cmake CONFIG packages
......
#include "sonata/Backend.hpp"
#include <json/json.h>
namespace sonata {
class UnQLiteBackend : public Backend {
public:
UnQLiteBackend(const Json::Value& config);
UnQLiteBackend(UnQLiteBackend&&) = delete;
UnQLiteBackend(const UnQLiteBackend&) = delete;
UnQLiteBackend& operator=(UnQLiteBackend&&) = delete;
UnQLiteBackend& operator=(const UnQLiteBackend&) = delete;
virtual ~UnQLiteBackend() = default;
virtual RequestResult<bool> createCollection(
const std::string& coll_name) override;
virtual RequestResult<bool> dropCollection(
const std::string& coll_name) override;
virtual RequestResult<uint64_t> store(
const std::string& coll_name,
const std::string& record) override;
virtual RequestResult<std::string> fetch(
const std::string& coll_name,
uint64_t record_id) override;
virtual RequestResult<std::string> filter(
const std::string& coll_name,
const std::string& filter_code) override;
virtual RequestResult<bool> update(
const std::string& coll_name,
uint64_t record_id,
const std::string& new_content) override;
virtual RequestResult<std::string> all(
const std::string& coll_name) override;
virtual RequestResult<uint64_t> lastID(
const std::string& coll_name) override;
virtual RequestResult<size_t> size(
const std::string& coll_name) override;
virtual RequestResult<bool> erase(
const std::string& coll_name,
uint64_t record_id) override;
virtual RequestResult<bool> destroy() override;
};
SONATA_REGISTER_BACKEND(unqlite, UnQLiteBackend);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment