Skip to content

Commit

Permalink
Add default hint for required values in schema (#885)
Browse files Browse the repository at this point in the history
I've seen this asked more than once

---------

Co-authored-by: Tim Condon <[email protected]>
Co-authored-by: Gwynne Raskind <[email protected]>
  • Loading branch information
3 people authored Aug 7, 2023
1 parent a4dfba1 commit b43e93c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion docs/fluent/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,21 @@ Below is an example using foreign key actions.
Foreign key actions happen solely in the database, bypassing Fluent.
This means things like model middleware and soft-delete may not work correctly.

## SQL

The `.sql` parameter allows you to add arbitrary SQL to your schema. This is useful for adding specific constraints or data types.
A common use case is defining a default value for a field:

```swift
.field("active", .bool, .required, .sql(.default(true)))
```

or even a default value for a timestamp:

```swift
.field("created_at", .datetime, .required, .sql(.default(SQLFunction("now"))))
```

## Dictionary

The dictionary data type is capable of storing nested dictionary values. This includes structs that conform to `Codable` and Swift dictionaries with a `Codable` value.
Expand Down Expand Up @@ -389,4 +404,4 @@ try await db.schema("planets", space: "mirror_universe")
.id()
// ...
.create()
```
```

0 comments on commit b43e93c

Please sign in to comment.