> For the complete documentation index, see [llms.txt](https://docs.wirebootstrap.com/orm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wirebootstrap.com/orm/tables-and-views.md).

# 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.

```javascript
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](#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*.

```javascript
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. |

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

```

## DataTable Interface

The results of base queries are returned as [wire.data.DataTable](https://docs.wirebootstrap.com/wirebootstrap/working-with-datatables/datatables) 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.

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

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