entity_id

Macro entity_id 

Source
macro_rules! entity_id {
    ($($name:ident),+ $(,)?) => { ... };
    ($($name:ident),+ $(,)? ; $($from:ty => $to:ty),* $(,)?) => { ... };
}
Expand description

Create UUID-wrappers for database operations.

This macro generates type-safe UUID-wrapper structs with trait support for serialization, database operations, GraphQL integration, and JSON schema generation.

§Features

The macro automatically includes different trait implementations based on enabled features:

  • graphql: Adds GraphQL UUID conversion traits
  • json-schema: Adds JSON schema generation support

§Generated Traits

All entity IDs automatically implement:

  • Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash
  • serde::Serialize, serde::Deserialize (with transparent serialization)
  • sqlx::Type (with transparent database type)
  • Display and FromStr for string conversion
  • From<Uuid> and From<EntityId> for UUID conversion

§Parameters

  • $name: One or more entity ID type names to create
  • $from => $to: Optional conversion pairs between different entity ID types

§Examples

use es_entity::entity_id;

entity_id! { UserId, OrderId }

// Creates:
// pub struct UserId(Uuid);
// pub struct OrderId(Uuid);
use es_entity::entity_id;

entity_id! {
    UserId,
    AdminUserId;
    UserId => AdminUserId
}

// Creates UserId and AdminUserId with `impl From` conversion between them