orange-orm

The ultimate ORM for Node and Typescript

ISC License

Downloads
67K
Stars
675
Committers
9

Bot releases are hidden (Show)

orange-orm - v4.1.2 Latest Release

Published by lroal 4 months ago

Bugfix with composite primary key with hasMany relation. #106

orange-orm - v4.1.0

Published by lroal 4 months ago

Escape table and column names. #91 #92
NotNullable relations #104

orange-orm - v4.0.1

Published by lroal 4 months ago

Using inhouse definitions of ajv to avoid trouble with nestjs.

orange-orm - v4.0.0

Published by lroal 5 months ago

Changed the behaviour of update to accept a where filter and only update passed in columns and relations. The previous behaviour of update has moved to replace method.

From the docs:

__Selective updates__  
The update method is ideal for updating specific columns and relationships across one or multiple rows. You must provide a where filter to specify which rows to target. If you include a fetching strategy, the affected rows and their related data will be returned; otherwise, no data is returned.

```javascript
import map from './map';
const db = map.sqlite('demo.db');

update();

async function update() {

  const propsToBeModified = {
    orderDate: new Date(),
    customerId: 2,
    lines: [
      { id: 1, product: 'Bicycle', amount: 250 }, //already existing line
      { id: 2, product: 'Small guitar', amount: 150 }, //already existing line
      { product: 'Piano', amount: 800 } //the new line to be inserted
    ]
  };

  const strategy = {customer: true, deliveryAddress: true, lines: true};
  const orders = await db.order.update(propsToBeModified, { where: x => x.id.eq(1) }, strategy);
}

Replacing a row from JSON
The replace method is suitable when a complete overwrite is required from a JSON object - typically in a REST API. However, it's important to consider that this method replaces the entire row and it's children, which might not always be desirable in a multi-user environment.

import map from './map';
const db = map.sqlite('demo.db');

replace();

async function replace() {

  const modified = {
    id: 1,
    orderDate: '2023-07-14T12:00:00',
    customer: {
      id: 2
    },
    deliveryAddress: {
      name: 'Roger', //modified name
      street: 'Node street 1',
      postalCode: '7059',
      postalPlace: 'Jakobsli',
      countryCode: 'NO'
    },
    lines: [
      { id: 1, product: 'Bicycle', amount: 250 },
      { id: 2, product: 'Small guitar', amount: 150 },
      { product: 'Piano', amount: 800 } //the new line to be inserted
    ]
  };

  const order = await db.order.replace(modified, {customer: true, deliveryAddress: true, lines: true});
}
orange-orm - v3.10.3

Published by lroal 5 months ago

Fix duplicate signature for those still using code generation

orange-orm - v3.10.2

Published by lroal 5 months ago

RDB was renamed to orange-orm
Install from npmjs.org/package/orange-orm

orange-orm - v3.10.1

Published by lroal 5 months ago

Bugfix: Adding hasOne row to existing parent throws. See https://github.com/alfateam/rdb/issues/86

orange-orm - v3.10.0

Published by lroal 5 months ago

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:

  • count
  • sum
  • min
  • max
  • avg

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)    
  });
}
orange-orm - v3.9.0

Published by lroal 5 months ago

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
  });
orange-orm - v3.8.0

Published by lroal 6 months ago

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),
  });
orange-orm - v.3.7.0

Published by lroal 6 months ago

orange-orm - v3.6.2

Published by lroal 6 months ago

Bug fix:
getMany with orderBy an array throws after v3.6.0

orange-orm - v3.6.1

Published by lroal 7 months ago

What's Changed

orange-orm - v3.6.0

Published by lroal 7 months ago

Filtering relations

orange-orm - v3.5.2

Published by lroal 9 months ago

MssqlNative and SAP ASE: PRINT statements no longer yields error.

orange-orm -

Published by lroal 9 months ago

orange-orm - v3.5.0

Published by lroal 9 months ago

Now supporting Oracle

orange-orm - v3.4.0

Published by lroal 9 months ago

Allow multiple result sets for sap and mssql

orange-orm - v3.3.0

Published by lroal 10 months ago

Possible to apply updates from JSON object. See #70.

orange-orm - v3.2.9

Published by lroal 11 months ago

Transaction was ignored. See #68.
Proxify method had incorrect type signature. See #69.