1

I am wanting to move the ORDER BY part of my AdonisJs query into a column as a number so that when it's stored on the client-side in a Vuex store I have a "Ranking" for ordering.

    let posts = Post.query().where('processed', 1)

    posts = posts
      .preload('postTags')
      .preload('reactions')
      .preload('tiers')
      .preload('files')
      .withCount('reactions')
      .forPage(1, 40)

    const hotPosts = await posts.orderByRaw(
      'LOG10(reactions_count + 1) + (UNIX_TIMESTAMP(created_at) / 30000) DESC'
    )

    const trendingPosts = await posts.orderByRaw(
      'LOG10(reactions_count + 1) + (UNIX_TIMESTAMP(created_at) / 300000) DESC'
    )

I have scoured the documentation and any solution I attempt does not seem to work with the ORM side of the code and requires me to re-write with raw Database queries which I would like to avoid.

Michael Smith
  • 625
  • 1
  • 8
  • 19

0 Answers0