Skip to content

Can add a hook method? #57

Description

@qibinlin

Feature Request

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.

Activity

  1. github-actions commented on Apr 22, 2024

    @github-actions

    Thank you for opening your first issue in the Canyon-SQL project!

  2. TheRustifyer commented on Apr 22, 2024

    @TheRustifyer
    Member

    Hello @qibinlin

    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.

    Let us know if this helped you.

    Cheers.

  3. locked and limited conversation to collaborators on May 8, 2024
  4. converted this issue into a discussion #63 on May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions