Methods
_accumulateCapacityToContext(capacityUnits, type)
- Description:
Accumulate capacity units to the current batch context. This is called internally by model operations to track total capacity consumed.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
capacityUnits |
number | The capacity units to accumulate |
type |
string | Either "read" or "write" |
_withExtraCapacityUnits()
- Description:
Return a ConsumedCapacity object with
extraUnitsadded to its CapacityUnits. Used so the legacy-fallback reads (migrating mode) are reflected in the capacity carried by the returned item/ObjectNotFound, not just the context.
- Source:
getBatchContextCapacity() → {Object}
- Description:
Get the total consumed capacity for the current batch context. Returns the accumulated RCUs and WCUs for all operations within the current runWithBatchContext scope.
- Source:
Example
import { runWithBatchContext, getBatchContextCapacity } from "dynamo-bao";
await runWithBatchContext(async () => {
await User.find(userId);
await Post.queryByIndex('byUser', userId);
const capacity = getBatchContextCapacity();
console.log(`Read: ${capacity.read} RCUs, Write: ${capacity.write} WCUs`);
});
Returns:
The accumulated capacity, or { read: 0, write: 0 } if not in a batch context
- Type
- Object
runWithBatchContext(fn) → {*}
- Description:
Initialize batch context for request-scoped batching. This should be called at the beginning of each request in Cloudflare Workers.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
fn |
function | Function to run within the batch context |
Returns:
Result of the function
- Type
- *