(
c: &Client,
name: &str,
hash_key: &str,
range_key: Option<&str>,
attr_defs: Vec<AttributeDefinition>,
gsis: Option<Vec<GlobalSecondaryIndex>>,
)
| 251 | } |
| 252 | |
| 253 | async fn create_table_raw( |
| 254 | c: &Client, |
| 255 | name: &str, |
| 256 | hash_key: &str, |
| 257 | range_key: Option<&str>, |
| 258 | attr_defs: Vec<AttributeDefinition>, |
| 259 | gsis: Option<Vec<GlobalSecondaryIndex>>, |
| 260 | ) { |
| 261 | let mut key_schema = vec![KeySchemaElement::builder() |
| 262 | .attribute_name(hash_key) |
| 263 | .key_type(KeyType::Hash) |
| 264 | .build() |
| 265 | .unwrap()]; |
| 266 | |
| 267 | if let Some(rk) = range_key { |
| 268 | key_schema.push( |
| 269 | KeySchemaElement::builder() |
| 270 | .attribute_name(rk) |
| 271 | .key_type(KeyType::Range) |
| 272 | .build() |
| 273 | .unwrap(), |
| 274 | ); |
| 275 | } |
| 276 | |
| 277 | let mut req = c |
| 278 | .create_table() |
| 279 | .table_name(name) |
| 280 | .billing_mode(BillingMode::PayPerRequest) |
| 281 | .set_key_schema(Some(key_schema)) |
| 282 | .set_attribute_definitions(Some(attr_defs)); |
| 283 | |
| 284 | if let Some(g) = gsis { |
| 285 | req = req.set_global_secondary_indexes(Some(g)); |
| 286 | } |
| 287 | |
| 288 | match req.send().await { |
| 289 | Ok(_) => {} |
| 290 | Err(e) => { |
| 291 | if err_code(&e) != Some("ResourceInUseException") { |
| 292 | panic!("Failed to create table {name}: {e:?}"); |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | wait_for_active(c, name).await; |
| 297 | } |
| 298 | |
| 299 | async fn create_table_with_gsi( |
| 300 | c: &Client, |
no test coverage detected