You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
how do i add a hook method? : Such as modified_field, validate_delete, validate_field,validate_write
Describe the solution you'd like
1, When inserting or updating an entity, the validate_write method is triggered ;
2,When the entity field value is modified, the modified_field and validate_field method is triggered ;
3.When the entity field value is modified, there is a method such as orig() that returns the original record value before modification.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
There's no direct functionality like those hooks, but since most of the methods of the entities returns a wrapper Result<T, E>, (and the ones that makes inserts and updates for sure) you can apply any of the methods over the result wrapper to implement a similar functionality, for example, you can invoke .map(), and_then(), or() and pass the logic that you want to execute to the methods argument (typically a clousure).
For example, after inserting data with a canyon_entity instace, invoking the .insert() method, you'll obtain a Result<Pk, Err>, where Pk is just a placeholder for the same datatype that holds the primary_key annotation on your entity.
So, if you need something with that, you'll need to procedurally manipulate the Result with the methods provided in its API, or do a pattern matching for handling the Ok or Err variants.
Activity
github-actions commentedon Apr 22, 2024
Thank you for opening your first issue in the Canyon-SQL project!
TheRustifyer commentedon Apr 22, 2024
Hello @qibinlin
There's no direct functionality like those
hooks, but since most of the methods of the entities returns a wrapperResult<T, E>, (and the ones that makes inserts and updates for sure) you can apply any of the methods over the result wrapper to implement a similar functionality, for example, you can invoke.map(),and_then(),or()and pass the logic that you want to execute to the methods argument (typically a clousure).For example, after inserting data with a
canyon_entityinstace, invoking the.insert()method, you'll obtain aResult<Pk, Err>, wherePkis just a placeholder for the same datatype that holds theprimary_keyannotation on your entity.So, if you need something with that, you'll need to procedurally manipulate the
Resultwith the methods provided in its API, or do a pattern matching for handling the Ok or Err variants.Let us know if this helped you.
Cheers.