Skip to content

Commit

Permalink
Add new_with_client to WriteTx (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuntara authored Apr 6, 2023
1 parent e44fd69 commit 5d4cbf5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
43 changes: 43 additions & 0 deletions raiden/examples/transact_write_with_http_client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use raiden::*;

#[derive(Raiden)]
#[raiden(table_name = "user")]
pub struct User {
#[raiden(partition_key)]
pub id: String,
pub name: String,
}

fn main() {
let rt = tokio::runtime::Runtime::new().unwrap();
async fn example() {
let dispatcher =
raiden::request::HttpClient::new().expect("failed to create request dispatcher");
let credentials_provider = raiden::credential::DefaultCredentialsProvider::new()
.expect("failed to create credentials provider");
let core_client = raiden::Client::new_with(credentials_provider, dispatcher);

let tx = ::raiden::WriteTx::new_with_client(
core_client,
Region::Custom {
endpoint: "http://localhost:8000".into(),
name: "ap-northeast-1".into(),
},
);
let cond = User::condition().attr_not_exists(User::id());
let input = User::put_item_builder()
.id("testId".to_owned())
.name("bokuweb".to_owned())
.build();
let input2 = User::put_item_builder()
.id("testId2".to_owned())
.name("bokuweb".to_owned())
.build();
tx.put(User::put(input).condition(cond))
.put(User::put(input2))
.run()
.await
.unwrap();
}
rt.block_on(example());
}
8 changes: 8 additions & 0 deletions raiden/src/ops/transact_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ impl WriteTx {
retry_condition: crate::RetryCondition::new(),
}
}
pub fn new_with_client(client: crate::Client, region: crate::Region) -> Self {
let client = crate::DynamoDbClient::new_with_client(client, region);
Self {
items: vec![],
client,
retry_condition: crate::RetryCondition::new(),
}
}

pub fn with_retries(mut self, s: Box<dyn crate::retry::RetryStrategy + Send + Sync>) -> Self {
self.retry_condition.strategy = s;
Expand Down

0 comments on commit 5d4cbf5

Please sign in to comment.