Filter support passing context (#2200) #2270

Merged
lunny merged 1 commits from LinkinStars/xorm:feat_filter_context into master 2023-05-31 01:43:28 +00:00
Contributor
// Filter is an interface to filter SQL
type Filter interface {
---	Do(sql string) string
+++	Do(ctx context.Context, sql string) string
}

Adds a Context parameter to the Do method of the Filter interface.

Developers can rewrite SQL through the Filter Do method and need to get the necessary data from the Context to assist.

For example, get user information through Context, so that different users can use different tables. Another example is to get the flags through Context to add annotations to the SQL, and use the annotations to let the subsequent DB-Proxy to achieve read/write separation.

```diff // Filter is an interface to filter SQL type Filter interface { --- Do(sql string) string +++ Do(ctx context.Context, sql string) string } ``` ### Adds a `Context` parameter to the `Do` method of the Filter interface. Developers can rewrite SQL through the `Filter` `Do` method and **need to get the necessary data from the Context** to assist. For example, get user information through `Context`, so that different users can use different tables. Another example is to get the flags through `Context` to add annotations to the SQL, and use the annotations to let the subsequent `DB-Proxy` to achieve read/write separation.
LinkinStars added 1 commit 2023-05-30 10:14:37 +00:00
Filter support passing context (#2200)
All checks were successful
test mariadb / test mariadb (pull_request) Successful in 7m21s
test mssql / test mssql (pull_request) Successful in 8m43s
test mysql / test mysql (pull_request) Successful in 5m46s
test mysql8 / test mysql8 (pull_request) Successful in 5m42s
test postgres / test postgres (pull_request) Successful in 6m25s
test sqlite / unit test & test sqlite (pull_request) Successful in 10m2s
test tidb / test tidb (pull_request) Successful in 5m47s
test cockroach / test cockroach (pull_request) Successful in 6m55s
d00e239c3c
lunny approved these changes 2023-05-30 13:41:09 +00:00
lunny merged commit cb851a2f95 into master 2023-05-31 01:43:28 +00:00
Sign in to join this conversation.
No description provided.