Skip to main content

create_item

Creates a new item in the database by validating the input data, associating it with an owner, and committing the transaction to the session.

def create_item(
session: Session,
item_in: ItemCreate,
owner_id: uuid.UUID
) - > Item

Creates a new item record in the database associated with a specific owner and persists the changes.

Parameters

NameTypeDescription
sessionSessionThe active SQLAlchemy database session used to perform the transaction.
item_inItemCreateA Pydantic model containing the initial data and attributes for the new item.
owner_iduuid.UUIDThe unique identifier of the user who will own the created item.

Returns

TypeDescription
ItemThe newly created Item database model instance, refreshed with database-generated fields like IDs or timestamps.