LanguageValues and typesStandard typesCommerce and logistics
UnitQuantity
On this page
How much of something: a count of items, or an amount by mass, volume, length or area.
Use it on an order line or a stock count that sells both "3 items" and "2.5 kg". If you sell only whole items, your own type on Int is simpler.
Shape
One of these, each with its own fields:
| Variant | Field | Type | Required? |
|---|---|---|---|
UnitQuantity.each |
count |
Int |
Yes |
UnitQuantity.mass |
amount |
Mass |
Yes |
UnitQuantity.volume |
amount |
Volume |
Yes |
UnitQuantity.length |
amount |
Length |
Yes |
UnitQuantity.area |
amount |
Area |
Yes |
Example
UnitQuantity.each { count: 3 }Good to know
- The others are
.mass,.volume,.lengthand.area, each with anamount:UnitQuantity.mass { amount: 2.5kg }. - It can't be below zero.
==tells you whether two are the same.<andlist.sort_bydon't take it.
In JSON
An object of its variant's name, as tag, and the variant's fields, in a request, a response or json.write:
{"tag":"each","count":3}{"tag":"each","count":1200}{"tag":"mass","amount":{"value":"2.5","unit":"kg"}}
Details
Text form, storage, how it is shown, and operations
UnitQuantity is in the group Commerce and logistics, and has been in Jadpo since 0.1.0.
Text form
It has no single text form, so text.from and text.parse don't take it.
How it is stored
It is stored in 3 columns, each named for the field, _ and its suffix. This is {"tag":"volume","amount":{"value":"0.0015","unit":"cubic_metre"}}:
| Column | Type | Holds |
|---|---|---|
<field>_kind |
text |
'volume' |
<field>_count |
bigint |
NULL::bigint |
<field>_amount |
numeric(38, 9) |
0.0015 |
How it is shown to people
text.format(value, locale:) shows it to people in their locale.
With locale: Locale.en_gb:
| Value | Shown |
|---|---|
{"tag":"each","count":3} |
3 |
{"tag":"each","count":1200} |
1,200 |
{"tag":"mass","amount":{"value":"2.5","unit":"kg"}} |
2.5 kg |
{"tag":"volume","amount":{"value":"0.0015","unit":"cubic_metre"}} |
0.0015 m³ |
{"tag":"length","amount":{"value":"12","unit":"metre"}} |
12 m |
{"tag":"area","amount":{"value":"20","unit":"sqm"}} |
20 m² |
Operations
It also takes text.format, json.read, json.write and ==. How every standard type behaves says how they work.
Markdown for agents: /docs/types/type-unit-quantity.md.Built from Jadpo main at aee2e8f.