Skip to content

[Feature Request]: BeforeExecute, AfterExecute hook support #475

Open
@kcmvp

Description

@kcmvp

Firstly thank you very much to build such useful framework. I am using it in my project. I have a use case for data privilege, for the same statement different user role would take different data privilege strategies. eg:

select a, b, c from ta

if current use a normal user then the return result of column c should be maksed as "xxxx", in our project (sass, multi-tenancy), there are many cases.

if the framework supports hooks, then we can handle the logic in one place. right now we mix such logic every where. it's not a good practice.

thank you!

Activity

jeffgbutler

jeffgbutler commented on Apr 19, 2022

@jeffgbutler
Member

I'm going to add hooks to the library that will allow you to modify the generated SQL. I'm not sure that's what you are asking about however.

This library does not execute SQL - we defer that to either MyBatis or Spring. So if you need execution hooks, you will need to do it in those libraries. In MyBatis that would probably mean writing a plugin or interceptor - you can read about MyBatis plugins on this page: https://mybatis.org/mybatis-3/configuration.html

kcmvp

kcmvp commented on Apr 20, 2022

@kcmvp
Author

I'm going to add hooks to the library that will allow you to modify the generated SQL. I'm not sure that's what you are asking about however.

This library does not execute SQL - we defer that to either MyBatis or Spring. So if you need execution hooks, you will need to do it in those libraries. In MyBatis that would probably mean writing a plugin or interceptor - you can read about MyBatis plugins on this page: https://mybatis.org/mybatis-3/configuration.html

yeath, that what I wanted for BeforeHook. , back to AfterHook (my case) is to modify the result.(eg encrypt).

in order to control the BeforeHook and AfterHook precisely, there should be a context I can pass a flag/variable in it. for example If set a variable/flag in context in BeforeHook for a sql, in the following AfterHook I can tell that's the very sql I am caring about by checking(and using) the flag/variable (eg, using it to encrypt the value)

generally speaking: our use case can fall into two categories

1: simply using BeforeHook to modify the sql
2: Using BeforeHook and AfterHook together to modify the returned the result.

Thank you quick reply very much!

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

      [Feature Request]: BeforeExecute, AfterExecute hook support · Issue #475 · mybatis/mybatis-dynamic-sql