Skip to content

Using NOW() in custom where? #56

Open
@mswdev

Description

@mswdev

I need to select data where ``last_update >= now() - INTERVAL 1 MINUTE

Example of what I'm currently trying to use:

qb.select('*').where('last_update >= NOW() - INTERVAL 1 MINUTE', null, false).get('account', (err, rows) => {
            qb.release();
            if (err) throw err;
            return res.json(rows)
        })

EDIT: It looks like the issue seems to be occurring due to it placing NOW() inside single quotes when executing the query causing mysql to treat it as a field rather than a function. Any idea how to get around this?

EDIT 2: I realized you can pass false for escape strings which is what I want for executing the NOW() function, but for some reason, it keeps appending the AS keyword after the function? Any idea why this is?

I'm using the query above, but it seems to return this with the AS keyword which is clearly not right?:

ComQueryPacket {
  command: 3,
  sql:
   'SELECT * FROM `account` WHERE last_update >= NOW() AS `- INTERVAL 1 MINUTE`' }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions