mirror of
https://github.com/ent/ent.git
synced 2026-05-05 00:50:54 +03:00
doc/md: docs for new globalid feature (#4344)
This commit is contained in:
@@ -413,3 +413,24 @@ client.User.
|
||||
|
||||
// INSERT INTO "users" (...) VALUES ... ON CONFLICT WHERE ... DO UPDATE SET ... WHERE ...
|
||||
```
|
||||
|
||||
### Globally Unique ID
|
||||
|
||||
By default, SQL primary-keys start from 1 for each table; which means that multiple entities of different types
|
||||
can share the same ID. Unlike AWS Neptune, where node IDs are UUIDs.
|
||||
|
||||
This does not work well if you work with [GraphQL](https://graphql.org/learn/schema/#scalar-types), which requires
|
||||
the object ID to be unique.
|
||||
|
||||
To enable the Universal-IDs support for your project, simply use the `--feature sql/globalid` flag.
|
||||
|
||||
:::warning Note
|
||||
If you have used the `migrate.WithGlobalUniqueID(true)` migration option in the past, please read
|
||||
[this guide](globalid-migrate) before you switch your project to use the new globalid feature.
|
||||
:::
|
||||
|
||||
**How does it work?** `ent` migration allocates a 1<<32 range for the IDs of each entity (table),
|
||||
and store this information alongside your generated code (`internal/globalid.go`). For example, type `A` will have the
|
||||
range of `[1,4294967296)` for its IDs, and type `B` will have the range of `[4294967296,8589934592)`, etc.
|
||||
|
||||
Note that if this option is enabled, the maximum number of possible tables is **65535**.
|
||||
|
||||
Reference in New Issue
Block a user