Skip to main content

Row

Struct Row 

Source
pub struct Row { /* private fields */ }

Implementations§

Source§

impl Row

Source

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));
Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for Row

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Row

Source§

fn default() -> Row

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Row

§

impl RefUnwindSafe for Row

§

impl Send for Row

§

impl Sync for Row

§

impl Unpin for Row

§

impl UnwindSafe for Row

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.