Skip to content

Commit 95d62fe

Browse files
committed
feat(cat-gateway): add macros to implement Query trait
1 parent bb6e5f1 commit 95d62fe

File tree

1 file changed

+48
-0
lines changed
  • catalyst-gateway/bin/src/db/index/queries

1 file changed

+48
-0
lines changed

catalyst-gateway/bin/src/db/index/queries/mod.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,54 @@ pub(crate) trait Query {
8686
) -> anyhow::Result<QueryKind>;
8787
}
8888

89+
/// Implement Query trait for batched types
90+
#[macro_export]
91+
macro_rules! impl_query_batch {
92+
($i:ty, $c:ident) => {
93+
impl $crate::db::index::queries::Query for $i {
94+
/// Prepare Batch of Insert TXI Index Data Queries
95+
async fn prepare_query(
96+
session: &std::sync::Arc<scylla::Session>,
97+
cfg: &$crate::settings::cassandra_db::EnvVars,
98+
) -> anyhow::Result<$crate::db::index::queries::QueryKind> {
99+
Self::prepare_batch(session, cfg)
100+
.await
101+
.map($crate::db::index::queries::QueryKind::Batch)
102+
}
103+
}
104+
105+
impl std::fmt::Display for $i {
106+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
107+
write!(f, "{{$c}}")
108+
}
109+
}
110+
};
111+
}
112+
113+
/// Implement Query trait for statement types
114+
#[macro_export]
115+
macro_rules! impl_query_statement {
116+
($i:ty, $c:ident) => {
117+
impl $crate::db::index::queries::Query for $i {
118+
/// Prepare Batch of Insert TXI Index Data Queries
119+
async fn prepare_query(
120+
session: &std::sync::Arc<scylla::Session>,
121+
_: &$crate::settings::cassandra_db::EnvVars,
122+
) -> anyhow::Result<$crate::db::index::queries::QueryKind> {
123+
Self::prepare(session)
124+
.await
125+
.map($crate::db::index::queries::QueryKind::Statement)
126+
}
127+
}
128+
129+
impl std::fmt::Display for $i {
130+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
131+
write!(f, "{{$c}}")
132+
}
133+
}
134+
};
135+
}
136+
89137
/// All Prepared insert Queries that we know about.
90138
#[derive(strum_macros::Display)]
91139
#[allow(clippy::enum_variant_names)]

0 commit comments

Comments
 (0)