20 #ifndef RIPPLE_PEERFINDER_STORESQDB_H_INCLUDED
21 #define RIPPLE_PEERFINDER_STORESQDB_H_INCLUDED
23 #include <ripple/basics/contract.h>
24 #include <ripple/core/SociDB.h>
25 #include <boost/optional.hpp>
28 namespace PeerFinder {
77 "FROM PeerFinder_BootstrapCache;",
87 if (!is_unspecified(endpoint))
89 cb(endpoint, valence);
95 <<
"Bad address string '" << s <<
"' in Bootcache table";
107 m_session <<
"DELETE FROM PeerFinder_BootstrapCache;";
116 for (
auto const& e : v)
122 m_session <<
"INSERT INTO PeerFinder_BootstrapCache ( "
128 soci::use(s), soci::use(valence);
143 boost::optional<int> vO;
146 "FROM SchemaVersion WHERE "
147 " name = 'PeerFinder';",
150 version = vO.value_or(0);
153 <<
"Opened version " << version <<
" database";
164 Throw<std::runtime_error>(
165 "The PeerFinder database version is higher than expected");
175 m_session <<
"CREATE TABLE IF NOT EXISTS "
176 "PeerFinder_BootstrapCache_Next ( "
177 " id INTEGER PRIMARY KEY AUTOINCREMENT, "
178 " address TEXT UNIQUE NOT NULL, "
182 m_session <<
"CREATE INDEX IF NOT EXISTS "
183 " PeerFinder_BootstrapCache_Next_Index ON "
184 " PeerFinder_BootstrapCache_Next "
188 m_session <<
"SELECT COUNT(*) FROM PeerFinder_BootstrapCache;",
201 "FROM PeerFinder_BootstrapCache;",
203 soci::into(valence));
210 if (!is_unspecified(entry.
endpoint))
218 <<
"' in Bootcache table";
230 for (
auto iter(list.
cbegin()); iter != list.
cend(); ++iter)
236 m_session <<
"INSERT INTO PeerFinder_BootstrapCache_Next ( "
242 soci::use(s), soci::use(valence);
245 m_session <<
"DROP TABLE IF EXISTS PeerFinder_BootstrapCache;";
248 <<
"DROP INDEX IF EXISTS PeerFinder_BootstrapCache_Index;";
250 m_session <<
"ALTER TABLE PeerFinder_BootstrapCache_Next "
251 " RENAME TO PeerFinder_BootstrapCache;";
253 m_session <<
"CREATE INDEX IF NOT EXISTS "
254 " PeerFinder_BootstrapCache_Index ON "
255 "PeerFinder_BootstrapCache "
267 m_session <<
"DROP TABLE IF EXISTS LegacyEndpoints;";
269 m_session <<
"DROP TABLE IF EXISTS PeerFinderLegacyEndpoints;";
271 m_session <<
"DROP TABLE IF EXISTS PeerFinder_LegacyEndpoints;";
274 <<
"DROP TABLE IF EXISTS PeerFinder_LegacyEndpoints_Index;";
279 m_session <<
"INSERT OR REPLACE INTO SchemaVersion ("
283 " 'PeerFinder', :version "
296 m_session <<
"PRAGMA encoding=\"UTF-8\";";
298 m_session <<
"CREATE TABLE IF NOT EXISTS SchemaVersion ( "
299 " name TEXT PRIMARY KEY, "
303 m_session <<
"CREATE TABLE IF NOT EXISTS PeerFinder_BootstrapCache ( "
304 " id INTEGER PRIMARY KEY AUTOINCREMENT, "
305 " address TEXT UNIQUE NOT NULL, "
309 m_session <<
"CREATE INDEX IF NOT EXISTS "
310 " PeerFinder_BootstrapCache_Index ON "
311 "PeerFinder_BootstrapCache "
SociConfig is used when a client wants to delay opening a soci::session after parsing the config para...
StoreSqdb(beast::Journal journal=beast::Journal{beast::Journal::getNullSink()})
Database persistence for PeerFinder using SQLite.
void open(SociConfig const &sociConfig)
std::string to_string(ListDisposition disposition)
Abstract persistence for PeerFinder data.
void save(std::vector< Entry > const &v) override
static Sink & getNullSink()
Returns a Sink which does nothing.
A generic endpoint for log messages.
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static Endpoint from_string(std::string const &s)
void open(soci::session &s) const
A version-independent IP address and port combination.
std::size_t load(load_callback const &cb) override
std::string connectionString() const
beast::IP::Endpoint endpoint