Skip to content

feat: Update readme #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
445 changes: 434 additions & 11 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
doc-valid-idents = ["EventSourcingDB", "EventQL", "CloudEvents", ".."]
21 changes: 21 additions & 0 deletions examples/event_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use eventsourcingdb::client::Client;
use futures::StreamExt;
use url::Url;

#[tokio::main]
async fn main() {
let base_url: Url = "localhost:3000".parse().unwrap();
let api_token = "secret";
let client = Client::new(base_url, api_token);

let result = client.list_event_types().await;

match result {
Err(err) => panic!("{}", err),
Ok(mut event_types) => {
while let Some(Ok(event_type)) = event_types.next().await {
println!("{:?}", event_type)
}
}
}
}
21 changes: 21 additions & 0 deletions examples/listing_subjects.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use eventsourcingdb::client::Client;
use futures::StreamExt;
use url::Url;

#[tokio::main]
async fn main() {
let base_url: Url = "localhost:3000".parse().unwrap();
let api_token = "secret";
let client = Client::new(base_url, api_token);

let result = client.list_subjects(Some("/")).await;

match result {
Err(err) => panic!("{}", err),
Ok(mut subjects) => {
while let Some(Ok(subject)) = subjects.next().await {
println!("{:?}", subject)
}
}
}
}
30 changes: 30 additions & 0 deletions examples/observing_events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use eventsourcingdb::client::{Client, request_options::ObserveEventsRequestOptions};
use futures::StreamExt;
use url::Url;

#[tokio::main]
async fn main() {
let base_url: Url = "localhost:3000".parse().unwrap();
let api_token = "secret";
let client = Client::new(base_url, api_token);

let result = client
.observe_events(
"/books/42",
Some(ObserveEventsRequestOptions {
recursive: false,
from_latest_event: None,
lower_bound: None,
}),
)
.await;

match result {
Err(err) => panic!("{}", err),
Ok(mut stream) => {
while let Some(Ok(event)) = stream.next().await {
println!("{:?}", event)
}
}
}
}
15 changes: 15 additions & 0 deletions examples/ping.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use eventsourcingdb::client::Client;
use url::Url;

#[tokio::main]
async fn main() {
let base_url: Url = "localhost:3000".parse().unwrap();
let api_token = "secret";
let client = Client::new(base_url, api_token);

let result = client.ping().await;
if let Err(err) = result {
// handle error
panic!("{}", err)
}
}
32 changes: 32 additions & 0 deletions examples/reading_events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use eventsourcingdb::client::{Client, request_options::ReadEventsRequestOptions};
use futures::StreamExt;
use url::Url;

#[tokio::main]
async fn main() {
let base_url: Url = "localhost:3000".parse().unwrap();
let api_token = "secret";
let client = Client::new(base_url, api_token);

let result = client
.read_events(
"/books/42",
Some(ReadEventsRequestOptions {
recursive: false,
from_latest_event: None,
order: None,
lower_bound: None,
upper_bound: None,
}),
)
.await;

match result {
Err(err) => panic!("{}", err),
Ok(mut stream) => {
while let Some(Ok(event)) = stream.next().await {
println!("{:?}", event)
}
}
}
}
34 changes: 34 additions & 0 deletions examples/registering_event_schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use eventsourcingdb::client::Client;
use serde_json::json;
use url::Url;

#[tokio::main]
async fn main() {
let base_url: Url = "localhost:3000".parse().unwrap();
let api_token = "secret";
let client = Client::new(base_url, api_token);

let result = client
.register_event_schema(
"io.eventsourcingdb.library.book-acquired",
&json!({
"type": "object",
"properties": {
"title": { "type": "string" },
"author": { "type": "string" },
"isbn": { "type": "string" },
},
"required": [
"title",
"author",
"isbn",
],
"additionalProperties": false,
}),
)
.await;

if let Err(err) = result {
panic!("{}", err)
}
}
23 changes: 23 additions & 0 deletions examples/running_eventql.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use eventsourcingdb::client::Client;
use futures::StreamExt;
use url::Url;

#[tokio::main]
async fn main() {
let base_url: Url = "localhost:3000".parse().unwrap();
let api_token = "secret";
let client = Client::new(base_url, api_token);

let result = client
.run_eventql_query("FROM e IN events PROJECT INTO e")
.await;

match result {
Err(err) => panic!("{}", err),
Ok(mut stream) => {
while let Some(Ok(row)) = stream.next().await {
println!("{:?}", row)
}
}
}
}
15 changes: 15 additions & 0 deletions examples/verify_api_token.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use eventsourcingdb::client::Client;
use url::Url;

#[tokio::main]
async fn main() {
let base_url: Url = "localhost:3000".parse().unwrap();
let api_token = "secret";
let client = Client::new(base_url, api_token);

let result = client.verify_api_token().await;
if let Err(err) = result {
// handle error
panic!("{}", err)
}
}
27 changes: 27 additions & 0 deletions examples/write_events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use eventsourcingdb::{client::Client, event::EventCandidate};
use serde_json::json;
use url::Url;

#[tokio::main]
async fn main() {
let base_url: Url = "localhost:3000".parse().unwrap();
let api_token = "secret";
let client = Client::new(base_url, api_token);

let event = EventCandidate::builder()
.source("https://library.eventsourcingdb.io".to_string())
.subject("/books/42".to_string())
.ty("io.eventsourcingdb.library.book-acquired")
.data(json!({
"title": "2001 - A Space Odyssey",
"author": "Arthur C. Clarke",
"isbn": "978-0756906788",
}))
.build();

let result = client.write_events(vec![event.clone()], vec![]).await;
match result {
Ok(written_events) => println!("{:?}", written_events),
Err(err) => panic!("{}", err),
}
}
32 changes: 31 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
#![doc = include_str!("../README.md")]
//! # eventsourcingdb
//!
//! The official Rust client SDK for [EventSourcingDB](https://www.eventsourcingdb.io) – a purpose-built database for event sourcing.
//! EventSourcingDB enables you to build and operate event-driven applications with native support for writing, reading, and observing events. This client SDK provides convenient access to its capabilities in Rust.
//! For more information on EventSourcingDB, see its [official documentation](https://docs.eventsourcingdb.io/).
//! This client SDK includes support for [Testcontainers](https://testcontainers.com/) to spin up EventSourcingDB instances in integration tests. For details, see [Using Testcontainers](#using-testcontainers).
//!
//! ## Getting Started
//!
//! Install the client SDK:
//!
//! ```shell
//! cargo add eventsourcingdb
//! ```
//!
//! Import the package and create an instance by providing the URL of your EventSourcingDB instance and the API token to use:
//!
//! ```rust
//! use eventsourcingdb::client::Client;
//! # use url::Url;
//! // ...
//!
//! let base_url: Url = "localhost:3000".parse().unwrap();
//! let api_token = "secret";
//! let client = Client::new(base_url, api_token);
//! ```
//!
//! ## Examples
//!
//! Examples can be found in the [examples](https://github.com/thenativeweb/eventsourcingdb-client-rust/tree/main/examples) directory.
//!
// There is a known bug in clippy:
// https://github.com/rust-lang/rust-clippy/issues/12908
#![allow(clippy::needless_lifetimes)]
Expand Down