pub struct Row { /* private fields */ }Implementations§
Source§impl Row
impl Row
Sourcepub fn set<T: ToDatabaseValue>(&mut self, name: &str, value: T) -> &mut Self
pub fn set<T: ToDatabaseValue>(&mut self, name: &str, value: T) -> &mut Self
Set a field to a value, this is the standard method for setting fields in a row.
This method ensures that the value is converted to a database-compatible format
using the ToDatabaseValue trait. It is the primary way to set fields in a row
for most use cases.
The ToDatabaseValue trait is implemented for various types, including primitive
types, strings, and custom types. This allows you to set fields with different
types of values without worrying about the underlying conversion. Check example
for more details.
Check ToDatabaseValue for implemented automatic conversions.
§Panics
This method will panic if called on a row marked for deletion.
§Example
use substreams::scalar::{BigInt, BigDecimal};
use crate::substreams_database_change::tables::Tables;
let mut tables = Tables::new();
let row = tables.create_row("myevent", "my_key");
row.set("name", "asset name");
row.set("decimals", 42);
row.set("count", BigDecimal::from(42));
row.set("value", BigInt::from(42));Sourcepub fn add<T: NumericAddable>(&mut self, name: &str, value: T) -> &mut Self
pub fn add<T: NumericAddable>(&mut self, name: &str, value: T) -> &mut Self
Add to the existing value: column = COALESCE(column, 0) + value Used with upsert_row() for accumulating values like counters or balances. If called multiple times for the same column within a block, values are accumulated.
Sourcepub fn sub<T: NumericAddable>(&mut self, name: &str, value: T) -> &mut Self
pub fn sub<T: NumericAddable>(&mut self, name: &str, value: T) -> &mut Self
Subtract from the existing value: column = COALESCE(column, 0) - value Convenience method that negates the value and uses ADD operation. If called multiple times for the same column within a block, values are accumulated.
Sourcepub fn max<T: NumericComparable>(&mut self, name: &str, value: T) -> &mut Self
pub fn max<T: NumericComparable>(&mut self, name: &str, value: T) -> &mut Self
Set to the maximum of existing and new: column = GREATEST(COALESCE(column, value), value) Used with upsert_row() for tracking high values. Can only follow set() or another max() call on the same field.
Sourcepub fn min<T: NumericComparable>(&mut self, name: &str, value: T) -> &mut Self
pub fn min<T: NumericComparable>(&mut self, name: &str, value: T) -> &mut Self
Set to the minimum of existing and new: column = LEAST(COALESCE(column, value), value) Used with upsert_row() for tracking low values. Can only follow set() or another min() call on the same field.
Sourcepub fn set_if_null<T: ToDatabaseValue>(
&mut self,
name: &str,
value: T,
) -> &mut Self
pub fn set_if_null<T: ToDatabaseValue>( &mut self, name: &str, value: T, ) -> &mut Self
Set only if column is null: column = COALESCE(column, new_value) Used with upsert_row() for setting initial values that should not be overwritten. When called multiple times, the FIRST value is kept (subsequent calls are no-ops). Cannot be mixed with other operations on the same field.
Sourcepub fn set_raw(&mut self, name: &str, value: String) -> &mut Self
pub fn set_raw(&mut self, name: &str, value: String) -> &mut Self
Set a field to a raw value, this is useful for setting values that are not normalized across all databases. In there, you can put the raw value as you would in a SQL statement of the database you are targeting.
This will be pass as a string to the database which will interpret it itself.
Sourcepub fn set_psql_array<T: ToDatabaseValue>(
&mut self,
name: &str,
value: Vec<T>,
) -> &mut Row
pub fn set_psql_array<T: ToDatabaseValue>( &mut self, name: &str, value: Vec<T>, ) -> &mut Row
Set a field to an array of values compatible with PostgresSQL database, this method is currently experimental and hidden as we plan to support array natively in the model.
For now, this method should be used with great care as it ties the model to the database implementation.
Sourcepub fn set_clickhouse_array<T: ToDatabaseValue>(
&mut self,
name: &str,
value: Vec<T>,
) -> &mut Row
pub fn set_clickhouse_array<T: ToDatabaseValue>( &mut self, name: &str, value: Vec<T>, ) -> &mut Row
Set a field to an array of values compatible with Clickhouse database, this method is currently experimental and hidden as we plan to support array natively in the model.
For now, this method should be used with great care as it ties the model to the database implementation.