v icon indicating copy to clipboard operation
v copied to clipboard

orm: Support 'like' operator

Open cstffx opened this issue 3 years ago • 2 comments

Make possible:

admin := sql db {
    select from User where name like '%admin' limit 1
}

The SQL generated should be something like:

SELECT * FROM "User" WHERE name LIKE ....

I wish to work on it. But I need to confirm some ideas, for example, current valid operators are:

s[Kind.eq] = '=='
s[Kind.ne] = '!='
s[Kind.gt] = '>'
s[Kind.lt] = '<'
s[Kind.ge] = '>='
s[Kind.le] = '<='

Then 'like' must to be a new token kind, with his own precedence in build_precedences() right?

cstffx avatar Aug 05 '22 16:08 cstffx

I would just use like instead of coming up with some sort of symbols to represent it.

JalonSolov avatar Aug 05 '22 17:08 JalonSolov

Would it be okay to declare like as a new keyword? select, where, order, etc are not exactly keywords, they are parsed like Kind.name. But in the case of like if I declare it as a keyword, relational, and infix the work is almost done since like is a kind of operator as ==, >=, <=, etc. I finished an implementation that works. But I found that this is a valid code in my implementation:

a := "a"
b := "b"
c := a like b

Since like must be declared as a valid string operator to work inside the sql expression it is also working out of the sql block. That result in a program that crash and must not be valid. Any idea of how to solve this or any other recommendation?

cstffx avatar Aug 05 '22 21:08 cstffx

Fixed in #18020

walkingdevel avatar Apr 23 '23 11:04 walkingdevel