pub trait Relation<Target: ?Sized> {}
pub trait Joinable<Target: ?Sized> {
fn fk_columns() -> &'static [(&'static str, &'static str)];
}
#[diagnostic::on_unimplemented(
message = "table `{T}` is not part of schema `{Self}`",
label = "add this table as a field in your schema struct",
note = "all tables used in queries must be included in the schema"
)]
pub trait SchemaHasTable<T: ?Sized> {}
#[cfg(feature = "query")]
pub trait RelationDef: private::Sealed + 'static {
type Source;
type Target: crate::query::QueryTable;
type Card: CardWrap;
const NAME: &'static str;
fn fk_columns() -> &'static [(&'static str, &'static str)];
#[must_use]
fn junction() -> Option<JunctionMeta> {
None
}
}
#[cfg(feature = "query")]
pub trait CardWrap: private::Sealed {
const CARDINALITY: crate::query::RelCardinality;
type Wrap<T>;
}
#[cfg(feature = "query")]
pub struct Many;
#[cfg(feature = "query")]
pub struct One;
#[cfg(feature = "query")]
pub struct OptionalOne;
#[cfg(feature = "query")]
#[derive(Debug, Clone, Copy)]
pub struct JunctionMeta {
pub table_name: &'static str,
pub source_fk: &'static [(&'static str, &'static str)],
pub target_fk: &'static [(&'static str, &'static str)],
}
#[cfg(feature = "query")]
impl private::Sealed for Many {}
#[cfg(feature = "query")]
impl private::Sealed for One {}
#[cfg(feature = "query")]
impl private::Sealed for OptionalOne {}
#[cfg(feature = "query")]
impl CardWrap for Many {
const CARDINALITY: crate::query::RelCardinality = crate::query::RelCardinality::Many;
type Wrap<T> = crate::prelude::Vec<T>;
}
#[cfg(feature = "query")]
impl CardWrap for One {
const CARDINALITY: crate::query::RelCardinality = crate::query::RelCardinality::One;
type Wrap<T> = T;
}
#[cfg(feature = "query")]
impl CardWrap for OptionalOne {
const CARDINALITY: crate::query::RelCardinality = crate::query::RelCardinality::OptionalOne;
type Wrap<T> = Option<T>;
}
#[cfg(feature = "query")]
#[doc(hidden)]
pub mod private {
pub trait Sealed {}
}