Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
CassandraMigrationSchema.hpp
1#pragma once
2
3#include "data/cassandra/Handle.hpp"
4#include "data/cassandra/Schema.hpp"
5#include "data/cassandra/SettingsProvider.hpp"
6#include "data/cassandra/Types.hpp"
7
8#include <fmt/format.h>
9
10#include <functional>
11#include <string>
12
13namespace migration::cassandra::impl {
14
20 using SettingsProviderType = data::cassandra::SettingsProvider;
21 std::reference_wrapper<SettingsProviderType const> settingsProvider_;
22
23public:
29 explicit CassandraMigrationSchema(SettingsProviderType const& settings)
30 : settingsProvider_{settings}
31 {
32 }
33
42 data::cassandra::PreparedStatement
44 data::cassandra::Handle const& handler,
45 std::string const& tableName,
46 std::string const& key
47 )
48 {
49 return handler.prepare(
50 fmt::format(
51 R"(
52 SELECT *
53 FROM {}
54 WHERE TOKEN({}) >= ? AND TOKEN({}) <= ?
55 )",
57 settingsProvider_.get(), tableName
58 ),
59 key,
60 key
61 )
62 );
63 }
64
68 * @param handler The database handler
69 * @return The prepared statement to insert into migrator_status table
70 */
71 data::cassandra::PreparedStatement const&
73 {
74 static auto kPREPARED = handler.prepare(
75 fmt::format(
76 R"(
77 INSERT INTO {}
78 (migrator_name, status)
79 VALUES (?, ?)
80 )",
82 settingsProvider_.get(), "migrator_status"
83 )
84 )
85 );
86 return kPREPARED;
87 }
88};
89} // namespace migration::cassandra::impl
Represents a handle to the cassandra database cluster.
Definition Handle.hpp:27
PreparedStatementType prepare(std::string_view query) const
Prepare a statement.
Definition Handle.cpp:149
Provides settings for BasicCassandraBackend.
Definition SettingsProvider.hpp:16
data::cassandra::PreparedStatement getPreparedFullScanStatement(data::cassandra::Handle const &handler, std::string const &tableName, std::string const &key)
Get the prepared statement for the full scan of a table.
Definition CassandraMigrationSchema.hpp:43
data::cassandra::PreparedStatement const & getPreparedInsertMigratedMigrator(data::cassandra::Handle const &handler)
Get the prepared statement for insertion of migrator_status table.
Definition CassandraMigrationSchema.hpp:68
CassandraMigrationSchema(SettingsProviderType const &settings)
Construct a new Cassandra Migration Schema object.
Definition CassandraMigrationSchema.hpp:29
std::string qualifiedTableName(SettingsProviderType const &provider, std::string_view name)
Returns the table name qualified with the keyspace and table prefix.
Definition Schema.hpp:27