Expand description
nostralink is a Rust crate that allows you to transform nostr events to linked data and save them to an RDF triple store. It also offers APIs to write events as linked data (using JSON-LD) and make queries.
§RDF events store
In order to activate nostralink for a nostr Client , open an RdfEventsStore
and set it as the client’s database.
Incoming events will automatically be converted to RDF triples and saved to the store.
use nostralink::prelude::*;
use std::path::PathBuf;
#[tokio::main]
async fn main() {
let keys = Keys::generate();
let store = RdfEventsStore::open(PathBuf::from("store")).expect("Cannot open store");
let client = Client::builder().database(store).signer(keys).build();
}§Querying
Use run_query to run a SparQL query. There is a built-in
collection
of SparQL queries. Use crate::querydb::nrq_get to retrieve a query by its name.
use nostralink::prelude::*;
use std::path::PathBuf;
fn main() -> Result<(), RdfStoreError> {
let store = RdfEventsStore::open(PathBuf::from("store")).expect("Cannot open store");
let result_set = store
.run_query(&nrq_get("user_metadata")?, [], None)?;
for row in &result_set.rows {
if let Some(cell) = row.get("metadata_name") {
println!("name: {}", cell.to_string());
}
}
Ok(())
}Modules§
- err
- Errors
- ldbuilder
- LD builder module
- ldevents
- Embed JSON-LD in nostr events
- niri
- Nostralink IRIs
- oxistore
- Oxigraph store for nostr events
- parser
- JSON-LD parser
- querydb
- API to retrieve SparQL queries from the built-in queries database
- rdfify
- Functions to transform nostr Events to RDF using oxjsonld
- rdfify_
sophia - Functions to transform nostr Events to RDF (using sophia)
- util
- Util