Struct geekorm::ForeignKey

source ·
pub struct ForeignKey<T, D>
where T: Display + 'static, D: TableBuilder,
{ pub key: T, pub data: D, }
Expand description

Foreign Key Type

use geekorm::prelude::*;
use geekorm::{ForeignKey, PrimaryKeyInteger};

#[derive(Clone, Default, GeekTable)]
struct Users {
    id: PrimaryKeyInteger,
    name: String,
}

#[derive(Default, Clone, GeekTable)]
struct Posts {
    id: PrimaryKeyInteger,
    title: String,
    /// Foreign Key to the Users table
    /// i32 as the key type, and Users as the data type
    #[geekorm(foreign_key = "Users.id")]
    user: ForeignKey<i32, Users>,
}

// Create the Posts table with the foreign key referencing the Users table (Users.id)
let create_posts_query = Posts::create().build()
    .expect("Failed to build query");

// Use the foreign key to and join the tables together
// to get the user posts
let user_posts = Users::select()
    .order_by("name", geekorm::QueryOrder::Asc)
    .build()
    .expect("Failed to build query");

println!("User posts query: {:?}", user_posts);
// ...

Fields§

§key: T

Foreign Key Value

§data: D

Foreign Key Data Type

Implementations§

source§

impl<D> ForeignKey<i32, D>
where D: TableBuilder + Default,

source

pub fn new(value: i32) -> ForeignKey<i32, D>

Create a new foreign key with an integer

source§

impl<D> ForeignKey<String, D>
where D: TableBuilder + Default,

source

pub fn new(value: String) -> ForeignKey<String, D>

Create a new foreign key with a String

Trait Implementations§

source§

impl<T, D> Clone for ForeignKey<T, D>
where T: Clone + Display + 'static, D: Clone + TableBuilder,

source§

fn clone(&self) -> ForeignKey<T, D>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T, D> Debug for ForeignKey<T, D>
where T: Debug + Display + 'static, D: TableBuilder,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<D> Default for ForeignKey<String, D>
where D: TableBuilder + Default,

source§

fn default() -> ForeignKey<String, D>

Returns the “default value” for a type. Read more
source§

impl<D> Default for ForeignKey<i32, D>
where D: TableBuilder + Default,

source§

fn default() -> ForeignKey<i32, D>

Returns the “default value” for a type. Read more
source§

impl<'de, T> Deserialize<'de> for ForeignKey<i32, T>

source§

fn deserialize<D>( deserializer: D ) -> Result<ForeignKey<i32, T>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T, D> Display for ForeignKey<T, D>
where T: Display + 'static, D: TableBuilder,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<T> From<&ForeignKey<i32, T>> for Value

source§

fn from(value: &ForeignKey<i32, T>) -> Value

Converts to this type from the input type.
source§

impl<D> From<&str> for ForeignKey<String, D>
where D: TableBuilder + Default,

source§

fn from(value: &str) -> ForeignKey<String, D>

Converts to this type from the input type.
source§

impl<T> From<ForeignKey<i32, T>> for Value

source§

fn from(value: ForeignKey<i32, T>) -> Value

Converts to this type from the input type.
source§

impl<D> From<PrimaryKey<String>> for ForeignKey<String, D>
where D: TableBuilder + Default,

source§

fn from(value: PrimaryKey<String>) -> ForeignKey<String, D>

Converts to this type from the input type.
source§

impl<D> From<PrimaryKey<i32>> for ForeignKey<i32, D>
where D: TableBuilder + Default,

source§

fn from(value: PrimaryKey<i32>) -> ForeignKey<i32, D>

Converts to this type from the input type.
source§

impl<D> From<String> for ForeignKey<String, D>
where D: TableBuilder + Default,

source§

fn from(value: String) -> ForeignKey<String, D>

Converts to this type from the input type.
source§

impl<D> From<i32> for ForeignKey<i32, D>
where D: TableBuilder + Default,

source§

fn from(value: i32) -> ForeignKey<i32, D>

Converts to this type from the input type.
source§

impl<T, D> PartialEq for ForeignKey<T, D>
where T: PartialEq + Display + 'static, D: PartialEq + TableBuilder,

source§

fn eq(&self, other: &ForeignKey<T, D>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<D> Serialize for ForeignKey<i32, D>
where D: TableBuilder + Default,

source§

fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T, D> Copy for ForeignKey<T, D>
where T: Copy + Display + 'static, D: Copy + TableBuilder,

source§

impl<T, D> Eq for ForeignKey<T, D>
where T: Eq + Display + 'static, D: Eq + TableBuilder,

source§

impl<T, D> StructuralPartialEq for ForeignKey<T, D>
where T: Display + 'static, D: TableBuilder,

Auto Trait Implementations§

§

impl<T, D> Freeze for ForeignKey<T, D>
where T: Freeze, D: Freeze,

§

impl<T, D> RefUnwindSafe for ForeignKey<T, D>

§

impl<T, D> Send for ForeignKey<T, D>
where T: Send, D: Send,

§

impl<T, D> Sync for ForeignKey<T, D>
where T: Sync, D: Sync,

§

impl<T, D> Unpin for ForeignKey<T, D>
where T: Unpin, D: Unpin,

§

impl<T, D> UnwindSafe for ForeignKey<T, D>
where T: UnwindSafe, D: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,