Skip to content

Commit 8df4ca0

Browse files
authored
docs: Adding docs for enum default values on model fields (#155)
1 parent 39b7381 commit 8df4ca0

File tree

1 file changed

+59
-22
lines changed

1 file changed

+59
-22
lines changed

docs/06-concepts/02-models.md

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ This means that `defaultPersist` only comes into play when the model does not pr
166166

167167
#### Boolean
168168

169-
| Type | Keyword | Description |
170-
|----------------------------|---------|-------------|
171-
| **Boolean Values** | `true` or `false` | Sets the field to a boolean value, either `true` or `false`. |
169+
| Type | Keyword | Description |
170+
|-----------------|--------------------|-------------------------------------------------------|
171+
| **Boolean** | `true` or `false` | Sets the field to a boolean value, either `true` or `false`. |
172172

173173
**Example:**
174174

@@ -178,10 +178,10 @@ boolDefault: bool, default=true
178178

179179
#### DateTime
180180

181-
| Type | Keyword | Description |
182-
|----------------------------|---------|-------------|
183-
| **Current Date and Time** | `now` | Sets the field to the current date and time. |
184-
| **Specific UTC DateTime** | UTC DateTime string in the format `yyyy-MM-dd'T'HH:mm:ss.SSS'Z'` | Sets the field to a specific date and time. |
181+
| Type | Keyword | Description |
182+
|-------------------------|---------------|--------------------------------------------------------------|
183+
| **Current Date and Time** | `now` | Sets the field to the current date and time. |
184+
| **Specific UTC DateTime** | UTC DateTime string in the format `yyyy-MM-dd'T'HH:mm:ss.SSS'Z'` | Sets the field to a specific date and time. |
185185

186186
**Example:**
187187

@@ -192,9 +192,9 @@ dateTimeDefaultUtc: DateTime, default=2024-05-01T22:00:00.000Z
192192

193193
#### Double
194194

195-
| Type | Keyword | Description |
196-
|----------------------------|---------|-------------|
197-
| **Double Values** | Any double value | Sets the field to a specific double value. |
195+
| Type | Keyword | Description |
196+
|-----------------|--------------------|-------------------------------------------------------|
197+
| **Double** | Any double value | Sets the field to a specific double value. |
198198

199199
**Example:**
200200

@@ -204,21 +204,58 @@ doubleDefault: double, default=10.5
204204

205205
#### Duration
206206

207-
| Type | Keyword | Description |
208-
|-------------------------------|----------|-------------|
209-
| **Specific Duration** | A valid duration in the format `Xd Xh Xmin Xs Xms` | Sets the field to a specific duration value. Each part of the format represents a different unit of time: `d` for days, `h` for hours, `min` for minutes, `s` for seconds, and `ms` for milliseconds. For example, `1d 2h 10min 30s 100ms` represents 1 day, 2 hours, 10 minutes, 30 seconds, and 100 milliseconds. |
207+
| Type | Keyword | Description |
208+
|---------------------|---------------------|-----------------------------------------------------------------------------|
209+
| **Specific Duration** | A valid duration in the format `Xd Xh Xmin Xs Xms` | Sets the field to a specific duration value. For example, `1d 2h 10min 30s 100ms` represents 1 day, 2 hours, 10 minutes, 30 seconds, and 100 milliseconds. |
210210

211211
**Example:**
212212

213213
```yaml
214214
durationDefault: Duration, default=1d 2h 10min 30s 100ms
215215
```
216216

217+
#### Enum
218+
219+
| Type | Keyword | Description |
220+
|-----------------|--------------------|-------------------------------------------------------|
221+
| **Enum** | Any valid enum value | Sets the field to a specific enum value. |
222+
223+
**Example:**
224+
225+
```yaml
226+
enum: ByNameEnum
227+
serialized: byName
228+
values:
229+
- byName1
230+
- byName2
231+
```
232+
233+
```yaml
234+
enum: ByIndexEnum
235+
serialized: byIndex
236+
values:
237+
- byIndex1
238+
- byIndex2
239+
```
240+
241+
```yaml
242+
class: EnumDefault
243+
table: enum_default
244+
fields:
245+
byNameEnumDefault: ByNameEnum, default=byName1
246+
byIndexEnumDefault: ByIndexEnum, default=byIndex1
247+
```
248+
249+
In this example:
250+
251+
- The `byNameEnumDefault` field will default to `'byName1'` in the database.
252+
- The `byIndexEnumDefault` field will default to `0` (the index of `byIndex1`).
253+
217254
#### Integer
218255

219-
| Type | Keyword | Description |
220-
|----------------------------|---------|-------------|
221-
| **Integer Values** | Any integer value | Sets the field to a specific integer value. |
256+
| Type | Keyword | Description |
257+
|-----------------|--------------------|-------------------------------------------------------|
258+
| **Integer** | Any integer value | Sets the field to a specific integer value. |
222259

223260
**Example:**
224261

@@ -228,9 +265,9 @@ intDefault: int, default=10
228265

229266
#### String
230267

231-
| Type | Keyword | Description |
232-
|----------------------------|---------|-------------|
233-
| **String Values** | Any string value | Sets the field to a specific string value. |
268+
| Type | Keyword | Description |
269+
|-----------------|--------------------|-------------------------------------------------------|
270+
| **String** | Any string value | Sets the field to a specific string value. |
234271

235272
**Example:**
236273

@@ -240,9 +277,9 @@ stringDefault: String, default='This is a string'
240277

241278
#### UuidValue
242279

243-
| Type | Keyword | Description |
244-
|--------------------|----------|-------------|
245-
| **Random UUID** | `random` | Generates a random UUID. On the Dart side, `Uuid().v4obj()` is used. On the database side, `gen_random_uuid()` is used. |
280+
| Type | Keyword | Description |
281+
|--------------------|--------------------|-------------------------------------------------------|
282+
| **Random UUID** | `random` | Generates a random UUID. On the Dart side, `Uuid().v4obj()` is used. On the database side, `gen_random_uuid()` is used. |
246283
| **UUID String** | A valid UUID version 4 string | Assigns a specific UUID to the field. |
247284

248285
**Example:**

0 commit comments

Comments
 (0)