Gnosis
Add Triple
Append a string triple and update the current instance’s three indexes.
add_triple(subject, predicate, object).await serializes a Triple, appends it to the supplied Strand, then indexes the sequence by subject, predicate and object. It returns (), not a triple ID. Duplicate triples are allowed. Persistence follows the Strand backend; no automatic replay rebuilds indexed queries on a new Gnosis/SDK instance. Check-then-add is not a uniqueness transaction, and a Lens boolean does not make it one.
This example is checked against source signatures; it was not compiled or run during this documentation pass.
use std::sync::Arc;
use tokio::sync::RwLock;
use strand::{Strand, StrandConfig};
use gnosis::Gnosis;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let dir = tempfile::tempdir()?;
let cfg = StrandConfig::new().with_storage(dir.path());
let strand = Arc::new(RwLock::new(Strand::new(cfg).await?));
let gnosis = Gnosis::new(strand);
gnosis.add_triple("alice", "trusts", "bob").await?;
gnosis.add_triple("alice", "trusts", "carol").await?;
gnosis.add_triple("bob", "has_role", "admin").await?;
gnosis.add_triple("carol", "has_role", "viewer").await?;
println!("4 facts persisted to the Strand and indexed by S/P/O");
Ok(())
}