WireBootstrap
HomeDocsBuySupport
  • Introduction
  • Overview
  • Getting Started
  • Installation
  • Connecting to Data
    • Data Connectors
      • SQL Data
      • Custom Web Services
      • Local Data
      • Other Sources
    • Data Sources
    • Discovery
    • Building a Data Connector
  • Working With Queries
    • Select Queries
      • Query Extensions
    • Stored Procedures
    • Custom Web Services
    • Executing Queries
    • ORM
  • Writing Data
  • Updates
  • Deletes
  • Working with DataTables
    • Introduction
    • Filter and Sort
    • Select and Calculate
    • Joins
    • Rows
    • Columns
  • Working with DataSets
  • Introduction
  • Executing Queries
  • Transforms
  • Writing Data
  • Data Events
  • Working with Components
    • Introduction
    • Encapsulation
    • Configuration
      • Data
      • Events
      • Observables
      • Validation
      • Display
      • Vendor
      • Custom
    • Component
    • Web Frameworks
    • Building a Component
      • Hello World
      • Data Events
      • DataSets
  • Working With Data Events
    • Introduction
    • Event Basics
    • Event Data
    • Event Actions
  • Working with Themes
    • Introduction
    • Sample Data
    • Libraries
    • Pages
    • Building a Theme Project
  • Utilities
    • Formatting
    • Expressions
    • Collections
    • Spinners
    • Copy and Merge
    • Validation
    • Loading Assets
    • Service Calls
    • Download Files
    • Browser Location
    • Types
    • Promise
  • Reference
    • wire
      • wire.Collection
      • wire.download
      • wire.validate
    • wire.data
      • wire.data.DataEvent
      • wire.data.DataModel
      • wire.data.DataPromise
      • wire.data.DataSet
      • wire.data.DataSource
      • wire.data.DataTable
        • Columns
        • Rows
      • wire.data.StoredProcedure
      • wire.data.TableQuery
    • wire.ui
      • wire.ui.Component
      • wire.ui.validate
Powered by GitBook
On this page
  • ExecAsync
  • Short-Hand
  • TypeScript
  • DataTables
  • Exec

Was this helpful?

  1. Working With Queries

Executing Queries

PreviousCustom Web ServicesNextORM

Last updated 1 year ago

Was this helpful?

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

ExecAsync

The data source execAsync method returns a . Use this asynchronous method to execute the query in the data service.

const accountService = new wire.data.DataSource("custom", {
    ServiceRoot: "./account"
});

const query = wire.data.select()
    .from("Users")
    .where().eq("Active", true);
    
const users = await accountService.execAsync(query);

Short-Hand

Queries can also be executed directly from both a and object using the execAsync method which takes the data source as a parameter.

...
const users = await wire.data.select()
    .from("Users")
    .where().eq("Active", true)
    .execAsync(accountService);

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.

const accountService = new wire.data.DataSource("custom", {
    ServiceRoot: "./account"
});

const query = wire.data.select()
    .from("Users")
    .where().eq("Active", true);
    
const users = await accountService.execAsync(query) as undefined as Array<User>;

DataTables

const users = await accountService.execAsync(query) as undefined as Array<User>

const userTable = new wire.data.DataTable(users);
const accountService = new wire.data.DataSource("sql", {
    ServiceRoot: "./account"
});

const query = wire.data.select()
    .from("Users")
    .where().eq("Active", true);
    
const userTable = await accountService.execAsync(query) as undefined as IWireDataTable

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.

...
    
const userData = await accountService.execAsync(query);

const userTable: IWireDataTable = accountService.getResponseTable(userData);

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.

...
const users = accountService.exec(query);

The format of asynchronous results depends on how the data connector returns the data. In the example above, the results are returned as an array of plain JavaScript objects containing the user data.

An instance of can also be created from the array in order to work with the data locally.

In the example below, the service provider returns a data table automatically.

For details on these data source methods, visit the reference page. For details on data tables, visit the reference page.

DataSource
deferred jQuery promise
TableQuery
StoredProcedure
Custom Data Connector
WireBootstrap's DataTable
Query Service
DataSource
DataTable