PreparedQueryOptions
A simple set of JS classes to help build and parse OData queries
New in 1.2.2
- Case insensitive matching on 'and' and 'or'
- Added Predicate.GROUP_OPERATOR.AND and .OR for convenience
Fix in 1.2.1
- Filter contains uses correct syntax: contains(property, value)
Breaking Changes in 1.2.0
- Renamed "parseOptions" and "parsePredicate" to "toString"
- Renamed "parser" property on predicate to "getValue"
New in 1.2.0
- Fixed predicate test to check do a string insensitive match for startswith, endswith and contains
New in 1.1.x
- Get and Clear values stored in PreparedQueryOptions. Passing no value returns the current value. Passing null clears the current value.
options; // Return the current $top valueoptions; // Clears the current $top value
- Predicate.fromString(filterString): create a predicate from a filter query string.
- Evaluate an object to see if it matches a predicates filter conditions
var testObject = age: 25 ;var predicate = 'age';predicate; // Returns true.
- predicate.startsWith(value): parses as "startswith(property, 'value')"
- predicate.endsWith(value): parses as "endswith(property, 'value')"
- predicate.contains(value): parses as "contains(property, 'value')"
Breaking Changes in 1.1.0
The predicate class has been significantly updated for better management of the predicate structure. You can now create a predicate object from a filter string in the URL. On the client side, this means you can take an existing PreparedQueryOptions object and modify/extend the filter string that is stored. On the server side, you now have the ability to take an incoming query string and parse a predicate from it making it easier to parse into SQL or into an ORM for querying the database.
Furthermore, the Predicate class now supports the OData standard startswith, endswith and contains methods. These are accessed via the startsWith(), endsWith() and contains() methods respectivly.
To accomodate these changes, there is one breaking change:
The signature of the constructor for a Predicate has changed and no longer takes the operator or value. It instead just takes the property (and a parser method that is used internally for cloning a predicate). To set the operator and value, you should now use the methods on the Predicate to set the operator and value (equals(), notEqualTo(), greaterThan()...).
'age' 'gt' 21;
Should now be:
'age';
PreparedQueryOptions.js
PreparedQueryOptions are used to set, store and parse OData query parameters. Instead of passing multiple arguments to methods for each query option, simply pass the preparedQueryOptions object. Use the parseOptions method on the object to return an OData string for a query.
Get Started
-
Include preparedQueryOptions.js in your index.html file or if using RequireJS, just require the file as a dependency.
-
Create a new preparedQueryOptions object
var options = ;
- Set new options
options;// Parsed result looks like "?$top=10"
- Chain any number of options
var options = ;options;
- Parse the options into a query string
var options = ;var urlParameters = options;// Parsed result looks like "?$top=10&$orderby=name asc"
- Get and clear the current values
var options = ;options; // Returns 10options; // Clears the top value
Predicate.js
Predicates are used to define complex filter clauses for use in an OData query string.
Get Started
-
Include predicate.js in your index.html file or if using RequireJS, just require the file as a dependency.
-
Create a new predicate object passing the property and using chained operation methods
var predicate = 'age';
- Join existing predicates with an 'and' separator
var pred1 = 'age';var pred2 = 'age';pred1;// Parsed result looks like "age gt 21 and age lt 50"
- Optionally use the Predicate class to join an array of predicates
var pred1 = 'age';var pred2 = 'age';var joinedPredicate = Predicate;
- Parse the predicate into a query string
var predicate = 'age';var urlString = predicate;// urlString result looks like "age gt 21"