Select

To begin working with an entity, start with the name of the entity. Use the select method to begin a new query. This method returns a new instance of the entity class. When finished, use the execAsync method to execute the query in the database and return the records as a strongly typed version of the WireBootstrap DataTable.

The example below will return all the records and fields in the Categories table in the Northwind database.

const categoryTable = await Categories.select().execAsync();

Note, the execAsync method returns a TypeScript Promise so the await keyword can be used to execute the query asynchronously.

Fields

To select fields from an entity, use the [entity]Field enum parameters on the select method.

const categoryTable = await Categories.select(
    CategoriesField.CategoryID, 
    CategoriesField.CategoryName
)
.execAsync();

The field method can also be used to select fields.

const categoryTable = await Categories.select()
   .field(CategoriesField.CategoryID)
   .field(CategoriesField.CategoryName)
.execAsync();

Filter

To filter the records returned, use the eq method.

const categoryTable = await Categories.select()
   .eq(CategoriesField.CategoryName, "Dairy Products") 
.execAsync();

First

To return the first record in a result set, the execFirstAsync method can be used instead of the execAsync method.

const dairyProducts = await Categories.select()
   .eq(CategoriesField.CategoryName, "Dairy Products") 
.execAsyncFirst();

Note, unlike the execAsync method which returns a data table, this method returns a single Categories object.

Scaler

When selecting a single cell in a query, the execScalerAsync method can be used.

const categoryId = await Categories.select(
     CategoriesFields.CategoryID
   )
   .eq(Categories_Field.CategoryName, "Dairy Products") 
.execAsyncScaler();

Order By

To order the records in the result set, use the orderBy method.

const categoryTable = await Categories.select()
.orderBy(CategoriesField.CategoryName)
.execAsync();

Last updated