Struct Tables

Source
pub struct Tables {
    pub tables: HashMap<String, Rows>,
    /* private fields */
}

Fields§

§tables: HashMap<String, Rows>

Implementations§

Source§

impl Tables

Source

pub fn new() -> Self

Source

pub fn all_row_count(&self) -> usize

Returns the number of rows in all tables.

Source

pub fn create_row<K: Into<PrimaryKey>>( &mut self, table: &str, key: K, ) -> &mut Row

Create a new row in the table with the given primary key.

// With a Primary Key of type `Single`
use crate::substreams_database_change::tables::Tables;
let mut tables = Tables::new();
tables.create_row("myevent", "my_key",);
// With a Primary Key of type `Composite`
use crate::substreams_database_change::tables::Tables;
let mut tables = Tables::new();
tables.create_row("myevent", [("evt_tx_hash", String::from("hello")), ("evt_index", String::from("world"))]);
Source

pub fn upsert_row<K: Into<PrimaryKey>>( &mut self, table: &str, key: K, ) -> &mut Row

Upsert (insert or update) a new row in the table with the given primary key.

Note Ensure that the SQL sink driver you use supports upsert operations.

// With a Primary Key of type `Single`
use crate::substreams_database_change::tables::Tables;
let mut tables = Tables::new();
tables.upsert_row("myevent", "my_key",);
// With a Primary Key of type `Composite`
use crate::substreams_database_change::tables::Tables;
let mut tables = Tables::new();
tables.upsert_row("myevent", [("evt_tx_hash", String::from("hello")), ("evt_index", String::from("world"))]);
Source

pub fn update_row<K: Into<PrimaryKey>>( &mut self, table: &str, key: K, ) -> &mut Row

Source

pub fn delete_row<K: Into<PrimaryKey>>( &mut self, table: &str, key: K, ) -> &mut Row

Source

pub fn to_database_changes(self) -> DatabaseChanges

Trait Implementations§

Source§

impl Debug for Tables

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Tables

§

impl RefUnwindSafe for Tables

§

impl Send for Tables

§

impl Sync for Tables

§

impl Unpin for Tables

§

impl UnwindSafe for Tables

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.