Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ This allows the Amplify team to maintain and enhance the SQL Layer without needi
| integer | a.integer() |
| bigint | a.integer() |
| tinyint | a.integer() |
| serial* | a.integer().default() |
| float | a.float() |
| double | a.float() |
| decimal | a.float() |
Expand All @@ -429,6 +430,8 @@ This allows the Amplify team to maintain and enhance the SQL Layer without needi
| json | a.json() |
| enum | a.enum() |

*Support for auto increment (serial) fields is limited to PostgreSQL datasources.

## Troubleshooting

### Debug Mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ const schema = a.schema({
}),
}).authorization((allow) => allow.publicApiKey());
```

If you're working with a Postgres datasource, `.default()` can be used to represent [serial fields](/[platform]/build-a-backend/data/connect-to-existing-data-sources/connect-postgres-mysql-database/#mapping-of-sql-data-types-to-field-types-for-auto-generated-schema).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to specify that .default() can only be applied to .integer() fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworded to make integer fields more explicit

If you're working with a Postgres datasource, .default() can be applied to integer fields to represent serial fields.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does .default() require an argument here similar to the graphql directive?

Copy link
Contributor Author

@p5quared p5quared Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we've removed the required arg for both. .default() maps to @default. There are checks in place so that this special (no argument) case can only be applied if:

  1. Datsource is Postgres
  2. Fieldtype is integer


<Callout>
**Note:** The `.default(...)` modifier can't be applied to required fields.
</Callout>
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ print("New Todo created: \(createdTodo)")
</InlineFilter>

If you want, you can use Amplify Data to define single-field and composite identifiers:
- Single-field identifier with a consumer-provided value (type: `id` or `string`, and must be marked `required`)
- Composite identifier with a set of consumer-provided values (type: `id` or `string`, and must be marked `required`)
- Single-field identifier with a consumer-provided value (type: `id` or `string` marked `required`, or for a [serial identifier](/[platform]/build-a-backend/data/data-modeling/add-fields/#assign-default-values-for-fields), type: `integer` marked `default`)
- Composite identifier with a set of consumer-provided values (type: `id` or `string` marked `required`, or for a [serial identifier](/[platform]/build-a-backend/data/data-modeling/add-fields/#assign-default-values-for-fields), type: `integer` marked `default`)

## Single-field identifier

Expand Down