2019-08-17 07:08:00 +03:00
|
|
|
// Copyright (c) 2014-2019 Zano Project
|
2018-12-27 18:50:45 +03:00
|
|
|
// Copyright (c) 2014-2018 The Louisdor Project
|
|
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
namespace tools
|
|
|
|
|
{
|
|
|
|
|
namespace db
|
|
|
|
|
{
|
|
|
|
|
typedef size_t container_handle;
|
|
|
|
|
const uint64_t invalid_tx_id = 0;
|
|
|
|
|
struct i_db_callback
|
|
|
|
|
{
|
|
|
|
|
virtual bool on_enum_item(uint64_t i, const void* pkey, uint64_t ks, const void* pval, uint64_t vs) = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct stat_info
|
|
|
|
|
{
|
|
|
|
|
uint64_t tx_count;
|
|
|
|
|
uint64_t write_tx_count;
|
|
|
|
|
uint64_t map_size;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct i_db_backend
|
|
|
|
|
{
|
2019-08-17 07:08:00 +03:00
|
|
|
virtual bool close() = 0;
|
2018-12-27 18:50:45 +03:00
|
|
|
virtual bool begin_transaction(bool read_only = false) = 0;
|
2019-08-17 07:08:00 +03:00
|
|
|
virtual bool commit_transaction() = 0;
|
|
|
|
|
virtual void abort_transaction() = 0;
|
|
|
|
|
virtual bool open(const std::string& path, uint64_t flags = 0) = 0;
|
|
|
|
|
virtual bool open_container(const std::string& name, container_handle& h) = 0;
|
2018-12-27 18:50:45 +03:00
|
|
|
virtual bool erase(container_handle h, const char* k, size_t s) = 0;
|
|
|
|
|
virtual uint64_t size(container_handle h) = 0;
|
|
|
|
|
virtual bool get(container_handle h, const char* k, size_t s, std::string& res_buff) = 0;
|
|
|
|
|
virtual bool set(container_handle h, const char* k, size_t s, const char* v, size_t vs) = 0;
|
|
|
|
|
virtual bool clear(container_handle h) = 0;
|
2019-08-17 07:08:00 +03:00
|
|
|
virtual bool enumerate(container_handle h, i_db_callback* pcb) = 0;
|
2018-12-27 18:50:45 +03:00
|
|
|
virtual bool get_stat_info(stat_info& si) = 0;
|
2019-08-17 07:08:00 +03:00
|
|
|
virtual ~i_db_backend() {};
|
2018-12-27 18:50:45 +03:00
|
|
|
};
|
|
|
|
|
}
|
2019-08-17 07:08:00 +03:00
|
|
|
}
|