The .from() function should always be the first function after calling the jingJs constructor.
Working With Collections
The .from() can handle 1 to many arguments. Each argument can be a mix of collections of JSON objects and/or url's to web services that return JSON responses. If there is more than one argument then each collection or JSON response object from a web service will have a UNION ALL effect. To perform a UNION see the .union() function. If the .on() is immediately followed then the arguments will be inner joined.
from(array | string, array | string , array | string, ...)
type FromCollection<T> = string | any[] | T[];
from<T>(collection: FromCollection<T>, ...collections: FromCollection<T>[]): jinqJs;
The following examples use the .select(), top() and are explained further down the document of its usage.
Simple query using from()
Simple query performing a union on two collections
Working With A JSON REST Service
The string parameter is the url to a web service that returns a collection of JSON objects.
If the second parameter is omitted then the call will be a synchronously made call. If a function is provided then an asynchronously call is made and the callback function(instance) is raised when a return is received from the web service. If an asynchronous call is made then the .from() is last in the chain of functions and the chain then continues inside the callback function.
Synchronously/Asynchronous Calls
Note: Web service calls will be made synchronously. (See sample below for asynchronous option)
.from(string, function(instance):optional )
from(url: string, callback?: (self: jinqJs) => void): void;
var result = new jinqJs() //Syncronous call made here
.from('http://www.telize.com/geoip')
.top(1)
.select('city', 'region');
/* result: [{city:'New York', region:'North East'}] */
var result = null;
new jinqJs() //Asyncronous call made here
.from('http://www.telize.com/geoip',
function(self) {
result = self
.top(1)
.select('city', 'region');
}
);
/* result: [{city:'New York', region:'North East'}] */