pub struct DynamodbConnector { /* private fields */ }
Expand description
Provides a connection to DynamoDB, potentially managing test table lifecycles.
This struct encapsulates an AWS DynamoDB client (aws_sdk_dynamodb::Client
).
If configured with table definitions and a local endpoint
in TableConfig
,
it will create uniquely named tables upon construction.
If the test_utils
feature is enabled and delete_on_exit
is true in the
configuration, the created tables will be automatically deleted when this
connector is dropped.
Implementations§
Source§impl DynamodbConnector
impl DynamodbConnector
Sourcepub async fn load(config_path: impl AsRef<Path>) -> Result<Self>
pub async fn load(config_path: impl AsRef<Path>) -> Result<Self>
Creates a new connector by loading configuration from a YAML file.
See TableConfig::load_from_file
and DynamodbConnector::try_new
.
§Errors
Returns Err
if loading the config file fails or if creating the connector fails
(e.g., table creation fails, AWS configuration error).
Sourcepub fn client(&self) -> Result<&Client>
pub fn client(&self) -> Result<&Client>
Returns a reference to the underlying aws_sdk_dynamodb::Client
.
§Errors
Returns Err
(DynamoToolsError::Internal
) if the client has already been
taken (e.g., after Drop
has started).
Sourcepub fn get_created_table_name(&self, base_name: &str) -> Option<&str>
pub fn get_created_table_name(&self, base_name: &str) -> Option<&str>
Returns the unique name of a table created by this connector, given its base name.
The base_name
corresponds to the table_name
field within [TableInfo
]
in the configuration.
Sourcepub fn get_all_created_table_names(&self) -> &HashMap<String, String>
pub fn get_all_created_table_names(&self) -> &HashMap<String, String>
Returns a map of all tables created by this connector. Keys are the base names from the config, values are the unique created names.
Sourcepub async fn try_new(config: TableConfig) -> Result<Self>
pub async fn try_new(config: TableConfig) -> Result<Self>
Creates a new connector based on the provided TableConfig
.
- Sets up AWS SDK configuration.
- Creates a
aws_sdk_dynamodb::Client
. - Iterates through
config.tables
. For eachTableInfo
:- Attempts to create a DynamoDB table with a unique name derived from
TableInfo.table_name
. - Stores the mapping from the base name to the unique name.
- Attempts to create a DynamoDB table with a unique name derived from
§Errors
Returns Err
if AWS config fails, client creation fails, or any table creation fails.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DynamodbConnector
impl !RefUnwindSafe for DynamodbConnector
impl Send for DynamodbConnector
impl Sync for DynamodbConnector
impl Unpin for DynamodbConnector
impl !UnwindSafe for DynamodbConnector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more