Knex throws an error if no rows are returned for a query

问题内容:

I run a knex query:

knexClient.knex.queryBuilder()
    .from(`mytable`)
    .where({params: ... })
    .orderBy('myfield')
    .then((rows) => {
        // if rows.length>0, all is good, otherwise an error is thrown
    });

If it has no rows in the response, I see an error like this:

Unhandled rejection TypeError: Cannot read property ‘myfield’ of undefined

How do I handle this case properly?

问题评论:

原文地址:

https://stackoverflow.com/questions/47756447/knex-throws-an-error-if-no-rows-are-returned-for-a-query

Add a Comment