---
# System prepended metadata

title: Potential Helper Syntax for Scylla-rs

---

# Potential Helper Syntax for Scylla-rs

<style>.markdown-body { max-width: 60%; }</style>
```rust=
pub struct TransactionsTable {
    transaction_id: String,
    idx: u16,
    variant: String,
    message_id: String,
    version: u8,
    data: Vec<u8>,
    inclusion_state: Option<u8>,
    milestone_index: Option<u32>,
}

let res: Option<TransactionsTable> = 
    TransactionsTable::select_all("my_keyspace") // select * from my_keyspace.transactions
        .transaction_id(Operator::Equal, "129386sdgh481hsd262395asfs876") // where transaction_id = '129386sdgh481hsd262395asfs876'
        .idx(Operator::GreaterThan, 0) // and idx > 0
        .consistency(Consistency::One)
        .page_size(100)
        .build()
        .get_local()
        .await?;

let res: Option<???> = 
    TransactionsTable::select("my_keyspace", &["message_id", "inclusion_state", "milestone_index"])
        .transaction_id(Operator::Equal, "129386sdgh481hsd262395asfs876")
        .idx(Operator::GreaterThan, 0)
        .group_by(&["version", "variant"])
        .order_by(&["version", "variant"])
        .consistency(Consistency::One)
        .page_size(100)
        .build()
        .get_local()
        .await?;

let res: Option<TransactionsTable> = 
    TransactionsTable::in_keyspace("my_keyspace")
        .select_all() // select * from my_keyspace.transactions
        .transaction_id_bind(Operator::Equal) // where transaction_id = ?
        .idx_bind(Operator::GreaterThan) // and idx > ?
        .consistency(Consistency::One)
        .page_size(100)
        .build()
        .get_local()
        .await?;

let res: Option<???> = 
    TransactionsTable::in_keyspace("my_keyspace")
        .select(&[
            // consts generated by Table derive?
            TransactionsTable::MESSAGE_ID,
            TransactionsTable::INCLUSION_STATE,
            TransactionsTable::MILESTONE_INDEX,
        ]) // select message_id, inclusion_state, milestone_index from my_keyspace.transactions
        .transaction_id(Operator::Equal, BindMarker::Anonymous) // where transaction_id = ?
        .idx(Operator::GreaterThan, 0) // and idx > 0
        .group_by(&[TransactionsTable::VERSION, TransactionsTable::VARIANT]) // group by version, variant
        .order_by(&[TransactionsTable::VERSION, TransactionsTable::VARIANT]) // order by version, variant
        .consistency(Consistency::One)
        .page_size(100)
        .build()
        .get_local()
        .await?;

let res: Option<(String, Option<u8>, Option<u32>)> = 
    TransactionsTable::in_keyspace("my_keyspace")
        .select::<(
            // types generated by Table derive?
            TransactionsTableMessageId,
            TransactionsTableInclusionState,
            TransactionsTableMilestoneIndex,
        )>() // select message_id, inclusion_state, milestone_index from my_keyspace.transactions
        .transaction_id(Operator::Equal, BindMarker::Anonymous) // where transaction_id = ?
        .idx(Operator::GreaterThan, 0) // and idx > 0
        .group_by(&[TransactionsTable::VERSION, TransactionsTable::VARIANT]) // group by version, variant
        .order_by(&[TransactionsTable::VERSION, TransactionsTable::VARIANT]) // order by version, variant
        .consistency(Consistency::One)
        .page_size(100)
        .build()
        .get_local()
        .await?;

let res: Option<???> = 
    TransactionsTable::in_keyspace("my_keyspace")
        .distinct()
        .select_message_id()
        .select_inclusion_state()
        .select_milestone_index() // select distinct message_id, inclusion_state, milestone_index from my_keyspace.transactions
        .where_transaction_id(Operator::Equal, "129386sdgh481hsd262395asfs876") // where transaction_id = '129386sdgh481hsd262395asfs876'
        .where_idx(Operator::GreaterThan, 0) // and idx > 0
        .group_by_version()
        .group_by_variant() // group by version, variant
        .order_by_version()
        .order_by_variant() // order by version, variant
        .consistency(Consistency::One)
        .page_size(100)
        .build()
        .get_local()
        .await?;

let res: Option<???> = 
    TransactionsTable::in_keyspace("my_keyspace")
        .select(
            // Type generated by the Table derive
            TransactionsTableColumns
                .message_id()
                .inclusion_state()
                .milestone_index(),
        ) // select message_id, inclusion_state, milestone_index from my_keyspace.transactions
        .where_clause(
            TransactionsTableColumns::transaction_id(Operator::Equal, "129386sdgh481hsd262395asfs876")
                .and(TransactionsTableColumns::idx(Operator::GreaterThan, 0)),
        ) // where transaction_id = '129386sdgh481hsd262395asfs876' and idx > 0
        .group_by(TransactionsTableColumns.version().variant())
        .order_by(TransactionsTableColumns.version().variant())
        .consistency(Consistency::One)
        .page_size(100)
        .build()
        .get_local()
        .await?;

// Since TransactionsTable is user defined, fns can be defined on it to simply
// return a SelectStatement(/Builder) which can be manually created or parsed from
// a string using parse_statement!()
let res: Option<MyPreDefinedReturnType> = 
    TransactionsTable::my_pre_defined_select() // Returns built SelectStatement
        .consistency(Consistency::One)
        .page_size(100)
        .build()
        .get_local()
        .await?;
```