Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/streamingfast/substreams-sink-database-changes
https://github.com/streamingfast/substreams-sink-database-changes
Last synced: about 15 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/streamingfast/substreams-sink-database-changes
- Owner: streamingfast
- License: apache-2.0
- Created: 2022-06-21T13:21:22.000Z (over 2 years ago)
- Default Branch: develop
- Last Pushed: 2024-10-16T19:24:23.000Z (29 days ago)
- Last Synced: 2024-11-08T09:03:15.937Z (6 days ago)
- Language: Rust
- Size: 227 KB
- Stars: 0
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-substreams - DatabaseChanges - [`sf.substreams.sink.database.v1`](https://github.com/streamingfast/substreams-database-change/blob/develop/proto/substreams/sink/database/v1/database.proto) (Protobuf / Sinks)
README
# Substreams Sink Database Changes
[](https://github.com/streamingfast/substreams-sink-database-changes)
[](https://crates.io/crates/substreams-database-change)
[](https://docs.rs/substreams-database-change)
[](https://github.com/streamingfast/substreams-sink-database-changes/actions?query=branch%3Adevelop)> `substreams-sink-database-changes` contains all the definitions for database changes which can be emitted by a substream.
## Used by
- [substreams-sink-postgres](https://github.com/streamingfast/substreams-sink-postgres)
- [substreams-sink-mongodb](https://github.com/streamingfast/substreams-sink-mongodb)## Install
```bash
# The Rust crate is named substreams-database-change for historical reasons
cargo add substreams-database-change
```## Quickstart
**Cargo.toml**
```toml
[dependencies]
substreams = "0.5"
substreams-database-change = "1.0"
```**src/lib.rs**
```rust
use substreams::errors::Error;
use substreams_database_change::pb::database::{DatabaseChanges, table_change::Operation};#[substreams::handlers::map]
fn db_out(
... some stores ...
) -> Result {
// 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:
```bash
buf generate proto
```