Introduction

ORM is an acronym for object-relational mapping which is a way in which data types in one system can be represented in another using object-oriented programming. Common ORM solutions in modern server-side programming include NHibernate and Entity Framework.

WireBootstrap has an ORM solution built on top of it's base query features that creates TypeScript classes, interfaces, and enums from tables, views, and stored procedures inside a database, data service, or other data connector end-point. The resulting TypeScript classes allow CRUD operations such as reading, writing, deleting, and updating these objects directly from JavaScript.

Samples

This site uses examples from the WireBootstrap Query Service ORM classes generated from the Northwind sample database.

Consider the code below created using standard WireBootstrap data objects to execute a query using the Query Service.

const source = new wire.data.DataSource("sql", {
    ...
}

const query = wire.data.select("ProductName", "UnitPrice")
    .from("Products").eq("SupplierID", 3843);
    
const table = await source.execAsync(query);

After generating an ORM TypeScript file from the SQL database, the same query can be created with less code.

import {Products, ProductsField} from "./northwind.orm.js";

const productsTable = await Products.select(ProductsField.ProductName)
    .eq(ProductsField.SupplierID, 3843)
.execAsync();

Both the query and it's results are type-safe and type-aware. Also, while creating the query, the author can take advantage of intellisense as all the classes, enums, and interfaces represent objects in the database.

For details on ORM support for a specific data connector, see the data connector documentation.

Last updated