DecoratorsUuid
@uuid7
Auto-generate a time-ordered v7 UUID value on record creation.
Auto-generates a time-ordered v7 UUID when a record is created and the field is not provided. Uses SurrealDB's rand::uuid::v7() function.
Syntax
model Event {
id Record @id
sortableId Uuid @uuid7
}Behavior
Same behavior as @uuid, but explicitly generates a v7 (time-ordered) UUID:
- Uuid fields only — can only be applied to
Uuidtype fields. - Set on creation — generated when the field is absent. Your value is used if provided.
- Optional in CreateInput — the field becomes optional in create types.
- Time-ordered — v7 UUIDs embed a timestamp, making them naturally sortable by creation time. Ideal for IDs that need chronological ordering.
Usage
const event = await db.Event.create({
data: {
/* sortableId is optional — auto-generated as v7 */
},
});
console.log(event.sortableId); // CerialUuid — time-ordered v7Allowed On
- Model fields (
Uuidtype) - Object sub-fields (
Uuidtype)
- Not allowed on tuple elements — SurrealDB doesn't support
DEFAULTon tuple elements - Mutually exclusive — Cannot combine with
@default,@defaultAlways,@createdAt,@updatedAt,@now,@uuid, or@uuid4