MySQL Functions


#1

I have the code below:

await database.select('*')
        .from('payments')
        .where('payments.agent', '=', agent_uid)
        .where('MONTH(due_date)', '=', month)

The MONTH function is a standard function of MySQL, but when I use in where clause, the sql script generated include ``, look.
Script generated:

where `payments`.`agent` = 1 and `MONTH(due_date)` = \'3\'

Script I wish:

where `payments`.`agent` = 1 and MONTH(`due_date`) = \'3\'

How can I do this?


#2

I found it.
I can use database.raw to write scripts directly, so the line code will be like this:

.where(database.raw('MONTH(payments.due_date)'), '=', month)

#3

Nice!

The .where() function just accept the model/table as first parameter.

You can mark the problem as solved?