Skip to main content

GetItemRequest

Struct GetItemRequest 

Source
pub struct GetItemRequest<TD: TableDefinition, T = (), O: OutputFormat = Raw, P: ProjectionState = NoProjection> { /* private fields */ }
Expand description

Builder for a DynamoDB GetItem request.

Constructed via DynamoDBItemOp::get (typed, with a concrete T) or GetItemRequest::new (stand-alone, raw output). The builder provides:

  • Output format — the result can be deserialized into T. Call .raw() to receive an untyped Item<TD> instead (one-way).
  • Projection — call .project() to limit which attributes are returned. This can only be called once and automatically switches to raw output, since the projected result may not contain all fields required for deserialization.

The builder implements IntoFuture, so it can be .awaited directly without calling .execute() explicitly.

§Errors

Returns Err if the DynamoDB request fails or if deserialization of the returned attributes fails.

§Examples

use dynamodb_facade::{DynamoDBItemOp, KeyId};

// Simple get
let user /* : Option<User> */ = User::get(client, KeyId::pk("user-1")).await?;

// Consistent read
let user /* : Option<User> */ = User::get(client, KeyId::pk("user-1"))
    .consistent_read()
    .await?;

Implementations§

Source§

impl<TD: TableDefinition> GetItemRequest<TD>

Source

pub fn new(client: Client, key: Key<TD>) -> Self

Creates a stand-alone GetItemRequest with raw output (T = (), O = Raw).

Use this when you do not have a concrete item type and want to work with the raw Item<TD> map directly. For typed access, prefer DynamoDBItemOp::get instead.

§Examples
use dynamodb_facade::{GetItemRequest, Key};

let raw_item = GetItemRequest::<PlatformTable>::new(client, key).await?;
Source§

impl<TD: TableDefinition, T, O: OutputFormat, P: ProjectionState> GetItemRequest<TD, T, O, P>

Source

pub fn consistent_read(self) -> Self

Enables strongly consistent reads for this request.

By default DynamoDB uses eventually consistent reads. Enabling consistent reads guarantees the most up-to-date data but consumes twice the read capacity units and is not supported on Global Secondary Indexes.

§Examples
use dynamodb_facade::{DynamoDBItemOp, KeyId};

let user /* : Option<User> */ = User::get(client, KeyId::pk("user-1"))
    .consistent_read()
    .await?;
Source

pub fn into_inner(self) -> GetItemFluentBuilder

Consumes the builder and returns the underlying SDK GetItemFluentBuilder.

Use this escape hatch when you need to set options not exposed by this facade, such as expression_attribute_names for a manual projection, or when integrating with code that expects the raw SDK builder.

§Examples
use dynamodb_facade::{DynamoDBItemOp, KeyId};

let sdk_builder = User::get(client, KeyId::pk("user-1")).into_inner();
// configure sdk_builder further, then call .send().await
Source§

impl<TD: TableDefinition, T, O: OutputFormat> GetItemRequest<TD, T, O, NoProjection>

Source

pub fn project( self, projection: Projection<'_, TD>, ) -> GetItemRequest<TD, T, Raw, AlreadyHasProjection>

Applies a projection expression, limiting the attributes returned.

This method can only be called once. It forces the output to raw Item<TD> because projected results may not contain all fields required for deserialization into T.

§Examples
use dynamodb_facade::{AttributeDefinition, DynamoDBItemOp, KeyId, Projection};

// Fetch only the "name" and "email" attributes
let partial /* : Option<Item<PlatformTable>> */ =
    User::get(client, KeyId::pk("user-1"))
        .project(Projection::new(["name", Email::NAME]))
        .await?;
// partial: contains only "PK", "SK", "name" and "email"
Source§

impl<TD: TableDefinition, T, P: ProjectionState> GetItemRequest<TD, T, Typed, P>

Source

pub fn raw(self) -> GetItemRequest<TD, T, Raw, P>

Switches the output format from Typed to Raw.

After calling .raw(), execute returns Option<Item<TD>> instead of Option<T>. This transition is one-way — you cannot switch back to Typed.

§Examples
use dynamodb_facade::{DynamoDBItemOp, KeyId};

let raw_item = User::get(client, KeyId::pk("user-1"))
    .raw()
    .await?;
// raw_item: Option<Item<PlatformTable>>
if let Some(item) = raw_item {
    let name = item.get("name");
}
Source§

impl<TD: TableDefinition, T: DynamoDBItem<TD> + DeserializeOwned, P: ProjectionState> GetItemRequest<TD, T, Typed, P>

Source

pub fn execute(self) -> impl Future<Output = Result<Option<T>>> + Send + 'static

Sends the GetItem request and returns the item deserialized as T.

Returns Ok(None) if no item exists for the given key.

This method is also available implicitly via .await because GetItemRequest implements IntoFuture.

§Errors

Returns Err if the DynamoDB request fails or if deserialization of the returned attributes fails.

§Examples
use dynamodb_facade::{DynamoDBItemOp, KeyId};

let user /* : Option<User> */ = User::get(client, KeyId::pk("user-1"))
    .consistent_read()
    .execute()
    .await?;
Source§

impl<TD: TableDefinition, T, P: ProjectionState> GetItemRequest<TD, T, Raw, P>

Source

pub fn execute( self, ) -> impl Future<Output = Result<Option<Item<TD>>>> + Send + 'static

Sends the GetItem request and returns the raw item map.

Returns Ok(None) if no item exists for the given key.

This method is also available implicitly via .await because GetItemRequest implements IntoFuture.

§Errors

Returns Err if the DynamoDB request fails.

§Examples
use dynamodb_facade::{DynamoDBItemOp, KeyId};

let raw = User::get(client, KeyId::pk("user-1"))
    .raw()
    .execute()
    .await?;
// raw: Option<Item<PlatformTable>>
if let Some(item) = raw {
    let name = item.get("name");
}

Auto Trait Implementations§

§

impl<TD, T, O, P> Freeze for GetItemRequest<TD, T, O, P>

§

impl<TD, T = (), O = Raw, P = NoProjection> !RefUnwindSafe for GetItemRequest<TD, T, O, P>

§

impl<TD, T, O, P> Send for GetItemRequest<TD, T, O, P>
where TD: Send, T: Send, O: Send, P: Send,

§

impl<TD, T, O, P> Sync for GetItemRequest<TD, T, O, P>
where TD: Sync, T: Sync, O: Sync, P: Sync,

§

impl<TD, T, O, P> Unpin for GetItemRequest<TD, T, O, P>
where TD: Unpin, T: Unpin, O: Unpin, P: Unpin,

§

impl<TD, T, O, P> UnsafeUnpin for GetItemRequest<TD, T, O, P>

§

impl<TD, T = (), O = Raw, P = NoProjection> !UnwindSafe for GetItemRequest<TD, T, O, P>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more