Skip to main content

Database

Struct Database 

Source
pub struct Database<S = RusqliteBackend> { /* private fields */ }
Expand description

The main entry point for the DynamoDB emulator.

Generic over the storage backend S, monomorphised (no dyn). The type parameter defaults to RusqliteBackend, so Database means the native engine and the public synchronous API is preserved via NativeDatabase.

Wraps a storage layer and provides DynamoDB-compatible operations. Thread-safe via Arc<Mutex<>>, so clone freely across threads.

Implementations§

Source§

impl Database<RusqliteBackend>

Source

pub fn new(path: &str) -> Result<Self>

Open a persistent database at the given path.

Source

pub fn memory() -> Result<Self>

Open an in-memory database (for tests and ephemeral use).

Source

pub fn create_table( &self, request: CreateTableRequest, ) -> Result<CreateTableResponse>

Create a new DynamoDB table.

Source

pub fn delete_table( &self, request: DeleteTableRequest, ) -> Result<DeleteTableResponse>

Delete a DynamoDB table.

Source

pub fn describe_table( &self, request: DescribeTableRequest, ) -> Result<DescribeTableResponse>

Describe a DynamoDB table.

Source

pub fn update_table( &self, request: UpdateTableRequest, ) -> Result<UpdateTableResponse>

Update a DynamoDB table (add/remove GSIs).

Source

pub fn list_tables( &self, request: ListTablesRequest, ) -> Result<ListTablesResponse>

List DynamoDB tables.

Source

pub fn tag_resource( &self, request: TagResourceRequest, ) -> Result<TagResourceResponse>

Add tags to a DynamoDB table.

Source

pub fn untag_resource( &self, request: UntagResourceRequest, ) -> Result<UntagResourceResponse>

Remove tags from a DynamoDB table.

Source

pub fn list_tags_of_resource( &self, request: ListTagsOfResourceRequest, ) -> Result<ListTagsOfResourceResponse>

List tags for a DynamoDB table.

Source

pub fn put_item(&self, request: PutItemRequest) -> Result<PutItemResponse>

Put an item into a DynamoDB table.

Source

pub fn get_item(&self, request: GetItemRequest) -> Result<GetItemResponse>

Get an item from a DynamoDB table.

Source

pub fn delete_item( &self, request: DeleteItemRequest, ) -> Result<DeleteItemResponse>

Delete an item from a DynamoDB table.

Source

pub fn update_item( &self, request: UpdateItemRequest, ) -> Result<UpdateItemResponse>

Update an item in a DynamoDB table.

Source

pub fn batch_get_item( &self, request: BatchGetItemRequest, ) -> Result<BatchGetItemResponse>

Batch get items from one or more DynamoDB tables.

Source

pub fn batch_write_item( &self, request: BatchWriteItemRequest, ) -> Result<BatchWriteItemResponse>

Batch write items to one or more DynamoDB tables.

Source

pub fn import_items( &self, table_name: &str, items: Vec<Item>, options: ImportOptions, ) -> Result<ImportResult>

Import items in bulk, bypassing per-item size validation.

All items are inserted in a single transaction. If any item fails, the entire import is rolled back. Items with duplicate keys within the batch are resolved by last-write-wins (later items in the vec overwrite earlier items with the same primary key).

GSI entries are maintained: items with GSI key attributes are inserted into the appropriate GSI tables. Items missing GSI key attributes are silently omitted from the GSI (sparse GSI behavior, matching DynamoDB semantics).

Stream records are NOT generated by default. Use ImportOptions { record_streams: true, .. } if stream recording is needed.

Source

pub fn enable_bulk_loading(&self) -> Result<()>

Set aggressive SQLite PRAGMAs for bulk loading.

Only safe when data loss on crash is acceptable (e.g., fresh import). Call disable_bulk_loading() after the import to restore normal settings.

Source

pub fn disable_bulk_loading(&self) -> Result<()>

Restore normal SQLite PRAGMAs after bulk loading.

Source

pub fn query(&self, request: QueryRequest) -> Result<QueryResponse>

Query a DynamoDB table.

Source

pub fn scan(&self, request: ScanRequest) -> Result<ScanResponse>

Scan a DynamoDB table.

Source

pub fn transact_write_items( &self, request: TransactWriteItemsRequest, ) -> Result<TransactWriteItemsResponse>

Execute a transactional write (up to 100 actions, all-or-nothing).

Source

pub fn transact_get_items( &self, request: TransactGetItemsRequest, ) -> Result<TransactGetItemsResponse>

Execute a transactional read (up to 100 gets).

Source

pub fn list_streams( &self, request: ListStreamsRequest, ) -> Result<ListStreamsResponse>

List DynamoDB Streams.

Source

pub fn describe_stream( &self, request: DescribeStreamRequest, ) -> Result<DescribeStreamResponse>

Describe a DynamoDB Stream.

Source

pub fn get_shard_iterator( &self, request: GetShardIteratorRequest, ) -> Result<GetShardIteratorResponse>

Get a shard iterator.

Source

pub fn get_records( &self, request: GetRecordsRequest, ) -> Result<GetRecordsResponse>

Get stream records.

Source

pub fn update_time_to_live( &self, request: UpdateTimeToLiveRequest, ) -> Result<UpdateTimeToLiveResponse>

Update time to live configuration.

Source

pub fn describe_time_to_live( &self, request: DescribeTimeToLiveRequest, ) -> Result<DescribeTimeToLiveResponse>

Describe time to live configuration.

Source

pub fn sweep_ttl(&self) -> Result<usize>

Run a TTL sweep, deleting expired items from all TTL-enabled tables. Returns the number of items deleted.

Source

pub fn execute_statement( &self, request: ExecuteStatementRequest, ) -> Result<ExecuteStatementResponse>

Execute a single PartiQL statement.

Source

pub fn execute_transaction( &self, request: ExecuteTransactionRequest, ) -> Result<ExecuteTransactionResponse>

Execute PartiQL statements transactionally (all-or-nothing).

Source

pub fn batch_execute_statement( &self, request: BatchExecuteStatementRequest, ) -> Result<BatchExecuteStatementResponse>

Execute a batch of PartiQL statements.

Source

pub fn touch_cached_at( &self, table_name: &str, pk: &str, sk: &str, timestamp: f64, ) -> Result<()>

Update the cached_at timestamp for a single item.

Used by cache layers to track when items were last fetched from a remote source. The timestamp is a Unix epoch in seconds (f64).

Source

pub fn get_lru_items( &self, table_name: &str, limit: usize, ) -> Result<Vec<(String, String, i64)>>

Get items ordered by cached_at (oldest first) for LRU eviction.

Returns (pk, sk, item_size) tuples. Items with NULL cached_at are excluded (they were never cached from a remote source).

Source

pub fn db_path(&self) -> Result<Option<String>>

Get the database file path, or None for in-memory databases.

Source

pub fn db_size_bytes(&self) -> Result<u64>

Get the total database size in bytes.

Source

pub fn table_count(&self) -> Result<usize>

Count the number of DynamoDB tables.

Source

pub fn table_stats(&self) -> Result<Vec<TableStats>>

Get per-table statistics: name, item count, and approximate size in bytes.

Source

pub fn get_table_metadata( &self, table_name: &str, ) -> Result<Option<TableMetadata>>

Get metadata for a specific table (key schema, GSIs, TTL config, etc.).

Source

pub fn database_info(&self) -> Result<DatabaseInfo>

Get combined database info atomically in a single lock acquisition.

Returns path, size, table count, and per-table stats + metadata. Avoids the consistency issues of calling individual methods separately.

Source

pub fn vacuum(&self) -> Result<()>

Run VACUUM to compact the database file in place.

Source

pub fn vacuum_into(&self, path: &str) -> Result<()>

Create a snapshot of the database by copying it to the given path.

Uses SQLite’s VACUUM INTO which works for both in-memory and file-backed databases. The snapshot is a standalone SQLite file.

Source

pub fn restore_from(&self, path: &str) -> Result<()>

Restore the database from a snapshot file.

Uses SQLite’s backup API to replace the current database contents with the snapshot. Works for both in-memory and file-backed databases. The backup is atomic — either all pages are copied or none are.

Trait Implementations§

Source§

impl<S> Clone for Database<S>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<S> Freeze for Database<S>

§

impl<S> RefUnwindSafe for Database<S>

§

impl<S> Send for Database<S>
where S: Send,

§

impl<S> Sync for Database<S>
where S: Send,

§

impl<S> Unpin for Database<S>

§

impl<S> UnsafeUnpin for Database<S>

§

impl<S> UnwindSafe for Database<S>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> Fake for T

Source§

fn fake<U>(&self) -> U
where Self: FakeBase<U>,

Source§

fn fake_with_rng<U, R>(&self, rng: &mut R) -> U
where R: Rng + ?Sized, Self: FakeBase<U>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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