Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add _is_null and _is_not_null operators #1467

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zlargon
Copy link

@zlargon zlargon commented Dec 5, 2023

This PR is related to #682 and #823.

  • Add _is_null and _is_not_null operators.
  • Add test cases.
  • Update README.

example

db.todos = [
  { id: 1, completeDate: null },
  { id: 2, completeDate: null },
  { id: 3, completeDate: '2022-11-20T13:02:47.210Z' },
  { id: 4, completeDate: '2023-12-05T17:58:17.420Z' },
]

attr_is_null

// GET /todos?completeDate_is_null
[
  { id: 1, completeDate: null },
  { id: 2, completeDate: null }
]

attr_is_not_null

// GET /todos?completeDate_is_not_null
[
  { id: 3, completeDate: '2022-11-20T13:02:47.210Z' },
  { id: 4, completeDate: '2023-12-05T17:58:17.420Z' },
]

@zlargon zlargon force-pushed the support-is-null-and-is-not-null-operators branch from a2cd204 to 231853e Compare December 5, 2023 14:02
@zlargon
Copy link
Author

zlargon commented Dec 7, 2023

Hi @typicode,

I want to express my gratitude for the valuable tool that json-server is, enabling us to swiftly set up mock servers for testing purposes. Your effort in providing this as an open-source project is highly appreciated.

While working with json-server, I noticed a limitation in its current functionality related to querying null and non-null values. I believe incorporating support for such queries would be a beneficial addition. This idea has also been raised in issues #682 and #823.

I observed attempts by others to implement this as a custom filter, but unfortunately, it didn't yield the desired results. Consequently, I took the initiative to contribute a feature that allows querying null values.

Initially, I envisioned designing the single is_null operator as follows:

URL description
GET /todos?completeDate_is_null return null values (default is true)
GET /todos?completeDate_is_null=true return null values
GET /todos?completeDate_is_null=false return non-null values

However, during the implementation, it seems that this design required some code refactoring. Consequently, I opted for a solution involving separate is_null and is_not_null operators. I would greatly appreciate any advice or guidance you could provide on this approach.

Thank you for your time and consideration.

Best,
Leon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant