Hint
This article is generated by AI translation.
Rule-Based Arguments
Use @{...} with the Rule mechanism to elegantly handle common dynamic command scenarios.
Only add name when it is not empty
select * from users where id > :id @{and, name = :name}
AND Rule
AND rule
select * from users where id > :id @{and, name = :name}
- When the named argument
nameis not null/empty,and name = ?is appended to the WHERE clause. - Final SQL:
nameempty:select * from users where id > ?namepresent:select * from users where id > ? and name = ?
OR Rule
OR rule
select * from users where id > :id @{or, name = :name}
- When
nameis not null/empty,or name = ?is appended to the WHERE clause. - Final SQL:
nameempty:select * from users where id > ?namepresent:select * from users where id > ? or name = ?
SET Rule
SET rule
update users set modify_time = ? @{set, status = :status} where id > :id
- When
statusis not null/empty,status = ?is appended to the SET clause. - Final SQL:
statusempty:update users set modify_time = ? where id > ?statuspresent:update users set modify_time = ?, status = ? where id > ?
IN Rule
IN rule
select * from users where status = true @{in,and id in :ids}
- If
idshas 3 elements, the IN rule appendsand id in (?, ?, ?); the number of placeholders matches the element count. - Final SQL:
idsempty:select * from users where status = trueidspresent:select * from users where status = true and id in (?, ?, ?)
About rules
- dbVisitor ships with many built-in rules for different needs.
- For details, see here.