add(obj)¶
Use this method to insert one module-owned ORM object.
Use add(...) because it gives you all of the expected module safeguards in one place:
- validates that the model belongs to the current module
- applies automatic
user_idandorganization_idassignment when those fields exist - persists the object
- commits the transaction
- refreshes the object before returning it
Example¶
row = module_sdk.database.add(
Ticket(
id=ticket_id,
title=title,
preview="",
)
)get(model, id)¶
Use this method to load one row by primary identifier inside the current module and current access scope.
The method:
- validates that the model belongs to the current module
- builds the scoped query
- filters by
model.id == id - returns the first matching row or
None
list(model, **filters)¶
Use this method to load multiple rows for one module-owned model inside the current access scope.
The method:
- validates that the model belongs to the current module
- builds the scoped query
- applies each provided filter only if the model has that attribute
- returns
query.all()
Example¶
rows = module_sdk.database.list(TicketMessage, ticket_id=ticket_id)all(model, **filters)¶
all(...) is functionally the same shape as list(...) in the current implementation.
Both methods:
- validate the model
- apply scope
- apply the provided equality filters
- return
query.all()
update(model, id, **updates)¶
Use this method to update one row by id inside the current module and current access scope.
The method:
- validates that the model belongs to the current module
- builds the scoped query
- loads the row by id inside that scope
- ignores ownership fields such as
user_idandorganization_id - applies each remaining update with
setattr - commits
- refreshes the row
- returns the updated row
If the row is not visible in the current scope, the method returns None.
update(...) is not an ownership-transfer API. Passing user_id or
organization_id does not move a row to another owner; those fields are ignored
and the runtime logs a warning.
delete(model, id) -> bool¶
Use this method to delete one row by id inside the current module and current access scope.
The method:
- validates that the model belongs to the current module
- builds the scoped query
- looks up the row by id inside that scope
- deletes it if found
- commits
- returns
Trueif a row was deleted, otherwiseFalse
Example CRUD Flow¶
row = module_sdk.database.add(
Ticket(
id="ticket_42",
title="Broken login",
status="open",
)
)
open_rows = module_sdk.database.list(Ticket, status="open")
loaded = module_sdk.database.get(Ticket, row.id)
updated = module_sdk.database.update(Ticket, row.id, status="closed")
deleted = module_sdk.database.delete(Ticket, row.id)