The ultimate ORM for Node and Typescript
Bugfix: Adding hasOne row to existing parent throws. See https://github.com/alfateam/rdb/issues/86
Now supporting aggregates
You can count records and aggregate numerical columns. This can either be done across rows or separately for each row.
Supported functions include:
The aggregate function effeciently groups data together.
In this particular example , for each customer, it counts the number of lines associated with their orders and calculates the total amount of these lines.
Under the hood, it will run an sql group by customerId and customerName.
import map from './map';
const db = map.sqlite('demo.db');
getAggregates();
async function getAggregates() {
const orders = await db.order.aggregate({
where: x => x.orderDate.greaterThan(new Date(2022, 0, 11, 9, 24, 47)),
customerId: x => x.customerId,
customerName: x => x.customer.name,
numberOfLines: x => x.count(x => x.lines.id),
totals: x => x.sum(x => lines.amount)
});
}
Possible to elevate associated column on a related table to a parent table when fetching. Example with the customer.balance column below.
const orders = await db.order.getAll({
balance: x => x.customer.balance
});
Aggregate operators
const orders = await db.order.getAll({
numberOfLines: x => x.count(x => x.lines.id),
totalAmount: x => x.sum(x => x.lines.amount),
minAmount: x => x.min(x => x.lines.amount),
maxAmount: x => x.max(x => x.lines.amount),
avgAmount: x => x.avg(x => x.lines.amount),
});
Full Changelog: https://github.com/alfateam/rdb/compare/v3.6.2...v3.7.0
Bug fix: getMany with orderBy an array throws after v3.6.0
Filtering relations
MssqlNative and SAP ASE: PRINT statements no longer yields error.