Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BEP 51: 参数构建器 可为字段 自定义 SQL 条件 #51

Closed
troyzhxu opened this issue Jun 14, 2022 · 1 comment
Closed

BEP 51: 参数构建器 可为字段 自定义 SQL 条件 #51

troyzhxu opened this issue Jun 14, 2022 · 1 comment
Labels
developing 开发中

Comments

@troyzhxu
Copy link
Owner

troyzhxu commented Jun 14, 2022

目的(BeanSearcher Enhancement Proposal)

  • 让使用者可以在 Java 代码里更灵活的定义条件

使用效果

Map<String, Object> params = MapUtils.builder()
    // 接收一个 SQL 片段作为参数值,$ 表示当前字段
    .field(User::getId).sql("$1 in (select id from xxx)")
    .build();
List<User> users = beanSearcher.searchList(User.class, params);

// select * from user u where u.id in (select id from xxx)
Map<String, Object> params = MapUtils.builder()
    // 接收一个 SQL 片段作为参数值,$ 表示当前字段
    .field(User::getId).sql("exsits (select 1 from xxx where user_id = $1)")
    .build();
List<User> users = beanSearcher.searchList(User.class, params);

// select * from user u where exsits (select 1 from xxx where user_id = u.id)

同时操作多个字段:

Map<String, Object> params = MapUtils.builder()
    // 接收一个 SQL 片段作为参数值,$ 表示当前字段
    .field(User::getId, User::getName).sql("$1 in (10, 11) or $2 like '张%'")
    .build();
List<User> users = beanSearcher.searchList(User.class, params);

// select * from user u where u.id in (10, 11) or u.name like '张%'

欢迎讨论

你是否有更好的语法,说说你的理由吧 ^_^

@troyzhxu troyzhxu changed the title v3.8 新增 SqlCond 运算符,可自定义 SQL 条件 BEP: 新增 SqlCond 运算符,可自定义 SQL 条件 Jun 17, 2022
@troyzhxu troyzhxu changed the title BEP: 新增 SqlCond 运算符,可自定义 SQL 条件 BEP: 参数构建器 可为字段 自定义 SQL 条件 Jun 17, 2022
@troyzhxu troyzhxu changed the title BEP: 参数构建器 可为字段 自定义 SQL 条件 BEP 51: 参数构建器 可为字段 自定义 SQL 条件 Jun 17, 2022
@troyzhxu troyzhxu added the developing 开发中 label Jun 27, 2022
@troyzhxu
Copy link
Owner Author

troyzhxu commented Jul 3, 2022

已在 v3.8.0 中实现:https://github.com/ejlchina/bean-searcher/releases/tag/v3.8.0

@troyzhxu troyzhxu closed this as completed Jul 3, 2022
@troyzhxu troyzhxu removed the feature label Jul 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developing 开发中
Projects
None yet
Development

No branches or pull requests

1 participant