Soontao/light-odata

Support for null query

ErnieBernie10 opened this issue · 6 comments

I want to use a filter that would generate a query like: $filter=Name eq null but this is not currently possible. Passing null to the eq function is not possible and passing null as a string puts it between quotes like 'null'

Is there any way around this and if not can this feature be added?

Let me check about this

Hello @ErnieBernie10

Sorry for the late reply, I've released a new version 2.13.0 to support create filter with null

const filter = OData.newFilter().field("Name").eq(null)

if you can not upgrade the version of @odata/client, you can easily create a param with free text

const param = OData.newParam().filter("Name eq null")

Thanks

I actually updated the package and there's still no support for null When looking at the code in the repo I also see the type of the eq param does not accept null. Not sure if I'm just missing something or what.

Hello @ErnieBernie10,

Could you provide more information about your project, with some code snippet or error statck?

Here are the unit tests about eq null, you can ref these

it('should support filter.eq(null)', () => {
expect(OData.newFilter().field("Name").eq(null).build()).toEqual("Name eq null")
expect(OData.newFilter().property("Name").eq(null).build()).toEqual("Name eq null")
});

test('Read By Filter null', async () => {
const odata = OData.New({ metadataUri: TestServiceURL })
const filter = OData.newFilter().field("Phone").eq(null);
const result = await odata.newRequest({
collection: "Customers",
params: OData.newParam().filter(filter)
})
expect(result.d.results).toHaveLength(0)
})

Thanks :)

I'm talking about the parameter type definition of eq here:

light-odata/src/filter.ts

Lines 127 to 130 in 3822266

eq(value: number | string | ODataDataObject): ODataFilter {
this._addExpr(ExprOperator.eq, value);
return this._filter;
}

It does not accept null. Perhaps it would work when using plain js but the typescript compiler complains

Hi @ErnieBernie10 ,

I guess you are using strictNullChecks in your ts config, you can simplely disable it in compileOptions, or, try the new version 2.14.0, I've added the null to the method declaration.

Thanks, have a nice day :)