Skip to main content
Back to contributions
Pull Request
In Review
1.7K

Add like_expr/not_like_expr methods accepting Into<Expr>

SeaQL/sea-query

Added like_expr(), not_like_expr(), ilike_expr(), and not_ilike_expr() methods that accept arbitrary expressions as LIKE patterns, enabling column references, function calls, and concatenation in LIKE clauses

The Problem

SeaQuery’s like() and not_like() methods only accept string patterns via LikeExpr. This meant users couldn’t use column references, function calls, concatenation, or other SQL expressions as LIKE patterns — a common need when building dynamic queries like WHERE column LIKE other_column || '%'.

This limitation was tracked in issue #464.

The Solution

Added new _expr variants to the LIKE family of methods:

  • like_expr() and not_like_expr() on ExprTrait for all backends
  • ilike_expr() and not_ilike_expr() on PgExpr for Postgres case-insensitive matching

All new methods accept Into<Expr>, enabling arbitrary expressions as LIKE patterns:

// Column reference as LIKE pattern
Expr::col(Character::Character).like_expr(Expr::col(Character::FontId))

// Function call as pattern
Expr::col(Character::Character).like_expr(Func::lower(Expr::col(Character::FontId)))

// Concatenation as pattern
Expr::col(Character::Character).like_expr(
    Expr::col(Character::FontId).concat("%")
)

The implementation follows the same self.binary(Op, right) pattern used by existing comparison operators (eq(), gt(), etc.). No breaking changes — existing like()/not_like() methods remain unchanged.

Tests cover all three backends (MySQL, Postgres, SQLite) with column references, function expressions, string literals, and concatenation patterns.

Timeline

DateAction
2026-03-23PR submitted with implementation and tests