Field types
Field types
A field is a column in an entity table. Its type tells Tauriam what kind of value belongs there, which input to show when someone creates a record, and how the value can be searched, compared, linked, or calculated. For example, a product price should be a number so a page can sort it numerically or calculate a total.
| Prop | Type | Description |
|---|---|---|
| text | Text | A word, name, code, or short phrase, such as a product name or SKU. |
| Email address | An email value, such as a customer's contact email. Tauriam checks that the value is in email format. | |
| number | Number | A quantity or amount, such as unit price, stock, tax, or payment. Numbers can be sorted and used in calculations. |
| boolean | True or false | A yes/no value, such as whether a product is active or an invoice has been paid. |
| datetime | Date and time | A calendar date with a time, such as an order's creation or a delivery appointment. A form lets the user pick a date and time. Set the default to now to fill the current date and time automatically when a record is created. |
| select | Choose one option | A pick list with the options you define, such as Draft, Confirmed, and Shipped. The user selects one option instead of typing a value. |
| relation | Link to another table | Connects this record to one or more records in another entity, such as linking an order to its customer or to its order items. |
| unique_id | Automatic identifier | Creates a prefixed sequential identifier for a new record, such as INV-1042. Tauriam generates it automatically, so the user does not need to type it. |
| formula | Automatically calculated number | Calculates a number from fields on the same record, for example quantity multiplied by unit price. It is calculated when the record is created or updated. |
| array_formula | Automatically calculated total or count | Calculates across related records, for example adding every order item's line total to get the order total. It is calculated automatically when the record and its related items are created or updated. |
For example, an order item can link to a product, store the quantity being purchased, and calculate its line total. The order can then add those line totals across all its related items.
products {
name: text
sku: unique_id prefix("SKU")
price: number
available: boolean = true
added_at: datetime = now
category: select [Food, Equipment, Supplies]
}order_items {
product: products
quantity: number
unit_price: number
line_total: formula(${quantity} * ${unit_price})
}
orders {
items: order_items[]
total: array_formula sum(order_items.line_total)
}The item stores its own quantity and unit_price; the formula multiplies those two values to make line_total. The order's array formula follows its items relation and adds the line totals together. If the price should come from the linked product, a formula can read the related value with a dotted reference such as product.price. Store unit_price on the order item as well when you need to preserve the price charged at the time of sale.
Required values and defaults
now means Tauriam fills in the current date and time automatically.Formulas
A formula is a field that Tauriam calculates for you. You define the calculation using the names of other fields, and Tauriam fills in the result when a record is created or updated. You do not ask users to type a calculated value into a form.
Use formula for a calculation on one record. Put field names inside ${...}, then use addition, subtraction, multiplication, division, remainder, and parentheses. For example, if an order item has quantity and unit_price, its line total is quantity × unit price.
order_items {
product: products snapshot
quantity: number
unit_price: number
line_total: formula(${quantity} * ${unit_price})
}In this example, quantity is entered for the item, and unit_price is the price used for this sale. If the product relation contains the price and you want to read the current related value, use a dotted reference such as product.price. Keeping a separate unit_price is useful for orders because it preserves the price actually charged even if the catalog price changes later.
Use array_formula when the value must be calculated from a list of related records. For an order, add all related order-item line totals to get the order total. You can then use that total in another formula, for example to add tax or subtract a discount.
orders {
items: order_items[]
subtotal: array_formula sum(order_items.line_total)
total: formula(${subtotal} + ${tax} - ${discount})
}- Formula inputs such as
quantity,unit_price,tax, anddiscountshould be number fields. - Use a relation field to connect records; a dotted path such as
product.pricereads a value through that relation. - An array formula must point to the related entity list and a numeric field to sum, average, find the minimum or maximum, or count.
- Formulas and array formulas are calculated automatically at record creation and update. They can use other calculated fields when those values are ready first.
- Invalid field names and circular calculations are rejected when the entity is saved.
| Prop | Type | Description |
|---|---|---|
| sum | Total | Adds the selected field from all related records, such as every order item's line total. |
| avg | Average | Finds the average value across related records, such as an average item price. |
| min / max | Lowest / highest | Finds the smallest or largest related value. |
| count | Number of records | Counts the related records, such as how many items are on an order. |