Code Monkey home page Code Monkey logo

Comments (10)

glebm avatar glebm commented on May 24, 2024 2

All done! Released in v0.4.0!

from order_query.

glebm avatar glebm commented on May 24, 2024

What database are you using? NULL LAST is the default for DESC in MySQL.
This gem doesn't deal with nulls well yet, I'll need to see what it does currently and how it can be improved.

from order_query.

glebm avatar glebm commented on May 24, 2024

As a quick hack for now while we figure out a proper solution, you could do this:

order_query :my_order, 
   [:posted_at_or_zero, :desc, sql: "COALESCE(posted_at, '0000-00-00 00:00:00')"]

def posted_at_or_zero
  posted_at || DateTime.new(0)
end

from order_query.

gauda avatar gauda commented on May 24, 2024

Looks good! That's postgresql so I had to change order_query to COALESCE(posted_at, '#{Time.utc(1900).to_s(:db)}') and posted_at_or_zero to posted_at || Time.utc(1900) since postgresql does not allow zeros as date.

That's good enough for my application. Nevertheless it would be nice if you could do something like: order_query :my_order, ['posted_at %order% NULLS LAST', :desc] and order_query would replace %order% by DESC or ASC. This way all future problems, where the name of a field to order by is not enough, would be solved.

Thank you for your time and your hints how to solve this problem!

from order_query.

bdtomlin avatar bdtomlin commented on May 24, 2024

@glebm I see that you did some work on this but it's well over a year old. I'm just curious what the status is and what your plans are for this feature.

from order_query.

glebm avatar glebm commented on May 24, 2024

This feature seems to work in the nulls-order branch, but:

  1. Tests are needed.
  2. Branch needs rebasing.
  3. Documentation needs to be updated.

I don't plan to do that myself, but if someone does all of the above and sends a PR I'll review it.

from order_query.

bdtomlin avatar bdtomlin commented on May 24, 2024

Thanks for the reply. I looked at it and rebased from master with no issues. All the tests ran afterwards but the nulls feature still needs a some work and is not currently working.

Nulls can be especially tricky since many times you want to keep them in the result set but still have them sorted.

As I looked more into it I realized I would be better off implementing keyset queries in my own app. I think this will be the case for most people who need queries that this gem doesn't handle.

from order_query.

glebm avatar glebm commented on May 24, 2024

Status update: Added more tests to the branch and got some of them to pass.

from order_query.

glebm avatar glebm commented on May 24, 2024

Status update: The nulls-order branch now passes all the tests. Still needs testing with all the databases to be safe to merge (#15)

from order_query.

glebm avatar glebm commented on May 24, 2024

Status update: PR merged, tests failing on Postgres, still not 100% coverage.

from order_query.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.