A Collection is defined by its Data fields and their corresponding Data type.
For example, in our test database (simpledb-abee.restdb.io
) we created a Contact Collection with the following Data fields:
Text, email and image are just some of the basic data types supported in restdb.io.
A complete table of the avaliable data types is shown below.
Data type | Description | Properties | Validation | Example |
---|---|---|---|---|
Primary types | ||||
text | Any character | singleline, multiline, Markdown | input mask or regular expression | The quick brown fox |
number | Integers | auto increment | integer | 123 |
float_number | Floating point | formula:{{temp}}/3.14 | double | 3.1456789 |
money | Floating point | formula:{{salary}}*1.25 | double 2 decimals | 1200.00 |
email address | valid email | jones@restdb.io | ||
rich text | HTML text | HTML | Bold is the new italic | |
Date types | ||||
date | Date | format:DD MM YYYY default: ISO date string | valid date | 09 22 2015 |
datetime | Date with time | format:DD-MM-YYYY hh:ss | valid date + time | 09-22-2015 20:36 , formats docs |
time | Time | format: hh:ss | 01.01.1970 + time | 20:36 |
Media types | ||||
image(s) | Image | jpg, png, gif | A random image: | |
file(s) | Any file | |||
Status types | ||||
bool | Boolean | true or false | false | |
option | Predefined choices | One or many | One of the predefined options | ["ABBA", "Rolling Stones"] |
Custom types | ||||
JSON | A JSON object | Valid JSON string / object | {"state": "on", "readings": [23.4, 34.2, 900.0]} | |
Relations to Collections | ||||
collection | An existing Collection in your database | one item, many items, sub list | Valid ObjectID | ["56011d51e1321c7300000010", "55bb3bf70b37951e000001dd"] |
All primary Data fields can have a property to define if a Field is required and/or unique. Activating the Field dialog shows the settings for Required and/or Unique.
Fields of type float and string can be computed using an expression. In the field dialog which pops up when you add or edit a field, fill in an expression in the "Calculated value" box. This expression can use fields from the same record in the collection, numbers or strings. You can also add logic using a ternary expression. For example (revenue>150000)?"premium":"regular"
will yield the string "premium" when the record is saved and the revenue is above 150000.
If you have space in the field names, you need to wrap them:
({{net revenue}}>150000)?"premium":"regular"
Calculations are simple using computed fields:
(cost + profit) * 1.20