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 {
72 soci::statement st = (
m_session.prepare <<
76 "FROM PeerFinder_BootstrapCache;"
78 , soci::into (valence)
87 if (!is_unspecified (endpoint))
89 cb (endpoint, valence);
95 "Bad address string '" << s <<
"' in Bootcache table";
107 "DELETE FROM PeerFinder_BootstrapCache;";
116 for (
auto const& e : v)
123 "INSERT INTO PeerFinder_BootstrapCache ( "
130 , soci::use (valence);
144 boost::optional<int> vO;
148 "FROM SchemaVersion WHERE "
149 " name = 'PeerFinder';"
153 version = vO.value_or (0);
156 "Opened version " << version <<
" database";
167 Throw<std::runtime_error> (
168 "The PeerFinder database version is higher than expected");
179 "CREATE TABLE IF NOT EXISTS PeerFinder_BootstrapCache_Next ( "
180 " id INTEGER PRIMARY KEY AUTOINCREMENT, "
181 " address TEXT UNIQUE NOT NULL, "
187 "CREATE INDEX IF NOT EXISTS "
188 " PeerFinder_BootstrapCache_Next_Index ON "
189 " PeerFinder_BootstrapCache_Next "
195 "SELECT COUNT(*) FROM PeerFinder_BootstrapCache;"
205 soci::statement st = (
m_session.prepare <<
209 "FROM PeerFinder_BootstrapCache;"
211 , soci::into (valence)
219 if (!is_unspecified (entry.
endpoint))
227 "Bad address string '" << s <<
"' in Bootcache table";
239 for (
auto iter (list.
cbegin ());
240 iter != list.
cend (); ++iter)
247 "INSERT INTO PeerFinder_BootstrapCache_Next ( "
254 , soci::use (valence)
260 "DROP TABLE IF EXISTS PeerFinder_BootstrapCache;";
263 "DROP INDEX IF EXISTS PeerFinder_BootstrapCache_Index;";
266 "ALTER TABLE PeerFinder_BootstrapCache_Next "
267 " RENAME TO PeerFinder_BootstrapCache;";
270 "CREATE INDEX IF NOT EXISTS "
271 " PeerFinder_BootstrapCache_Index ON "
272 "PeerFinder_BootstrapCache "
286 "DROP TABLE IF EXISTS LegacyEndpoints;";
289 "DROP TABLE IF EXISTS PeerFinderLegacyEndpoints;";
292 "DROP TABLE IF EXISTS PeerFinder_LegacyEndpoints;";
295 "DROP TABLE IF EXISTS PeerFinder_LegacyEndpoints_Index;";
301 "INSERT OR REPLACE INTO SchemaVersion ("
305 " 'PeerFinder', :version "
317 m_session <<
"PRAGMA encoding=\"UTF-8\";";
320 "CREATE TABLE IF NOT EXISTS SchemaVersion ( "
321 " name TEXT PRIMARY KEY, "
327 "CREATE TABLE IF NOT EXISTS PeerFinder_BootstrapCache ( "
328 " id INTEGER PRIMARY KEY AUTOINCREMENT, "
329 " address TEXT UNIQUE NOT NULL, "
335 "CREATE INDEX IF NOT EXISTS "
336 " PeerFinder_BootstrapCache_Index ON "
337 "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