sea_orm::entity

Trait PrimaryKeyTrait

Source
pub trait PrimaryKeyTrait: IdenStatic + Iterable {
    type ValueType: Sized + Send + Debug + PartialEq + IntoValueTuple + FromValueTuple + TryGetableMany + TryFromU64 + PrimaryKeyArity;

    // Required method
    fn auto_increment() -> bool;
}
Expand description

A Trait for to be used to define a Primary Key.

A primary key can be derived manually

§Example

use sea_orm::entity::prelude::*;

#[derive(Copy, Clone, Debug, EnumIter)]
pub enum PrimaryKey {
    Id,
}
impl PrimaryKeyTrait for PrimaryKey {
    type ValueType = i32;

    fn auto_increment() -> bool {
        true
    }
}

Alternatively, use derive macros to automatically implement the trait for a Primary Key

§Example

use sea_orm::entity::prelude::*;

#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
pub enum PrimaryKey {
    Id,
}

See module level docs crate::entity for a full example

Required Associated Types§

Required Methods§

Source

fn auto_increment() -> bool

Method to call to perform AUTOINCREMENT operation on a Primary Key

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§