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 uppercaselower(s)– convert to lowercaselength(s)– length of the stringleft(s, n)– firstncharactersright(s, n)– lastncharactersconcat(s1, s2, s3, …, sn)– concatenate multiple stringsformatstring(v, v1, v2, …, vn)– format a string based on values
Formatting to string
dateToString(f)– format a date using formatftimeToString(f)– format a time using formatfnumberToString(f)– format a number using formatfboolToString(f)– format a boolean using formatf
Boolean
Boolean computed properties are typically used for conditions or flags.
Logic
isnull(v, r1, r2)– returnsr1ifvis null, otherwiser2notnull(v, r1, r2)– opposite ofisnullgreater(v, r1, r2)–v > …comparisongtequal(...)– greater than or equalless(...)– less thanlsequal(...)– less than or equalequal(...)– equality checknotequal(...)– inequality checkodd(...)– check if a number is oddeven(...)– 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 dateweek– week numberyear– year partmonth– month partday– day of monthweekday– day of weekdateAddDay/dateAddWeek/dateAddYear– add unitsdateSubtractDay/dateSubtractWeek/dateSubtractYear– subtract unitsdateDifferenceDay/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 partminutes– minute partseconds– second parttimeAddHour/timeAddMinute/timeAddSecond– add timetimeSubtractHour/timeSubtractMinute/timeSubtractSecond– subtract timetimeDifferenceHour/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 valuessub(v1, v2, …, vn)– subtractionmul(v1, v2, …, vn)– multiplicationdiv(v1, v2, …, vn)– divisionpow(n, m)– powern^msqrt()– square root
Rounding
ceil()– round upfloor()– round downtrunc(v, n)– cut afterndecimal placesround(v, n)– round tondecimal places
Other
absolute()– absolute valuesign(v)– sign ofvrandom(n, m)– random number betweennandm
Finance
gross(value, vat)– gross value from net + VATgross100(value, vat)– gross for values already in percentnet(value, vat)– net value from grossnet100(value, vat)– net for percent valuespercentage(n, m)– percentage calculation
Statistics
average(v1, v2, v3, …, vn)– mean valuemedian(v1, v2, v3, …, vn)– medianmin(v1, v2, v3, …, vn)– minimummax(v1, v2, v3, …, vn)– maximum