I am using bookshelf.js to develop a project using mariaDB. I want to get my post items ordered randomly. I found this solution works for knex.js
knex('posts').select('id', 'text')
            .orderByRaw('RAND()')
            .limit(100)
But I want to do the same thing with Bookshelf.
According to bookshelf.js documentation, model.query() returns the underlying knex query builder which you can apply your knex solutions to.
Post.query(function (qb) {
            qb.select('id',  'text');
            qb.orderByRaw('RAND()')
            qb.limit(2);
        }).fetchAll()
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With