Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Schema.hpp
1#pragma once
2
3#include "data/cassandra/Concepts.hpp"
4#include "data/cassandra/Handle.hpp"
5#include "data/cassandra/Types.hpp"
6#include "util/log/Logger.hpp"
7
8#include <boost/json/string.hpp>
9#include <fmt/compile.h>
10
11#include <functional>
12#include <string>
13#include <string_view>
14#include <vector>
15
16namespace data::cassandra {
17
26template <SomeSettingsProvider SettingsProviderType>
27[[nodiscard]] std::string inline qualifiedTableName(
28 SettingsProviderType const& provider,
29 std::string_view name
30)
31{
32 return fmt::format(
33 "{}.{}{}", provider.getKeyspace(), provider.getTablePrefix().value_or(""), name
34 );
35}
36
40template <SomeSettingsProvider SettingsProviderType>
41class Schema {
42protected:
43 util::Logger log_{"Backend"};
44 std::reference_wrapper<SettingsProviderType const> settingsProvider_;
45
46public:
47 virtual ~Schema() = default;
48
54 explicit Schema(SettingsProviderType const& settingsProvider)
55 : settingsProvider_{std::cref(settingsProvider)}
56 {
57 }
58
59 std::string createKeyspace = [this]() {
60 return fmt::format(
61 R"(
62 CREATE KEYSPACE IF NOT EXISTS {}
63 WITH replication = {{
64 'class': 'SimpleStrategy',
65 'replication_factor': '{}'
66 }}
67 AND durable_writes = True
68 )",
69 settingsProvider_.get().getKeyspace(),
70 settingsProvider_.get().getReplicationFactor()
71 );
72 }();
73
74 // =======================
75 // Schema creation queries
76 // =======================
77
78 std::vector<Statement> createSchema = [this]() {
79 std::vector<Statement> statements;
80
81 statements.emplace_back(
82 fmt::format(
83 R"(
84 CREATE TABLE IF NOT EXISTS {}
85 (
86 key blob,
87 sequence bigint,
88 object blob,
89 PRIMARY KEY (key, sequence)
90 )
91 WITH CLUSTERING ORDER BY (sequence DESC)
92 )",
93 qualifiedTableName(settingsProvider_.get(), "objects")
94 )
95 );
96
97 statements.emplace_back(
98 fmt::format(
99 R"(
100 CREATE TABLE IF NOT EXISTS {}
101 (
102 hash blob PRIMARY KEY,
103 ledger_sequence bigint,
104 date bigint,
105 transaction blob,
106 metadata blob
107 )
108 )",
109 qualifiedTableName(settingsProvider_.get(), "transactions")
110 )
111 );
112
113 statements.emplace_back(
114 fmt::format(
115 R"(
116 CREATE TABLE IF NOT EXISTS {}
117 (
118 ledger_sequence bigint,
119 hash blob,
120 PRIMARY KEY (ledger_sequence, hash)
121 )
122 )",
123 qualifiedTableName(settingsProvider_.get(), "ledger_transactions")
124 )
125 );
126
127 statements.emplace_back(
128 fmt::format(
129 R"(
130 CREATE TABLE IF NOT EXISTS {}
131 (
132 key blob,
133 seq bigint,
134 next blob,
135 PRIMARY KEY (key, seq)
136 )
137 )",
138 qualifiedTableName(settingsProvider_.get(), "successor")
139 )
140 );
141
142 statements.emplace_back(
143 fmt::format(
144 R"(
145 CREATE TABLE IF NOT EXISTS {}
146 (
147 seq bigint,
148 key blob,
149 PRIMARY KEY (seq, key)
150 )
151 )",
152 qualifiedTableName(settingsProvider_.get(), "diff")
153 )
154 );
155
156 statements.emplace_back(
157 fmt::format(
158 R"(
159 CREATE TABLE IF NOT EXISTS {}
160 (
161 account blob,
162 seq_idx tuple<bigint, bigint>,
163 hash blob,
164 PRIMARY KEY (account, seq_idx)
165 )
166 WITH CLUSTERING ORDER BY (seq_idx DESC)
167 )",
168 qualifiedTableName(settingsProvider_.get(), "account_tx")
169 )
170 );
171
172 statements.emplace_back(
173 fmt::format(
174 R"(
175 CREATE TABLE IF NOT EXISTS {}
176 (
177 sequence bigint PRIMARY KEY,
178 header blob
179 )
180 )",
181 qualifiedTableName(settingsProvider_.get(), "ledgers")
182 )
183 );
184
185 statements.emplace_back(
186 fmt::format(
187 R"(
188 CREATE TABLE IF NOT EXISTS {}
189 (
190 hash blob PRIMARY KEY,
191 sequence bigint
192 )
193 )",
194 qualifiedTableName(settingsProvider_.get(), "ledger_hashes")
195 )
196 );
197
198 statements.emplace_back(
199 fmt::format(
200 R"(
201 CREATE TABLE IF NOT EXISTS {}
202 (
203 is_latest boolean PRIMARY KEY,
204 sequence bigint
205 )
206 )",
207 qualifiedTableName(settingsProvider_.get(), "ledger_range")
208 )
209 );
210
211 statements.emplace_back(
212 fmt::format(
213 R"(
214 CREATE TABLE IF NOT EXISTS {}
215 (
216 token_id blob,
217 sequence bigint,
218 owner blob,
219 is_burned boolean,
220 PRIMARY KEY (token_id, sequence)
221 )
222 WITH CLUSTERING ORDER BY (sequence DESC)
223 )",
224 qualifiedTableName(settingsProvider_.get(), "nf_tokens")
225 )
226 );
227
228 statements.emplace_back(
229 fmt::format(
230 R"(
231 CREATE TABLE IF NOT EXISTS {}
232 (
233 issuer blob,
234 taxon bigint,
235 token_id blob,
236 PRIMARY KEY (issuer, taxon, token_id)
237 )
238 WITH CLUSTERING ORDER BY (taxon ASC, token_id ASC)
239 )",
240 qualifiedTableName(settingsProvider_.get(), "issuer_nf_tokens_v2")
241 )
242 );
243
244 statements.emplace_back(
245 fmt::format(
246 R"(
247 CREATE TABLE IF NOT EXISTS {}
248 (
249 token_id blob,
250 sequence bigint,
251 uri blob,
252 PRIMARY KEY (token_id, sequence)
253 )
254 WITH CLUSTERING ORDER BY (sequence DESC)
255 )",
256 qualifiedTableName(settingsProvider_.get(), "nf_token_uris")
257 )
258 );
259
260 statements.emplace_back(
261 fmt::format(
262 R"(
263 CREATE TABLE IF NOT EXISTS {}
264 (
265 token_id blob,
266 seq_idx tuple<bigint, bigint>,
267 hash blob,
268 PRIMARY KEY (token_id, seq_idx)
269 )
270 WITH CLUSTERING ORDER BY (seq_idx DESC)
271 )",
272 qualifiedTableName(settingsProvider_.get(), "nf_token_transactions")
273 )
274 );
275
276 statements.emplace_back(
277 fmt::format(
278 R"(
279 CREATE TABLE IF NOT EXISTS {}
280 (
281 mptoken_issuance_id blob,
282 seq_idx tuple<bigint, bigint>,
283 hash blob,
284 PRIMARY KEY (mptoken_issuance_id, seq_idx)
285 )
286 WITH CLUSTERING ORDER BY (seq_idx DESC)
287 )",
288 qualifiedTableName(settingsProvider_.get(), "mptoken_issuance_transactions")
289 )
290 );
291
292 statements.emplace_back(
293 fmt::format(
294 R"(
295 CREATE TABLE IF NOT EXISTS {}
296 (
297 mptoken_issuance_id blob,
298 account blob,
299 seq_idx tuple<bigint, bigint>,
300 hash blob,
301 PRIMARY KEY ((mptoken_issuance_id, account), seq_idx)
302 )
303 WITH CLUSTERING ORDER BY (seq_idx DESC)
304 )",
305 qualifiedTableName(settingsProvider_.get(), "account_mptoken_issuance_transactions")
306 )
307 );
308
309 statements.emplace_back(
310 fmt::format(
311 R"(
312 CREATE TABLE IF NOT EXISTS {}
313 (
314 mpt_id blob,
315 holder blob,
316 PRIMARY KEY (mpt_id, holder)
317 )
318 WITH CLUSTERING ORDER BY (holder ASC)
319 )",
320 qualifiedTableName(settingsProvider_.get(), "mp_token_holders")
321 )
322 );
323
324 statements.emplace_back(
325 fmt::format(
326 R"(
327 CREATE TABLE IF NOT EXISTS {}
328 (
329 migrator_name TEXT,
330 status TEXT,
331 PRIMARY KEY (migrator_name)
332 )
333 )",
334 qualifiedTableName(settingsProvider_.get(), "migrator_status")
335 )
336 );
337
338 statements.emplace_back(
339 fmt::format(
340 R"(
341 CREATE TABLE IF NOT EXISTS {}
342 (
343 node_id UUID,
344 message TEXT,
345 PRIMARY KEY (node_id)
346 )
347 WITH default_time_to_live = 2
348 )",
349 qualifiedTableName(settingsProvider_.get(), "nodes_chat")
350 )
351 );
352
353 return statements;
354 }();
355
360 protected:
361 std::reference_wrapper<SettingsProviderType const> settingsProvider_;
362 std::reference_wrapper<Handle const> handle_;
363
364 public:
371 Statements(SettingsProviderType const& settingsProvider, Handle const& handle)
372 : settingsProvider_{settingsProvider}, handle_{std::cref(handle)}
373 {
374 }
375
376 //
377 // Insert queries
378 //
379
380 PreparedStatement insertObject = [this]() {
381 return handle_.get().prepare(
382 fmt::format(
383 R"(
384 INSERT INTO {}
385 (key, sequence, object)
386 VALUES (?, ?, ?)
387 )",
388 qualifiedTableName(settingsProvider_.get(), "objects")
389 )
390 );
391 }();
392
393 PreparedStatement insertTransaction = [this]() {
394 return handle_.get().prepare(
395 fmt::format(
396 R"(
397 INSERT INTO {}
398 (hash, ledger_sequence, date, transaction, metadata)
399 VALUES (?, ?, ?, ?, ?)
400 )",
401 qualifiedTableName(settingsProvider_.get(), "transactions")
402 )
403 );
404 }();
405
406 PreparedStatement insertLedgerTransaction = [this]() {
407 return handle_.get().prepare(
408 fmt::format(
409 R"(
410 INSERT INTO {}
411 (ledger_sequence, hash)
412 VALUES (?, ?)
413 )",
414 qualifiedTableName(settingsProvider_.get(), "ledger_transactions")
415 )
416 );
417 }();
418
419 PreparedStatement insertSuccessor = [this]() {
420 return handle_.get().prepare(
421 fmt::format(
422 R"(
423 INSERT INTO {}
424 (key, seq, next)
425 VALUES (?, ?, ?)
426 )",
427 qualifiedTableName(settingsProvider_.get(), "successor")
428 )
429 );
430 }();
431
432 PreparedStatement insertDiff = [this]() {
433 return handle_.get().prepare(
434 fmt::format(
435 R"(
436 INSERT INTO {}
437 (seq, key)
438 VALUES (?, ?)
439 )",
440 qualifiedTableName(settingsProvider_.get(), "diff")
441 )
442 );
443 }();
444
445 PreparedStatement insertAccountTx = [this]() {
446 return handle_.get().prepare(
447 fmt::format(
448 R"(
449 INSERT INTO {}
450 (account, seq_idx, hash)
451 VALUES (?, ?, ?)
452 )",
453 qualifiedTableName(settingsProvider_.get(), "account_tx")
454 )
455 );
456 }();
457
458 PreparedStatement insertNFT = [this]() {
459 return handle_.get().prepare(
460 fmt::format(
461 R"(
462 INSERT INTO {}
463 (token_id, sequence, owner, is_burned)
464 VALUES (?, ?, ?, ?)
465 )",
466 qualifiedTableName(settingsProvider_.get(), "nf_tokens")
467 )
468 );
469 }();
470
471 PreparedStatement insertIssuerNFT = [this]() {
472 return handle_.get().prepare(
473 fmt::format(
474 R"(
475 INSERT INTO {}
476 (issuer, taxon, token_id)
477 VALUES (?, ?, ?)
478 )",
479 qualifiedTableName(settingsProvider_.get(), "issuer_nf_tokens_v2")
480 )
481 );
482 }();
483
484 PreparedStatement insertNFTURI = [this]() {
485 return handle_.get().prepare(
486 fmt::format(
487 R"(
488 INSERT INTO {}
489 (token_id, sequence, uri)
490 VALUES (?, ?, ?)
491 )",
492 qualifiedTableName(settingsProvider_.get(), "nf_token_uris")
493 )
494 );
495 }();
496
497 PreparedStatement insertNFTTx = [this]() {
498 return handle_.get().prepare(
499 fmt::format(
500 R"(
501 INSERT INTO {}
502 (token_id, seq_idx, hash)
503 VALUES (?, ?, ?)
504 )",
505 qualifiedTableName(settingsProvider_.get(), "nf_token_transactions")
506 )
507 );
508 }();
509
510 PreparedStatement insertMPTokenIssuanceTx = [this]() {
511 return handle_.get().prepare(
512 fmt::format(
513 R"(
514 INSERT INTO {}
515 (mptoken_issuance_id, seq_idx, hash)
516 VALUES (?, ?, ?)
517 )",
518 qualifiedTableName(settingsProvider_.get(), "mptoken_issuance_transactions")
519 )
520 );
521 }();
522
523 PreparedStatement insertAccountMPTokenIssuanceTx = [this]() {
524 return handle_.get().prepare(
525 fmt::format(
526 R"(
527 INSERT INTO {}
528 (mptoken_issuance_id, account, seq_idx, hash)
529 VALUES (?, ?, ?, ?)
530 )",
532 settingsProvider_.get(), "account_mptoken_issuance_transactions"
533 )
534 )
535 );
536 }();
537
538 PreparedStatement insertMPTHolder = [this]() {
539 return handle_.get().prepare(
540 fmt::format(
541 R"(
542 INSERT INTO {}
543 (mpt_id, holder)
544 VALUES (?, ?)
545 )",
546 qualifiedTableName(settingsProvider_.get(), "mp_token_holders")
547 )
548 );
549 }();
550
551 PreparedStatement insertLedgerHeader = [this]() {
552 return handle_.get().prepare(
553 fmt::format(
554 R"(
555 INSERT INTO {}
556 (sequence, header)
557 VALUES (?, ?)
558 )",
559 qualifiedTableName(settingsProvider_.get(), "ledgers")
560 )
561 );
562 }();
563
564 PreparedStatement insertLedgerHash = [this]() {
565 return handle_.get().prepare(
566 fmt::format(
567 R"(
568 INSERT INTO {}
569 (hash, sequence)
570 VALUES (?, ?)
571 )",
572 qualifiedTableName(settingsProvider_.get(), "ledger_hashes")
573 )
574 );
575 }();
576
577 //
578 // Update (and "delete") queries
579 //
580
581 PreparedStatement deleteLedgerRange = [this]() {
582 return handle_.get().prepare(
583 fmt::format(
584 R"(
585 UPDATE {}
586 SET sequence = ?
587 WHERE is_latest = False
588 )",
589 qualifiedTableName(settingsProvider_.get(), "ledger_range")
590 )
591 );
592 }();
593
594 PreparedStatement insertMigratorStatus = [this]() {
595 return handle_.get().prepare(
596 fmt::format(
597 R"(
598 INSERT INTO {}
599 (migrator_name, status)
600 VALUES (?, ?)
601 )",
602 qualifiedTableName(settingsProvider_.get(), "migrator_status")
603 )
604 );
605 }();
606
607 PreparedStatement updateClioNodeMessage = [this]() {
608 return handle_.get().prepare(
609 fmt::format(
610 R"(
611 UPDATE {}
612 SET message = ?
613 WHERE node_id = ?
614 )",
615 qualifiedTableName(settingsProvider_.get(), "nodes_chat")
616 )
617 );
618 }();
619
620 //
621 // Select queries
622 //
623
624 PreparedStatement selectSuccessor = [this]() {
625 return handle_.get().prepare(
626 fmt::format(
627 R"(
628 SELECT next
629 FROM {}
630 WHERE key = ?
631 AND seq <= ?
632 ORDER BY seq DESC
633 LIMIT 1
634 )",
635 qualifiedTableName(settingsProvider_.get(), "successor")
636 )
637 );
638 }();
639
640 PreparedStatement selectDiff = [this]() {
641 return handle_.get().prepare(
642 fmt::format(
643 R"(
644 SELECT key
645 FROM {}
646 WHERE seq = ?
647 )",
648 qualifiedTableName(settingsProvider_.get(), "diff")
649 )
650 );
651 }();
652
653 PreparedStatement selectObject = [this]() {
654 return handle_.get().prepare(
655 fmt::format(
656 R"(
657 SELECT object, sequence
658 FROM {}
659 WHERE key = ?
660 AND sequence <= ?
661 ORDER BY sequence DESC
662 LIMIT 1
663 )",
664 qualifiedTableName(settingsProvider_.get(), "objects")
665 )
666 );
667 }();
668
669 PreparedStatement selectTransaction = [this]() {
670 return handle_.get().prepare(
671 fmt::format(
672 R"(
673 SELECT transaction, metadata, ledger_sequence, date
674 FROM {}
675 WHERE hash = ?
676 )",
677 qualifiedTableName(settingsProvider_.get(), "transactions")
678 )
679 );
680 }();
681
682 PreparedStatement selectAllTransactionHashesInLedger = [this]() {
683 return handle_.get().prepare(
684 fmt::format(
685 R"(
686 SELECT hash
687 FROM {}
688 WHERE ledger_sequence = ?
689 )",
690 qualifiedTableName(settingsProvider_.get(), "ledger_transactions")
691 )
692 );
693 }();
694
695 PreparedStatement getToken = [this]() {
696 return handle_.get().prepare(
697 fmt::format(
698 R"(
699 SELECT TOKEN(key)
700 FROM {}
701 WHERE key = ?
702 LIMIT 1
703 )",
704 qualifiedTableName(settingsProvider_.get(), "objects")
705 )
706 );
707 }();
708
709 PreparedStatement selectAccountTx = [this]() {
710 return handle_.get().prepare(
711 fmt::format(
712 R"(
713 SELECT hash, seq_idx
714 FROM {}
715 WHERE account = ?
716 AND seq_idx < ?
717 LIMIT ?
718 )",
719 qualifiedTableName(settingsProvider_.get(), "account_tx")
720 )
721 );
722 }();
723
724 PreparedStatement selectAccountTxForward = [this]() {
725 return handle_.get().prepare(
726 fmt::format(
727 R"(
728 SELECT hash, seq_idx
729 FROM {}
730 WHERE account = ?
731 AND seq_idx > ?
732 ORDER BY seq_idx ASC
733 LIMIT ?
734 )",
735 qualifiedTableName(settingsProvider_.get(), "account_tx")
736 )
737 );
738 }();
739
740 PreparedStatement selectNFT = [this]() {
741 return handle_.get().prepare(
742 fmt::format(
743 R"(
744 SELECT sequence, owner, is_burned
745 FROM {}
746 WHERE token_id = ?
747 AND sequence <= ?
748 ORDER BY sequence DESC
749 LIMIT 1
750 )",
751 qualifiedTableName(settingsProvider_.get(), "nf_tokens")
752 )
753 );
754 }();
755
756 PreparedStatement selectNFTURI = [this]() {
757 return handle_.get().prepare(
758 fmt::format(
759 R"(
760 SELECT uri
761 FROM {}
762 WHERE token_id = ?
763 AND sequence <= ?
764 ORDER BY sequence DESC
765 LIMIT 1
766 )",
767 qualifiedTableName(settingsProvider_.get(), "nf_token_uris")
768 )
769 );
770 }();
771
772 PreparedStatement selectNFTTx = [this]() {
773 return handle_.get().prepare(
774 fmt::format(
775 R"(
776 SELECT hash, seq_idx
777 FROM {}
778 WHERE token_id = ?
779 AND seq_idx < ?
780 ORDER BY seq_idx DESC
781 LIMIT ?
782 )",
783 qualifiedTableName(settingsProvider_.get(), "nf_token_transactions")
784 )
785 );
786 }();
787
788 PreparedStatement selectNFTTxForward = [this]() {
789 return handle_.get().prepare(
790 fmt::format(
791 R"(
792 SELECT hash, seq_idx
793 FROM {}
794 WHERE token_id = ?
795 AND seq_idx >= ?
796 ORDER BY seq_idx ASC
797 LIMIT ?
798 )",
799 qualifiedTableName(settingsProvider_.get(), "nf_token_transactions")
800 )
801 );
802 }();
803
804 PreparedStatement selectMPTokenIssuanceTx = [this]() {
805 return handle_.get().prepare(
806 fmt::format(
807 R"(
808 SELECT hash, seq_idx
809 FROM {}
810 WHERE mptoken_issuance_id = ?
811 AND seq_idx < ?
812 ORDER BY seq_idx DESC
813 LIMIT ?
814 )",
815 qualifiedTableName(settingsProvider_.get(), "mptoken_issuance_transactions")
816 )
817 );
818 }();
819
820 PreparedStatement selectMPTokenIssuanceTxForward = [this]() {
821 return handle_.get().prepare(
822 fmt::format(
823 R"(
824 SELECT hash, seq_idx
825 FROM {}
826 WHERE mptoken_issuance_id = ?
827 AND seq_idx >= ?
828 ORDER BY seq_idx ASC
829 LIMIT ?
830 )",
831 qualifiedTableName(settingsProvider_.get(), "mptoken_issuance_transactions")
832 )
833 );
834 }();
835
836 PreparedStatement selectAccountMPTokenIssuanceTx = [this]() {
837 return handle_.get().prepare(
838 fmt::format(
839 R"(
840 SELECT hash, seq_idx
841 FROM {}
842 WHERE mptoken_issuance_id = ?
843 AND account = ?
844 AND seq_idx < ?
845 ORDER BY seq_idx DESC
846 LIMIT ?
847 )",
849 settingsProvider_.get(), "account_mptoken_issuance_transactions"
850 )
851 )
852 );
853 }();
854
855 PreparedStatement selectAccountMPTokenIssuanceTxForward = [this]() {
856 return handle_.get().prepare(
857 fmt::format(
858 R"(
859 SELECT hash, seq_idx
860 FROM {}
861 WHERE mptoken_issuance_id = ?
862 AND account = ?
863 AND seq_idx >= ?
864 ORDER BY seq_idx ASC
865 LIMIT ?
866 )",
868 settingsProvider_.get(), "account_mptoken_issuance_transactions"
869 )
870 )
871 );
872 }();
873
874 PreparedStatement selectNFTIDsByIssuerTaxon = [this]() {
875 return handle_.get().prepare(
876 fmt::format(
877 R"(
878 SELECT token_id
879 FROM {}
880 WHERE issuer = ?
881 AND taxon = ?
882 AND token_id > ?
883 ORDER BY taxon ASC, token_id ASC
884 LIMIT ?
885 )",
886 qualifiedTableName(settingsProvider_.get(), "issuer_nf_tokens_v2")
887 )
888 );
889 }();
890
891 PreparedStatement selectMPTHolders = [this]() {
892 return handle_.get().prepare(
893 fmt::format(
894 R"(
895 SELECT holder
896 FROM {}
897 WHERE mpt_id = ?
898 AND holder > ?
899 ORDER BY holder ASC
900 LIMIT ?
901 )",
902 qualifiedTableName(settingsProvider_.get(), "mp_token_holders")
903 )
904 );
905 }();
906
907 PreparedStatement selectLedgerByHash = [this]() {
908 return handle_.get().prepare(
909 fmt::format(
910 R"(
911 SELECT sequence
912 FROM {}
913 WHERE hash = ?
914 LIMIT 1
915 )",
916 qualifiedTableName(settingsProvider_.get(), "ledger_hashes")
917 )
918 );
919 }();
920
921 PreparedStatement selectLedgerBySeq = [this]() {
922 return handle_.get().prepare(
923 fmt::format(
924 R"(
925 SELECT header
926 FROM {}
927 WHERE sequence = ?
928 )",
929 qualifiedTableName(settingsProvider_.get(), "ledgers")
930 )
931 );
932 }();
933
934 PreparedStatement selectLatestLedger = [this]() {
935 return handle_.get().prepare(
936 fmt::format(
937 R"(
938 SELECT sequence
939 FROM {}
940 WHERE is_latest = True
941 )",
942 qualifiedTableName(settingsProvider_.get(), "ledger_range")
943 )
944 );
945 }();
946
947 PreparedStatement selectLedgerRange = [this]() {
948 return handle_.get().prepare(
949 fmt::format(
950 R"(
951 SELECT sequence
952 FROM {}
953 WHERE is_latest in (True, False)
954 )",
955 qualifiedTableName(settingsProvider_.get(), "ledger_range")
956 )
957 );
958 }();
959
960 PreparedStatement selectMigratorStatus = [this]() {
961 return handle_.get().prepare(
962 fmt::format(
963 R"(
964 SELECT status
965 FROM {}
966 WHERE migrator_name = ?
967 )",
968 qualifiedTableName(settingsProvider_.get(), "migrator_status")
969 )
970 );
971 }();
972
973 PreparedStatement selectClioNodesData = [this]() {
974 return handle_.get().prepare(
975 fmt::format(
976 R"(
977 SELECT node_id, message
978 FROM {}
979 )",
980 qualifiedTableName(settingsProvider_.get(), "nodes_chat")
981 )
982 );
983 }();
984 };
985
991 virtual void
992 prepareStatements(Handle const& handle) = 0;
993};
994
995} // namespace data::cassandra
Represents a handle to the cassandra database cluster.
Definition Handle.hpp:27
Statements(SettingsProviderType const &settingsProvider, Handle const &handle)
Construct a new Statements object.
Definition Schema.hpp:371
Schema(SettingsProviderType const &settingsProvider)
Shared Schema's between all Schema classes (Cassandra and Keyspace).
Definition Schema.hpp:54
virtual void prepareStatements(Handle const &handle)=0
Recreates the prepared statements.
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:78
This namespace implements a wrapper for the Cassandra C++ driver.
Definition CassandraBackendFamily.hpp:47
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