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,
impl<D> ForeignKey<i32, D>where
D: TableBuilder + Default,
sourcepub fn new(value: i32) -> ForeignKey<i32, D>
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,
impl<D> ForeignKey<String, D>where
D: TableBuilder + Default,
sourcepub fn new(value: String) -> ForeignKey<String, D>
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>
impl<T, D> Clone for ForeignKey<T, D>
source§fn clone(&self) -> ForeignKey<T, D>
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<T, D> Debug for ForeignKey<T, D>
impl<T, D> Debug for ForeignKey<T, D>
source§impl<D> Default for ForeignKey<String, D>where
D: TableBuilder + Default,
impl<D> Default for ForeignKey<String, D>where
D: TableBuilder + Default,
source§impl<D> Default for ForeignKey<i32, D>where
D: TableBuilder + Default,
impl<D> Default for ForeignKey<i32, D>where
D: TableBuilder + Default,
source§impl<'de, T> Deserialize<'de> for ForeignKey<i32, T>
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>,
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,
impl<T, D> Display for ForeignKey<T, D>where
T: Display + 'static,
D: TableBuilder,
source§impl<T> From<&ForeignKey<i32, T>> for Valuewhere
T: TableBuilder + TablePrimaryKey,
impl<T> From<&ForeignKey<i32, T>> for Valuewhere
T: TableBuilder + TablePrimaryKey,
source§impl<D> From<&str> for ForeignKey<String, D>where
D: TableBuilder + Default,
impl<D> From<&str> for ForeignKey<String, D>where
D: TableBuilder + Default,
source§impl<T> From<ForeignKey<i32, T>> for Valuewhere
T: TableBuilder + TablePrimaryKey,
impl<T> From<ForeignKey<i32, T>> for Valuewhere
T: TableBuilder + TablePrimaryKey,
source§impl<D> From<PrimaryKey<String>> for ForeignKey<String, D>where
D: TableBuilder + Default,
impl<D> From<PrimaryKey<String>> for ForeignKey<String, D>where
D: TableBuilder + Default,
source§fn from(value: PrimaryKey<String>) -> ForeignKey<String, D>
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,
impl<D> From<PrimaryKey<i32>> for ForeignKey<i32, D>where
D: TableBuilder + Default,
source§fn from(value: PrimaryKey<i32>) -> ForeignKey<i32, D>
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,
impl<D> From<String> for ForeignKey<String, D>where
D: TableBuilder + Default,
source§impl<D> From<i32> for ForeignKey<i32, D>where
D: TableBuilder + Default,
impl<D> From<i32> for ForeignKey<i32, D>where
D: TableBuilder + Default,
source§impl<T, D> PartialEq for ForeignKey<T, D>
impl<T, D> PartialEq for ForeignKey<T, D>
source§fn eq(&self, other: &ForeignKey<T, D>) -> bool
fn eq(&self, other: &ForeignKey<T, D>) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl<D> Serialize for ForeignKey<i32, D>where
D: TableBuilder + Default,
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,
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
impl<T, D> Copy for ForeignKey<T, D>
impl<T, D> Eq for ForeignKey<T, D>
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>
impl<T, D> RefUnwindSafe for ForeignKey<T, D>where
T: RefUnwindSafe,
D: RefUnwindSafe,
impl<T, D> Send for ForeignKey<T, D>
impl<T, D> Sync for ForeignKey<T, D>
impl<T, D> Unpin for ForeignKey<T, D>
impl<T, D> UnwindSafe for ForeignKey<T, D>where
T: UnwindSafe,
D: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more