Skip to main content

Computed Properties

Introduction

When creating data entities, the basic property types cover most use cases.
For some scenarios, however, you need properties whose value is calculated dynamically based on other values.

For this, yeet provides computed properties.

Usage

As the name implies, computed properties are used for columns that require additional computation.
Typical examples:

  • calculating the sum of multiple numeric columns (e.g. prices, totals),
  • transforming dates or times into derived values,
  • formatting values for display (e.g. “gross price with VAT”).

Computed properties are based on predefined function sets, depending on the property’s data type.

Types of computed properties

String

String computed properties allow you to manipulate text.

String manipulation

  • upper(s) – convert to uppercase
  • lower(s) – convert to lowercase
  • length(s) – length of the string
  • left(s, n) – first n characters
  • right(s, n) – last n characters
  • concat(s1, s2, s3, …, sn) – concatenate multiple strings
  • formatstring(v, v1, v2, …, vn) – format a string based on values

Formatting to string

  • dateToString(f) – format a date using format f
  • timeToString(f) – format a time using format f
  • numberToString(f) – format a number using format f
  • boolToString(f) – format a boolean using format f

Boolean

Boolean computed properties are typically used for conditions or flags.

Logic

  • isnull(v, r1, r2) – returns r1 if v is null, otherwise r2
  • notnull(v, r1, r2) – opposite of isnull
  • greater(v, r1, r2)v > … comparison
  • gtequal(...) – greater than or equal
  • less(...) – less than
  • lsequal(...) – less than or equal
  • equal(...) – equality check
  • notequal(...) – inequality check
  • odd(...) – check if a number is odd
  • even(...) – check if a number is even

(Use these functions to build rules like “order total > 0” or “customer is active”.)


Date

Date computed properties allow you to create or transform dates.

  • now – current date
  • week – week number
  • year – year part
  • month – month part
  • day – day of month
  • weekday – day of week
  • dateAddDay / dateAddWeek / dateAddYear – add units
  • dateSubtractDay / dateSubtractWeek / dateSubtractYear – subtract units
  • dateDifferenceDay / dateDifferenceWeek / dateDifferenceYear – difference between two dates

These are useful, for example, to calculate deadlines, age, or validity ranges.


Time

Time computed properties work on time-of-day values.

  • hour – hour part
  • minutes – minute part
  • seconds – second part
  • timeAddHour / timeAddMinute / timeAddSecond – add time
  • timeSubtractHour / timeSubtractMinute / timeSubtractSecond – subtract time
  • timeDifferenceHour / timeDifferenceMinute / timeDifferenceSecond – time differences

Double (numeric)

Double computed properties can be used for numeric calculations, financial values or statistics.

Basic math

  • sum(v1, v2, …, vn) – sum of all values
  • sub(v1, v2, …, vn) – subtraction
  • mul(v1, v2, …, vn) – multiplication
  • div(v1, v2, …, vn) – division
  • pow(n, m) – power n^m
  • sqrt() – square root

Rounding

  • ceil() – round up
  • floor() – round down
  • trunc(v, n) – cut after n decimal places
  • round(v, n) – round to n decimal places

Other

  • absolute() – absolute value
  • sign(v) – sign of v
  • random(n, m) – random number between n and m

Finance

  • gross(value, vat) – gross value from net + VAT
  • gross100(value, vat) – gross for values already in percent
  • net(value, vat) – net value from gross
  • net100(value, vat) – net for percent values
  • percentage(n, m) – percentage calculation

Statistics

  • average(v1, v2, v3, …, vn) – mean value
  • median(v1, v2, v3, …, vn) – median
  • min(v1, v2, v3, …, vn) – minimum
  • max(v1, v2, v3, …, vn) – maximum