Comments (5)
We could also have an explicit value format: { cast: 'guid', value: '312312-3123-12-3123-123' }
, see #18
from odata-query.
Starting in 5.4.0
you can now pass the value as an object { type: 'guid', value: '312312-3123-12-3123-123' }
. We currently support type
as guid
and raw
(raw is provided if you want to perform all the formatting externally and not have the value quoted/escaped/etc (like a string normally would be)).
I would still like to support most of the types listed above (ex. datetime'....'
) before closing the issue, but they should be pretty trivial to implement now. OData/WebApi does not support these from my testing (and is predominately what I use although I'm investigating https://github.com/voronov-maxim/OdataToEntity)
from odata-query.
I've been debating myself how to handle specifying the types within odata-query. So far I've been considering 2 approaches:
- Have the formatting occur ahead of time by exposing a named function (or functions), such as:
import buildQuery, { format } from 'odata-query';
const query = { SomeProp: format(value, 'decimal') }
buildQuery({ filter })
I like this approach but it might be difficult to detect when passing in a "pre-typed" value as a string (ex. datetime'2017-01-01T00:00:00'
) and when just passing in a simple string value (ex. test
) as not all types follow the type'value'
format (ex. decimal is 12.345M
). When passing in a simple string value, we need to format it by wrapping it in single quotes '
but if we pass in the string 12.345M
we would not want to add the wrapping quotes.
- Pass in some structure as part of the query and have the formatting occur during query build time. For example:
import buildQuery from 'odata-query';
const query = { SomeProp: { decimal: value }}
buildQuery({ filter })
I'm not sure what the structure of this object should be, and I'm not overly keen on the key being the name of the formatter (although this somewhat aligns with the equality operators and boolean string functions). We would need a known list of formatters ahead of time, which would break supporting custom types (although I've not used them myself). It also seems like this approach adds more "magic" to the query format of odata-query.
For reference, here is the list of types we need to support (there might be more):
- guid
- datetime
- datetimeoffset
- byte
- single
- double
- decimal
- boolean
- int32
- custom types
from odata-query.
How is it supposed to work with the in
-Operator? Am I right that currently only eq
-Operator is supported?
The current implementation works with the foo
and foobar
filter, but not the bar
filter
buildQuery({
foo: {
eq: {
type: 'guid',
value: 'value'
}
},
bar: { in: {
type: 'guid',
value: ['bar1', 'bar2']
}
},
foobar: { in: [{
type: 'guid',
value: 'foobar'
}, {
type: 'guid',
value: 'barfoo'
}]
}
})
I implemented a solution for the in-operator (Commit). I don't know how you want to handle this case.
from odata-query.
@samuelportz all comparison operators except in
should be supported, as in
is a special convenience operator to explode into an or
statement.
Your referenced fix looks good to me and would merge it in if you would send a PR.
from odata-query.
Related Issues (20)
- Double filters in querystring HOT 3
- Automatically Title-Case Camel-Cased props HOT 1
- Filter with Any clause bad conversion
- ESM default export is not properly defined
- Add $skip support to $expand ExpandOptions
- TS error on $select when $orderBy added HOT 1
- not requires a whitespace
- [Question] Is the project maintained? HOT 4
- Select within an expand on an optional property not compatible with keyof
- Support compute query option HOT 7
- Support for an equality filter comparing two properties
- option to add custom query params HOT 1
- New Version Published? HOT 1
- adding whitespace after contains
- Parse query-string back into queryOptions-object HOT 2
- Add raw's description in documentation HOT 1
- Support for custom operator HOT 1
- Handling Typed Property Name Filter
- Issue with not operator inside collection filter
- $apply GroupBy Transform not capable of producing the query needed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from odata-query.