Code Monkey home page Code Monkey logo

Comments (6)

twelve17 avatar twelve17 commented on May 28, 2024

Thanks for looking into this @glebm , and let me know if I can assist.

from order_query.

glebm avatar glebm commented on May 28, 2024

After adding a test for multiple nulls, I can see that the query it generates without wrap_top_level_or has an incorrect OR clause:

  SELECT "posts".* FROM "posts"
   WHERE ("posts"."published_at" IS NULL OR -- <- *this is wrong*
          "posts"."published_at" IS NULL AND "posts"."id" < 47)
ORDER BY "posts"."published_at" IS NULL ASC,
         "posts"."published_at" ASC,
         "posts"."id" DESC LIMIT 1

from order_query.

glebm avatar glebm commented on May 28, 2024

@twelve17 Got a fix here: #22

If it works for you, I'll release a new version.

You can try it out with:

gem 'order_query', git: 'https://github.com/glebm/order_query', branch: 'null-wtlo'

There should be no need to set wrap_top_level_or = false in that branch (it wasn't a sufficient workaround anyway).

from order_query.

twelve17 avatar twelve17 commented on May 28, 2024

Hi @glebm , things seem to work with the updated code. 🎉

I did not use wrap_top_level_or = false for this test (I omitted the setting altogether).

For posterity, here its the resulting query:

seek_args: [[:title, :desc, {:nulls=|:first}]]
Entry Load (1.0ms)  SELECT  `entries`.* FROM `entries` ORDER BY `entries`.`title` IS NULL DESC, `entries`.`title` DESC, `entries`.`id` ASC LIMIT 20
Entry Load (0.7ms)  SELECT  `entries`.* FROM `entries` WHERE `entries`.`id` = 1 LIMIT 1
Entry Load (0.7ms)  SELECT  `entries`.* FROM `entries` WHERE (`entries`.`title` IS NULL AND `entries`.`id` | 1) ORDER BY `entries`.`title` IS NULL ASC, `entries`.`title` ASC, `entries`.`id` DESC LIMIT 1

Thanks for your help with this!

from order_query.

twelve17 avatar twelve17 commented on May 28, 2024

BTW, please feel free to close the other issue, it's obviously less pressing given this is working. Thanks again.

from order_query.

glebm avatar glebm commented on May 28, 2024

Fix released in v0.4.1

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.