Skip to content

feat: add convenience hooks for to_model operations - #347

Merged
cofin merged 2 commits into
mainfrom
to_model_hooks
Jan 17, 2025
Merged

cofin merged 2 commits into
mainfrom
to_model_hooks

Conversation

@cofin

@cofin cofin commented Jan 17, 2025

Copy link
Copy Markdown
Member

The service layer has always has a to_model function that accepts data and optionally an operation name. It would return a SQLAlchemy model no matter the input you gave it.

It is possible to move business logic into this to_model layer for populating fields on insert. (i.e. slug fields or tags, etc.).

When having logic for insert, update, delete, and upsert, that function can be a bit overwhelcoming. Now, there are helper functions that you can use that is specific to each DML hook:

  • to_model_on_create
  • to_model_on_update
  • to_model_on_delete
  • to_model_on_upsert

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

Documentation preview will be available shortly at https://litestar-org.github.io/advanced-alchemy-docs-preview/347

@cofin
cofin merged commit d7ce1c2 into main Jan 17, 2025
@cofin
cofin deleted the to_model_hooks branch January 17, 2025 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant