CRUD Operations¶
Create / Save¶
product = Product(
product_id="prod-123",
name="Widget",
price=29.99,
in_stock=True
)
product.save()
Create with Condition (Insert-if-not-exists)¶
This raises ConditionalCheckFailedError if the item already exists.
INSERT Semantics with create()¶
For models with Auto-UUID keys, create() guarantees insert-only semantics:
class Task(DynamoModel):
task_id: str = Key(auto=True)
title: str
class Meta:
table_name = "tasks"
task = Task(title="Buy groceries")
task.create() # Generates UUID and saves with condition check
Read / Get¶
# By partition key only
product = Product.get("prod-123")
# By partition + sort key
order = Order.get("customer-456", "order-789")
# Returns None if not found (no exception)
missing = Product.get("nonexistent") # None
Info
get() always returns None for missing items — never raises an exception.
Update¶
Fetch-then-save¶
Atomic updates (no fetch required)¶
For atomic, server-side updates without a round-trip, see Atomic Updates.