v
v copied to clipboard
orm: Support 'like' operator
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?
I would just use like instead of coming up with some sort of symbols to represent it.
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?
Fixed in #18020