Tables and Views

Entity Base

All the base TypeScript classes in an ORM file that represent a table or view (entity) extend the base class EntityBase. This base class is located in the wire-orm-base.ts file.

import { EntityBase } from "./wire-orm-base.ts";

class Categories extends EntityBase {
 
  public CategoryID: number;
  public CategoryName: string;
  public Description: string;

...

}

All the fields in an entity are defined on the ORM entity class which allows query results to be referenced using strong types. See DataTable Interface for details.

Fields

All the fields in an entity are created by name in an enum structure. The naming convention for the fields enum is [entity]Field.

enum CategoriesField {
  CategoryID = "CategoryID",
  CategoryName = "CategoryName",
  Description = "Description"
}

Constructor

The constructor for an entity class take three parameters.

Parameter

Description

source

The wire.data.DataSource object used to make calls to the query service

entity

The name of the entity in the SQL database

keys?

An optional array of primary key fields if they exist and the entity is a table. These are used in write operations.

class Categories extends EntityBase {
   ...
   constructor() {
      super(Northwind, "Categories", [CategoriesField.CategoryID]);
   }

DataTable Interface

The results of base queries are returned as wire.data.DataTable objects. In order for the Rows property on a data table to contains typed objects for a ORM class, an interface is used to override the property on the data table for each class. The execAsync method calls into its modified base method returning an instance of the typed object.

interface ICatagoriesDataTable extends Omit<IWireDataTable, "Rows"> {
  Rows: Array<Orders>;
}

class Categories extends EntityBase {
...
   async execAsync(): Promise<ICatagoriesDataTable> {
      return super.execAsync$();
   }
}

Last updated