substreams-database-change

Crates.iosubstreams-database-change
lib.rssubstreams-database-change
version2.0.0
sourcesrc
created_at2022-11-26 14:40:12.162357
updated_at2024-10-16 19:24:18.445265
descriptionSubstreams database change containg helpers
homepagehttps://substreams.streamingfast.io/
repositoryhttps://github.com/streamingfast/substreams-sink-database-changes
max_upload_size
id723296
size78,281
Mavericks (MavericksFive)

documentation

README

Substreams Sink Database Changes

github crates.io docs.rs GitHub Workflow Status

substreams-sink-database-changes contains all the definitions for database changes which can be emitted by a substream.

Used by

Install

# The Rust crate is named substreams-database-change for historical reasons
cargo add substreams-database-change

Quickstart

Cargo.toml

[dependencies]
substreams = "0.5"
substreams-database-change = "1.0"

src/lib.rs

use substreams::errors::Error;
use substreams_database_change::pb::database::{DatabaseChanges, table_change::Operation};

#[substreams::handlers::map]
fn db_out(
    ... some stores ...
) -> Result<DatabaseChanges, Error> {
    // Initialize Database Changes container
    let mut database_changes: DatabaseChanges = Default::default();

    // Push change
    database_changes.push_change("transfer", "primary-key", 0, Operation::Create)
        .change("key1", ("previous1", "value1"))
        .change("key2", ("previous2", "value2"));

    Ok(database_changes)
}

Re-generate Protobuf

Be sure to have buf CLI installed (https://buf.build/docs/installation/) and run:

buf generate proto
Commit count: 68

cargo fmt