aymond
A batteries-included client wrapper for DynamoDB
Builds upon the existing AWS SDK DynamoDB client, providing a high-level interface, somewhat akin to the DynamoDB Enhanced Java Client
Usage
Item shapes are described by structs:
#[aymond(item, table)]
struct Car {
#[hash_key]
make: String,
#[sort_key]
model: String,
hp: i16,
variants: Vec<String>,
production: Production,
}
#[aymond(nested_item)]
struct Production {
began: i32,
#[attribute(name = "units_produced")]
units: i64,
}
Interacting with the table is done through a Table instance:
let table = CarTable::new_with_local_config("test", "http://localhost:8000", "us-west-2");
table.create(false).await.expect("Failed to create");
Writing an item with put:
let it = Car {
make: "Porsche".to_string(),
model: "911".to_string(),
hp: 518,
variants: vec![
"Carrera".into(),
"Carrera S".into(),
"Carrera 4S".into(),
"GT3 RS".into(),
],
production: Production {
began: 1964,
units: 1_100_000,
},
};
table.put(it).await.expect("Failed to write");
Reading an item with get:
let _: Option<Car> = table
.get(|k| k.make("Porsche").model("911"))
.await
.expect("Failed to read");
use aymond::{prelude::*, shim::futures::StreamExt};
#[aymond(item, table)]
struct Car {
#[hash_key]
make: String,
#[sort_key]
model: String,
hp: i16,
variants: Vec<String>,
production: Production,
}
#[aymond(nested_item)]
struct Production {
began: i32,
#[attribute(name = "units_produced")]
units: i64,
}
#[tokio::main]
async fn main() {
let table = CarTable::new_with_local_config("test", "http://localhost:8000", "us-west-2");
table.create(false).await.expect("Failed to create");
let it = Car {
make: "Porsche".to_string(),
model: "911".to_string(),
hp: 518,
variants: vec![
"Carrera".into(),
"Carrera S".into(),
"Carrera 4S".into(),
"GT3 RS".into(),
],
production: Production {
began: 1964,
units: 1_100_000,
},
};
table.put(it).await.expect("Failed to write");
let _: Option<Car> = table
.get(|k| k.make("Porsche").model("911"))
.await
.expect("Failed to read");
let res: Result<_, _> = table
.get_item(
|k| k.make("Porsche").model("911"),
|r| r.consistent_read(true),
)
.await;
let _: Option<Car> = res.ok().and_then(|e| e.item().map(|i| i.into()));
}
Not (yet) implemented
- Query operation with fluent builder pattern
- Update operation with fluent builder pattern
- Global/local indices
- Optimistic locking with version attribute
- Transaction system, including cross-table
- Projections