Executing Queries
Use a DataSource object to execute queries in a data service and retrieve the results.

ExecAsync

The data source execAsync method returns a deferred jQuery promise. Use this asynchronous method to execute the query in the data service.
1
const accountService = new wire.data.DataSource("custom", {
2
ServiceRoot: "./account"
3
});
4
5
const query = wire.data.select()
6
.from("Users")
7
.where().eq("Active", true);
8
9
const users = await accountService.execAsync(query);
Copied!

Short-Cut

Queries can also be executed directly from both a TableQuery and StoredProcedure object using the execAsync method which takes the data source as a parameter.
1
...
2
const users = await wire.data.select()
3
.from("Users")
4
.where().eq("Active", true)
5
.execAsync(accountService);
Copied!

TypeScript

TypeScript requires a method to return a specific type. To cast the response from the execAsync method to a type use the as undefined pattern.
In the example below, the results can be cast directly into an array of User class objects by first casting them as undefined.
1
const accountService = new wire.data.DataSource("custom", {
2
ServiceRoot: "./account"
3
});
4
5
const query = wire.data.select()
6
.from("Users")
7
.where().eq("Active", true);
8
9
const users = await accountService.execAsync(query) as undefined as Array<User>;
Copied!

DataTables

The format of asynchronous results depends on how the service provider returns the data. In the example above, the Custom Service Provider results are returned as an array of plain JavaScript objects containing the user data.
An instance of WireBootstrap's DataTable can also be created from the array in order to work with the data locally.
1
const users = await accountService.execAsync(query) as undefined as Array<User>
2
3
const userTable = new wire.data.DataTable(users);
Copied!
In the example below, the Query Service service provider returns a data table automatically.
1
const accountService = new wire.data.DataSource("sql", {
2
ServiceRoot: "./account"
3
});
4
5
const query = wire.data.select()
6
.from("Users")
7
.where().eq("Active", true);
8
9
const userTable = await accountService.execAsync(query) as undefined as IWireDataTable
Copied!
Sometimes the format of the data returned from the data service call is unknown. The getResponseTable method on the data source can be used to transform the response data into a data table. Here, the data source will reach into the service provider for this transform as it knows the native format of the result set.
1
...
2
3
const userData = await accountService.execAsync(query);
4
5
const userTable: IWireDataTable = accountService.getResponseTable(userData);
Copied!

Exec

The exec method is the synchronous equivalent of execAsync. This method will pause the thread and wait for the results to come back from the data service call.
1
...
2
const users = accountService.exec(query);
Copied!
For details on these data source methods, visit the DataSource reference page. For details on data tables, visit the DataTable reference page.