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

OperatorMap type doesn't include $exists #3295

Closed
snigdha920 opened this issue Jul 11, 2022 · 4 comments
Closed

OperatorMap type doesn't include $exists #3295

snigdha920 opened this issue Jul 11, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@snigdha920
Copy link
Contributor

snigdha920 commented Jul 11, 2022

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

I have a deletedAt field in my entities. I'm trying to fetch the entities where the deletedAt field does not exist.

Here's what my query looks like:

await this.myRepository.findOneOrFail({deletedAt: {$exists: false}})

After MikroORM v5, I can't use this anymore.

It would be nice to have $exists option. Since it would check for both undefined and null at the same time. Also, there might be several other projects using $exists option, which will break. Having the $exists option will make v5 more backwards compatible with v4.

Describe the solution you'd like
A clear and concise description of what you want to happen.

Update the types of OperatorMap<T> to include $exists as well.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

await this.myRepository.findOneOrFail({deletedAt: undefined})

I find this a little wobbly, because it won't match deletedAt being set to null.

Additional context
Add any other context about the feature request here.

I'd be happy to open a PR if you think this is worth adding.

@snigdha920 snigdha920 added the enhancement New feature or request label Jul 11, 2022
@B4nan
Copy link
Member

B4nan commented Jul 11, 2022

It was never there. In v4 it was just not strictly type checked.

After MikroORM v5, I can't use this anymore.

This is a TS error, you can just cast as any to get around it.

I dont mind adding it there, as long as we will have meaningful error handling for SQL drivers where this wont work (or maybe we should just contert that for SQL drivers to SQL alternative, maybe to foo is not null?)

@snigdha920
Copy link
Contributor Author

It was never there. In v4 it was just not strictly type checked.

Right, that makes sense. My team tries to avoid any type as much as possible, so I'm going with the undefined approach.

I dont mind adding it there, as long as we will have meaningful error handling for SQL drivers where this wont work (or maybe we should just contert that for SQL drivers to SQL alternative, maybe to foo is not null?)

If I understood correctly, you are suggesting offering an equivalent $exists for SQL drivers instead of an error? I like that idea.

foo is not null

Matching MongoDB's exists, we can return all fields which are not equal to undefined.

@B4nan
Copy link
Member

B4nan commented Jul 11, 2022

Matching MongoDB's exists, we can return all fields which are not equal to undefined.

In SQL there is no undefined value, the value of nullable column is always null even if you did not provide it. That's why I said foo is not null could be good enough equivalent for that.

@snigdha920
Copy link
Contributor Author

Oh, I did not know that. In that case, what you said is perfect. Should I provide a PR for the same?

@B4nan B4nan closed this as completed in 112f2be Jul 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants