Postgres, MySQL, and SQLite all support string concatenation via CONCAT/CONCAT_WS functions, and Postgres and SQLite additionally support it via the || operator. We currently don't handle either form, and both + and || silently produce broken SQL statements.
Example:
#[model]
#[derive(Debug, Clone)]
pub struct Product {
#[model(primary_key)]
id: Auto<i64>,
#[model(unique)]
title: LimitedString<64>,
name: LimitedString<255>,
}
...
query!(Product, ($name + $title) == "mortal kombat").all(&db)
Currently produces
SELECT "id", "title", "name", FROM "foo__product" WHERE "name" + "title" = "mortal kombat"
which is meaningless for text columns.
Trying || instead:
query!(Product, ($name || $title) == "mortal kombat").all(&db)
Also produces:
SELECT "id", "title", "name" FROM "foo__product" WHERE "name" OR "title" = "mortal kombat"
because || is being parsed as logical OR, not SQL string concatenation.
Ideally, we want this to yield a cot::db::query::Expr::Concat expression:
Usage in the query! macro, and for the + operator specifically, we'd like it to dispatch to Expr::Concat when operating on string-typed fields(whenever possible), while continuing to produce Expr::Add for numeric fields
One caveat: this can get tricky for concat chains like below:
query!(Product, ($name + "-" + $title) == "mortal - kombat" )
Postgres, MySQL, and SQLite all support string concatenation via
CONCAT/CONCAT_WSfunctions, and Postgres and SQLite additionally support it via the||operator. We currently don't handle either form, and both+and||silently produce broken SQL statements.Example:
Currently produces
which is meaningless for text columns.
Trying
||instead:Also produces:
because
||is being parsed as logicalOR, not SQL string concatenation.Ideally, we want this to yield a
cot::db::query::Expr::Concatexpression:Usage in the
query!macro, and for the+operator specifically, we'd like it to dispatch toExpr::Concatwhen operating on string-typed fields(whenever possible), while continuing to produceExpr::Addfor numeric fieldsOne caveat: this can get tricky for concat chains like below: