pub use super::api::bigtable::v2::{
self, mutate_rows_request::Entry, mutation::*, MutateRowRequest, MutateRowsRequest,
};
use super::Bytes;
impl SetCell {
pub fn new(family_name: String, column_qualifier: Bytes, value: Bytes) -> SetCell {
SetCell {
family_name,
column_qualifier,
value,
..Default::default()
}
}
pub fn with_timestamp(mut self, timestamp_micros: i64) -> Self {
self.timestamp_micros = timestamp_micros;
self
}
}
impl Entry {
pub fn new(row_key: Bytes) -> Self {
Entry {
row_key,
..Default::default()
}
}
pub fn with_mutation(mut self, mutation: impl Into<Mutation>) -> Self {
self.mutations.push(super::v2::Mutation {
mutation: Some(mutation.into()),
});
self
}
pub fn with_mutations(
mut self,
mutations: impl IntoIterator<Item = impl Into<Mutation>>,
) -> Self {
self.mutations
.extend(mutations.into_iter().map(|mutation| super::v2::Mutation {
mutation: Some(mutation.into()),
}));
self
}
}
impl From<SetCell> for Mutation {
fn from(sc: SetCell) -> Mutation {
Mutation::SetCell(sc)
}
}
impl From<DeleteFromColumn> for Mutation {
fn from(dfc: DeleteFromColumn) -> Mutation {
Mutation::DeleteFromColumn(dfc)
}
}
impl From<DeleteFromFamily> for Mutation {
fn from(dff: DeleteFromFamily) -> Mutation {
Mutation::DeleteFromFamily(dff)
}
}
impl From<DeleteFromRow> for Mutation {
fn from(dfr: DeleteFromRow) -> Mutation {
Mutation::DeleteFromRow(dfr)
}
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum MutateRowsError {
#[error("gRPC error: {0}")]
Tonic(#[from] tonic::Status),
#[error("row mutation error")]
RowErrors(Vec<v2::mutate_rows_response::Entry>),
}
impl From<Vec<v2::mutate_rows_response::Entry>> for MutateRowsError {
fn from(entries: Vec<v2::mutate_rows_response::Entry>) -> Self {
MutateRowsError::RowErrors(entries)
}
}
impl MutateRowRequest {
pub fn new(table_name: String, row_key: Bytes) -> MutateRowRequest {
MutateRowRequest {
table_name,
row_key,
..Default::default()
}
}
pub fn with_mutation(mut self, mutation: impl Into<Mutation>) -> Self {
self.mutations.push(v2::Mutation {
mutation: Some(mutation.into()),
});
self
}
pub fn with_mutations(
mut self,
mutations: impl IntoIterator<Item = impl Into<Mutation>>,
) -> Self {
self.mutations
.extend(mutations.into_iter().map(|mutation| v2::Mutation {
mutation: Some(mutation.into()),
}));
self
}
}
impl MutateRowsRequest {
pub fn new(table_name: String) -> MutateRowsRequest {
MutateRowsRequest {
table_name,
..Default::default()
}
}
pub fn with_entry(mut self, entry: Entry) -> Self {
self.entries.push(entry);
self
}
pub fn with_entries(mut self, entries: impl Iterator<Item = Entry>) -> Self {
self.entries.extend(entries);
self
}
}