use super::{
morph_to_impls::{MorphToMutTargetSpec, MorphToTargetSpec},
*,
};
pub fn belongs_to<Child>(child: &Child) -> BelongsToBuilder<'_, Child> {
BelongsToBuilder { child }
}
pub fn belongs_to_mut<Child: Draftable>(child: &mut Child) -> BelongsToMutBuilder<'_, Child> {
BelongsToMutBuilder { child }
}
pub fn morph_to<Child>(child: &Child) -> MorphToBuilder<'_, Child> {
MorphToBuilder { child }
}
pub fn morph_to_mut<Child: Draftable>(child: &mut Child) -> MorphToMutBuilder<'_, Child> {
MorphToMutBuilder { child }
}
pub fn belongs_to_many<Parent>(parent: &Parent) -> BelongsToManyBuilder<'_, Parent> {
BelongsToManyBuilder { parent }
}
pub fn morph_to_many<Parent>(parent: &Parent) -> MorphToManyBuilder<'_, Parent> {
MorphToManyBuilder { parent }
}
pub fn morphed_by_many<Parent>(parent: &Parent) -> MorphedByManyBuilder<'_, Parent> {
MorphedByManyBuilder { parent }
}
pub fn has_many<Parent>(parent: &Parent) -> HasManyBuilder<'_, Parent> {
HasManyBuilder { parent }
}
pub fn has_one<Parent>(parent: &Parent) -> HasOneBuilder<'_, Parent> {
HasOneBuilder { parent }
}
pub fn morph_many<Parent>(parent: &Parent) -> MorphManyBuilder<'_, Parent> {
MorphManyBuilder { parent }
}
pub fn morph_one<Parent>(parent: &Parent) -> MorphOneBuilder<'_, Parent> {
MorphOneBuilder { parent }
}
pub struct BelongsToBuilder<'a, Child> {
pub(super) child: &'a Child,
}
pub struct BelongsToMutBuilder<'a, Child: Draftable> {
pub(super) child: &'a mut Child,
}
pub struct MorphToBuilder<'a, Child> {
pub(super) child: &'a Child,
}
pub struct MorphToMutBuilder<'a, Child: Draftable> {
pub(super) child: &'a mut Child,
}
pub struct BelongsToManyBuilder<'a, Parent> {
pub(super) parent: &'a Parent,
}
pub struct MorphToManyBuilder<'a, Parent> {
pub(super) parent: &'a Parent,
}
pub struct MorphedByManyBuilder<'a, Parent> {
pub(super) parent: &'a Parent,
}
pub struct BelongsToManyPivotBuilder<'a, Parent, Pivot> {
pub(super) parent: &'a Parent,
pub(super) pivot_table: query::Table<Pivot>,
}
pub struct MorphToManyPivotBuilder<'a, Parent, Pivot> {
pub(super) parent: &'a Parent,
pub(super) pivot_table: query::Table<Pivot>,
}
pub struct MorphedByManyPivotBuilder<'a, Parent, Pivot> {
pub(super) parent: &'a Parent,
pub(super) pivot_table: query::Table<Pivot>,
}
pub struct BelongsToManyParentKeyBuilder<'a, Parent, Pivot, ParentMeta: crate::TypeMeta> {
pub(super) parent: &'a Parent,
pub(super) pivot_table: query::Table<Pivot>,
pub(super) parent_key: expression::Column<Pivot, ParentMeta>,
}
pub struct MorphToManyParentKeyBuilder<'a, Parent, Pivot, ParentMeta: crate::TypeMeta> {
pub(super) parent: &'a Parent,
pub(super) pivot_table: query::Table<Pivot>,
pub(super) parent_key: expression::Column<Pivot, ParentMeta>,
}
pub struct MorphedByManyParentKeyBuilder<'a, Parent, Pivot, ParentMeta: crate::TypeMeta> {
pub(super) parent: &'a Parent,
pub(super) pivot_table: query::Table<Pivot>,
pub(super) parent_key: expression::Column<Pivot, ParentMeta>,
}
pub struct MorphToManyTypeBuilder<'a, Parent, Pivot, ParentMeta: crate::TypeMeta> {
pub(super) parent: &'a Parent,
pub(super) pivot_table: query::Table<Pivot>,
pub(super) parent_key: expression::Column<Pivot, ParentMeta>,
pub(super) morph_type: expression::Column<Pivot, crate::Text>,
}
pub struct MorphedByManyTypeBuilder<'a, Parent, Pivot, ParentMeta: crate::TypeMeta> {
pub(super) parent: &'a Parent,
pub(super) pivot_table: query::Table<Pivot>,
pub(super) parent_key: expression::Column<Pivot, ParentMeta>,
pub(super) morph_type: expression::Column<Pivot, crate::Text>,
}
pub struct BelongsToManyRelatedKeyBuilder<
'a,
Parent,
Pivot,
ParentMeta: crate::TypeMeta,
RelatedMeta: crate::TypeMeta,
> {
pub(super) parent: &'a Parent,
pub(super) pivot_table: query::Table<Pivot>,
pub(super) parent_key: expression::Column<Pivot, ParentMeta>,
pub(super) related_key: expression::Column<Pivot, RelatedMeta>,
}
pub struct MorphToManyRelatedKeyBuilder<
'a,
Parent,
Pivot,
ParentMeta: crate::TypeMeta,
RelatedMeta: crate::TypeMeta,
> {
pub(super) parent: &'a Parent,
pub(super) pivot_table: query::Table<Pivot>,
pub(super) parent_key: expression::Column<Pivot, ParentMeta>,
pub(super) morph_type: expression::Column<Pivot, crate::Text>,
pub(super) related_key: expression::Column<Pivot, RelatedMeta>,
pub(super) morph_name: Option<&'static str>,
}
pub struct MorphedByManyRelatedKeyBuilder<
'a,
Parent,
Pivot,
ParentMeta: crate::TypeMeta,
RelatedMeta: crate::TypeMeta,
> {
pub(super) parent: &'a Parent,
pub(super) pivot_table: query::Table<Pivot>,
pub(super) parent_key: expression::Column<Pivot, ParentMeta>,
pub(super) morph_type: expression::Column<Pivot, crate::Text>,
pub(super) related_key: expression::Column<Pivot, RelatedMeta>,
pub(super) morph_name: Option<&'static str>,
}
pub struct BuiltBelongsToMany<
'a,
Parent,
Pivot,
ParentMeta: crate::TypeMeta,
RelatedMeta: crate::TypeMeta,
LocalField,
> {
pub(super) parent: &'a Parent,
pub(super) pivot_table: query::Table<Pivot>,
pub(super) parent_key: expression::Column<Pivot, ParentMeta>,
pub(super) related_key: expression::Column<Pivot, RelatedMeta>,
pub(super) local_key: LocalField,
}
pub struct BuiltMorphToMany<
'a,
Parent,
Pivot,
ParentMeta: crate::TypeMeta,
RelatedMeta: crate::TypeMeta,
LocalField,
> {
pub(super) parent: &'a Parent,
pub(super) pivot_table: query::Table<Pivot>,
pub(super) parent_key: expression::Column<Pivot, ParentMeta>,
pub(super) morph_type: expression::Column<Pivot, crate::Text>,
pub(super) related_key: expression::Column<Pivot, RelatedMeta>,
pub(super) local_key: LocalField,
pub(super) morph_name: Option<&'static str>,
}
pub struct BuiltMorphedByMany<
'a,
Parent,
Pivot,
ParentMeta: crate::TypeMeta,
RelatedMeta: crate::TypeMeta,
LocalField,
> {
pub(super) parent: &'a Parent,
pub(super) pivot_table: query::Table<Pivot>,
pub(super) parent_key: expression::Column<Pivot, ParentMeta>,
pub(super) morph_type: expression::Column<Pivot, crate::Text>,
pub(super) related_key: expression::Column<Pivot, RelatedMeta>,
pub(super) local_key: LocalField,
pub(super) morph_name: Option<&'static str>,
}
pub struct HasManyBuilder<'a, Parent> {
pub(super) parent: &'a Parent,
}
pub struct HasOneBuilder<'a, Parent> {
pub(super) parent: &'a Parent,
}
pub struct MorphManyBuilder<'a, Parent> {
pub(super) parent: &'a Parent,
}
pub struct MorphOneBuilder<'a, Parent> {
pub(super) parent: &'a Parent,
}
pub trait IntoBelongsToBuilder<'a, Child> {
type Output;
fn into_builder(self, child: &'a Child) -> Self::Output;
}
pub trait IntoBelongsToMutBuilder<'a, Child: Draftable> {
type Output;
fn into_builder(self, child: &'a mut Child) -> Self::Output;
}
pub trait IntoMorphToBuilder<'a, Child> {
type Output;
fn into_builder(self, child: &'a Child) -> Self::Output;
}
pub trait IntoMorphToMutBuilder<'a, Child: Draftable> {
type Output;
fn into_builder(self, child: &'a mut Child) -> Self::Output;
}
pub trait IntoHasManyBuilder<'a, Parent> {
type Output;
fn into_builder(self, parent: &'a Parent) -> Self::Output;
}
pub trait IntoHasOneBuilder<'a, Parent> {
type Output;
fn into_builder(self, parent: &'a Parent) -> Self::Output;
}
pub trait IntoMorphManyBuilder<'a, Parent> {
type Output;
fn into_builder(self, parent: &'a Parent) -> Self::Output;
}
pub trait IntoMorphOneBuilder<'a, Parent> {
type Output;
fn into_builder(self, parent: &'a Parent) -> Self::Output;
}
pub struct RequiredBelongsToBuilder<'a, Child, ForeignKey, ForeignMeta: crate::TypeMeta> {
pub(super) child: &'a Child,
pub(super) foreign_key: PersistedField<Child, ForeignKey, ForeignMeta, RequiredField>,
}
pub struct NullableBelongsToBuilderImpl<'a, Child, ForeignKey, ForeignMeta: crate::TypeMeta> {
pub(super) child: &'a Child,
pub(super) foreign_key: PersistedField<Child, Option<ForeignKey>, ForeignMeta, NullableField>,
}
pub struct RequiredBelongsToMutBuilder<
'a,
Child: Draftable,
ForeignKey,
ForeignMeta: crate::TypeMeta,
> {
pub(super) child: &'a mut Child,
pub(super) foreign_key: PersistedField<Child, ForeignKey, ForeignMeta, RequiredField>,
}
pub struct NullableBelongsToMutBuilderImpl<
'a,
Child: Draftable,
ForeignKey,
ForeignMeta: crate::TypeMeta,
> {
pub(super) child: &'a mut Child,
pub(super) foreign_key: PersistedField<Child, Option<ForeignKey>, ForeignMeta, NullableField>,
}
pub struct RequiredMorphToBuilder<'a, Child, ForeignKey, ForeignMeta: crate::TypeMeta> {
pub(super) child: &'a Child,
pub(super) foreign_key: PersistedField<Child, ForeignKey, ForeignMeta, RequiredField>,
}
pub struct NullableMorphToBuilder<'a, Child, ForeignKey, ForeignMeta: crate::TypeMeta> {
pub(super) child: &'a Child,
pub(super) foreign_key: PersistedField<Child, Option<ForeignKey>, ForeignMeta, NullableField>,
}
pub struct RequiredMorphToMutBuilder<'a, Child: Draftable, ForeignKey, ForeignMeta: crate::TypeMeta>
{
pub(super) child: &'a mut Child,
pub(super) foreign_key: PersistedField<Child, ForeignKey, ForeignMeta, RequiredField>,
}
pub struct NullableMorphToMutBuilder<'a, Child: Draftable, ForeignKey, ForeignMeta: crate::TypeMeta>
{
pub(super) child: &'a mut Child,
pub(super) foreign_key: PersistedField<Child, Option<ForeignKey>, ForeignMeta, NullableField>,
}
pub struct MorphToTypeBuilder<'a, Child, ForeignField, MorphField> {
pub(super) child: &'a Child,
pub(super) foreign_key: ForeignField,
pub(super) morph_type: MorphField,
}
pub struct MorphToMutTypeBuilder<'a, Child: Draftable, ForeignField, MorphField> {
pub(super) child: &'a mut Child,
pub(super) foreign_key: ForeignField,
pub(super) morph_type: MorphField,
}
pub struct BuiltMorphTo<'a, Child, ForeignField, MorphField> {
pub(super) child: &'a Child,
pub(super) foreign_key: ForeignField,
pub(super) morph_type: MorphField,
pub(super) targets: Vec<MorphToTargetSpec<Child, ForeignField>>,
}
pub struct BuiltMorphToMut<'a, Child: Draftable, ForeignField, MorphField> {
pub(super) child: &'a mut Child,
pub(super) foreign_key: ForeignField,
pub(super) morph_type: MorphField,
pub(super) targets: Vec<MorphToMutTargetSpec<Child, ForeignField>>,
}
pub struct MorphToTargetBuilder<'a, Child, ForeignField, MorphField, Parent, OwnerField> {
pub(super) child: &'a Child,
pub(super) foreign_key: ForeignField,
pub(super) morph_type: MorphField,
pub(super) targets: Vec<MorphToTargetSpec<Child, ForeignField>>,
pub(super) morph_name: &'static str,
pub(super) owner_key: OwnerField,
pub(super) _marker: PhantomData<Parent>,
}
pub struct MorphToMutTargetBuilder<
'a,
Child: Draftable,
ForeignField,
MorphField,
Parent,
OwnerField,
> {
pub(super) child: &'a mut Child,
pub(super) foreign_key: ForeignField,
pub(super) morph_type: MorphField,
pub(super) targets: Vec<MorphToMutTargetSpec<Child, ForeignField>>,
pub(super) morph_name: &'static str,
pub(super) owner_key: OwnerField,
pub(super) _marker: PhantomData<Parent>,
}
pub struct BuiltBelongsTo<
'a,
Child,
Parent,
ForeignKey,
ForeignMeta: crate::TypeMeta,
OwnerKey,
OwnerMeta: crate::TypeMeta,
OwnerField,
> {
pub(super) child: &'a Child,
pub(super) foreign_key: PersistedField<Child, ForeignKey, ForeignMeta, RequiredField>,
pub(super) owner_key: OwnerField,
pub(super) _marker: PhantomData<(Parent, OwnerKey, OwnerMeta)>,
}
pub struct BuiltNullableBelongsTo<
'a,
Child,
Parent,
ForeignKey,
ForeignMeta: crate::TypeMeta,
OwnerKey,
OwnerMeta: crate::TypeMeta,
OwnerField,
> {
pub(super) child: &'a Child,
pub(super) foreign_key: PersistedField<Child, Option<ForeignKey>, ForeignMeta, NullableField>,
pub(super) owner_key: OwnerField,
pub(super) _marker: PhantomData<(Parent, ForeignKey, OwnerKey, OwnerMeta)>,
}
pub struct BuiltBelongsToMut<
'a,
Child: Draftable,
Parent,
ForeignKey,
ForeignMeta: crate::TypeMeta,
OwnerKey,
OwnerMeta: crate::TypeMeta,
OwnerField,
> {
pub(super) child: &'a mut Child,
pub(super) foreign_key: PersistedField<Child, ForeignKey, ForeignMeta, RequiredField>,
pub(super) owner_key: OwnerField,
pub(super) _marker: PhantomData<(Parent, OwnerKey, OwnerMeta)>,
}
pub struct BuiltNullableBelongsToMut<
'a,
Child: Draftable,
Parent,
ForeignKey,
ForeignMeta: crate::TypeMeta,
OwnerKey,
OwnerMeta: crate::TypeMeta,
OwnerField,
> {
pub(super) child: &'a mut Child,
pub(super) foreign_key: PersistedField<Child, Option<ForeignKey>, ForeignMeta, NullableField>,
pub(super) owner_key: OwnerField,
pub(super) _marker: PhantomData<(Parent, ForeignKey, OwnerKey, OwnerMeta)>,
}
pub struct HasManyFieldsBuilder<'a, Parent, Child, ForeignField> {
pub(super) parent: &'a Parent,
pub(super) foreign_key: ForeignField,
pub(super) _marker: PhantomData<Child>,
}
pub struct HasOneFieldsBuilder<'a, Parent, Child, ForeignField> {
pub(super) parent: &'a Parent,
pub(super) foreign_key: ForeignField,
pub(super) _marker: PhantomData<Child>,
}
pub struct BuiltHasMany<'a, Parent, Child, ForeignField, LocalField> {
pub(super) parent: &'a Parent,
pub(super) foreign_key: ForeignField,
pub(super) local_key: LocalField,
pub(super) _marker: PhantomData<Child>,
}
pub struct BuiltHasOne<'a, Parent, Child, ForeignField, LocalField> {
pub(super) parent: &'a Parent,
pub(super) foreign_key: ForeignField,
pub(super) local_key: LocalField,
pub(super) _marker: PhantomData<Child>,
}
pub struct MaxByOfMany<Relation, Child, SortMeta: crate::TypeMeta> {
pub(super) relation: Relation,
pub(super) column: expression::Column<Child, SortMeta>,
pub(super) _marker: PhantomData<Child>,
}
pub struct MinByOfMany<Relation, Child, SortMeta: crate::TypeMeta> {
pub(super) relation: Relation,
pub(super) column: expression::Column<Child, SortMeta>,
pub(super) _marker: PhantomData<Child>,
}
pub struct MorphManyFieldsBuilder<'a, Parent, Child, ForeignField> {
pub(super) parent: &'a Parent,
pub(super) foreign_key: ForeignField,
pub(super) _marker: PhantomData<Child>,
}
pub struct MorphOneFieldsBuilder<'a, Parent, Child, ForeignField> {
pub(super) parent: &'a Parent,
pub(super) foreign_key: ForeignField,
pub(super) _marker: PhantomData<Child>,
}
pub struct MorphManyTypeBuilder<'a, Parent, Child, ForeignField, MorphField> {
pub(super) parent: &'a Parent,
pub(super) foreign_key: ForeignField,
pub(super) morph_type: MorphField,
pub(super) _marker: PhantomData<Child>,
}
pub struct MorphOneTypeBuilder<'a, Parent, Child, ForeignField, MorphField> {
pub(super) parent: &'a Parent,
pub(super) foreign_key: ForeignField,
pub(super) morph_type: MorphField,
pub(super) _marker: PhantomData<Child>,
}
pub struct MorphManyLocalKeyBuilder<'a, Parent, Child, ForeignField, MorphField, LocalField> {
pub(super) parent: &'a Parent,
pub(super) foreign_key: ForeignField,
pub(super) morph_type: MorphField,
pub(super) local_key: LocalField,
pub(super) _marker: PhantomData<Child>,
}
pub struct MorphOneLocalKeyBuilder<'a, Parent, Child, ForeignField, MorphField, LocalField> {
pub(super) parent: &'a Parent,
pub(super) foreign_key: ForeignField,
pub(super) morph_type: MorphField,
pub(super) local_key: LocalField,
pub(super) _marker: PhantomData<Child>,
}
pub struct BuiltMorphMany<'a, Parent, Child, ForeignField, MorphField, LocalField> {
pub(super) parent: &'a Parent,
pub(super) foreign_key: ForeignField,
pub(super) morph_type: MorphField,
pub(super) local_key: LocalField,
pub(super) morph_name: &'static str,
pub(super) _marker: PhantomData<Child>,
}
pub struct BuiltMorphOne<'a, Parent, Child, ForeignField, MorphField, LocalField> {
pub(super) parent: &'a Parent,
pub(super) foreign_key: ForeignField,
pub(super) morph_type: MorphField,
pub(super) local_key: LocalField,
pub(super) morph_name: &'static str,
pub(super) _marker: PhantomData<Child>,
}
impl<'a, Child> BelongsToBuilder<'a, Child> {
pub fn foreign_key<Field>(self, field: Field) -> Field::Output
where
Field: IntoBelongsToBuilder<'a, Child>,
{
field.into_builder(self.child)
}
}
impl<'a, Child: Draftable> BelongsToMutBuilder<'a, Child> {
pub fn foreign_key<Field>(self, field: Field) -> Field::Output
where
Field: IntoBelongsToMutBuilder<'a, Child>,
{
field.into_builder(self.child)
}
}
impl<'a, Child> MorphToBuilder<'a, Child> {
pub fn morph_id<Field>(self, field: Field) -> Field::Output
where
Field: IntoMorphToBuilder<'a, Child>,
{
field.into_builder(self.child)
}
}
impl<'a, Child: Draftable> MorphToMutBuilder<'a, Child> {
pub fn morph_id<Field>(self, field: Field) -> Field::Output
where
Field: IntoMorphToMutBuilder<'a, Child>,
{
field.into_builder(self.child)
}
}
impl<'a, Parent> BelongsToManyBuilder<'a, Parent> {
pub fn pivot<Pivot>(self) -> BelongsToManyPivotBuilder<'a, Parent, Pivot>
where
Pivot: Qrafting,
{
BelongsToManyPivotBuilder {
parent: self.parent,
pivot_table: query::Table::new(Pivot::TABLE),
}
}
}
impl<'a, Parent> MorphToManyBuilder<'a, Parent> {
pub fn pivot<Pivot>(self) -> MorphToManyPivotBuilder<'a, Parent, Pivot>
where
Pivot: Qrafting,
{
MorphToManyPivotBuilder {
parent: self.parent,
pivot_table: query::Table::new(Pivot::TABLE),
}
}
}
impl<'a, Parent> MorphedByManyBuilder<'a, Parent> {
pub fn pivot<Pivot>(self) -> MorphedByManyPivotBuilder<'a, Parent, Pivot>
where
Pivot: Qrafting,
{
MorphedByManyPivotBuilder {
parent: self.parent,
pivot_table: query::Table::new(Pivot::TABLE),
}
}
}
impl<'a, Parent, Pivot> BelongsToManyPivotBuilder<'a, Parent, Pivot> {
pub fn parent_key<ParentMeta: crate::TypeMeta>(
self,
parent_key: expression::Column<Pivot, ParentMeta>,
) -> BelongsToManyParentKeyBuilder<'a, Parent, Pivot, ParentMeta> {
BelongsToManyParentKeyBuilder {
parent: self.parent,
pivot_table: self.pivot_table,
parent_key,
}
}
}
impl<'a, Parent, Pivot> MorphToManyPivotBuilder<'a, Parent, Pivot> {
pub fn parent_key<ParentMeta: crate::TypeMeta>(
self,
parent_key: expression::Column<Pivot, ParentMeta>,
) -> MorphToManyParentKeyBuilder<'a, Parent, Pivot, ParentMeta> {
MorphToManyParentKeyBuilder {
parent: self.parent,
pivot_table: self.pivot_table,
parent_key,
}
}
}
impl<'a, Parent, Pivot> MorphedByManyPivotBuilder<'a, Parent, Pivot> {
pub fn parent_key<ParentMeta: crate::TypeMeta>(
self,
parent_key: expression::Column<Pivot, ParentMeta>,
) -> MorphedByManyParentKeyBuilder<'a, Parent, Pivot, ParentMeta> {
MorphedByManyParentKeyBuilder {
parent: self.parent,
pivot_table: self.pivot_table,
parent_key,
}
}
}
impl<'a, Parent, Pivot, ParentMeta: crate::TypeMeta>
BelongsToManyParentKeyBuilder<'a, Parent, Pivot, ParentMeta>
{
pub fn related_key<RelatedMeta: crate::TypeMeta>(
self,
related_key: expression::Column<Pivot, RelatedMeta>,
) -> BelongsToManyRelatedKeyBuilder<'a, Parent, Pivot, ParentMeta, RelatedMeta> {
BelongsToManyRelatedKeyBuilder {
parent: self.parent,
pivot_table: self.pivot_table,
parent_key: self.parent_key,
related_key,
}
}
}
impl<'a, Parent, Pivot, ParentMeta: crate::TypeMeta>
MorphToManyParentKeyBuilder<'a, Parent, Pivot, ParentMeta>
{
pub fn morph_type(
self,
morph_type: expression::Column<Pivot, crate::Text>,
) -> MorphToManyTypeBuilder<'a, Parent, Pivot, ParentMeta> {
MorphToManyTypeBuilder {
parent: self.parent,
pivot_table: self.pivot_table,
parent_key: self.parent_key,
morph_type,
}
}
}
impl<'a, Parent, Pivot, ParentMeta: crate::TypeMeta>
MorphedByManyParentKeyBuilder<'a, Parent, Pivot, ParentMeta>
{
pub fn morph_type(
self,
morph_type: expression::Column<Pivot, crate::Text>,
) -> MorphedByManyTypeBuilder<'a, Parent, Pivot, ParentMeta> {
MorphedByManyTypeBuilder {
parent: self.parent,
pivot_table: self.pivot_table,
parent_key: self.parent_key,
morph_type,
}
}
}
impl<'a, Parent, Pivot, ParentMeta: crate::TypeMeta, RelatedMeta: crate::TypeMeta>
BelongsToManyRelatedKeyBuilder<'a, Parent, Pivot, ParentMeta, RelatedMeta>
{
pub fn local_key<LocalField>(
self,
local_key: LocalField,
) -> BuiltBelongsToMany<'a, Parent, Pivot, ParentMeta, RelatedMeta, LocalField> {
BuiltBelongsToMany {
parent: self.parent,
pivot_table: self.pivot_table,
parent_key: self.parent_key,
related_key: self.related_key,
local_key,
}
}
}
impl<'a, Parent, Pivot, ParentMeta: crate::TypeMeta>
MorphToManyTypeBuilder<'a, Parent, Pivot, ParentMeta>
{
pub fn related_key<RelatedMeta: crate::TypeMeta>(
self,
related_key: expression::Column<Pivot, RelatedMeta>,
) -> MorphToManyRelatedKeyBuilder<'a, Parent, Pivot, ParentMeta, RelatedMeta> {
MorphToManyRelatedKeyBuilder {
parent: self.parent,
pivot_table: self.pivot_table,
parent_key: self.parent_key,
morph_type: self.morph_type,
related_key,
morph_name: None,
}
}
}
impl<'a, Parent, Pivot, ParentMeta: crate::TypeMeta>
MorphedByManyTypeBuilder<'a, Parent, Pivot, ParentMeta>
{
pub fn related_key<RelatedMeta: crate::TypeMeta>(
self,
related_key: expression::Column<Pivot, RelatedMeta>,
) -> MorphedByManyRelatedKeyBuilder<'a, Parent, Pivot, ParentMeta, RelatedMeta> {
MorphedByManyRelatedKeyBuilder {
parent: self.parent,
pivot_table: self.pivot_table,
parent_key: self.parent_key,
morph_type: self.morph_type,
related_key,
morph_name: None,
}
}
}
impl<'a, Parent, Pivot, ParentMeta: crate::TypeMeta, RelatedMeta: crate::TypeMeta>
MorphToManyRelatedKeyBuilder<'a, Parent, Pivot, ParentMeta, RelatedMeta>
{
pub fn local_key<LocalField>(
self,
local_key: LocalField,
) -> BuiltMorphToMany<'a, Parent, Pivot, ParentMeta, RelatedMeta, LocalField> {
BuiltMorphToMany {
parent: self.parent,
pivot_table: self.pivot_table,
parent_key: self.parent_key,
morph_type: self.morph_type,
related_key: self.related_key,
local_key,
morph_name: self.morph_name,
}
}
pub fn morph_name(self, morph_name: &'static str) -> Self {
Self {
morph_name: Some(morph_name),
..self
}
}
}
impl<'a, Parent, Pivot, ParentMeta: crate::TypeMeta, RelatedMeta: crate::TypeMeta>
MorphedByManyRelatedKeyBuilder<'a, Parent, Pivot, ParentMeta, RelatedMeta>
{
pub fn local_key<LocalField>(
self,
local_key: LocalField,
) -> BuiltMorphedByMany<'a, Parent, Pivot, ParentMeta, RelatedMeta, LocalField> {
BuiltMorphedByMany {
parent: self.parent,
pivot_table: self.pivot_table,
parent_key: self.parent_key,
morph_type: self.morph_type,
related_key: self.related_key,
local_key,
morph_name: self.morph_name,
}
}
pub fn morph_name(self, morph_name: &'static str) -> Self {
Self {
morph_name: Some(morph_name),
..self
}
}
}
impl<'a, Parent, Pivot, ParentMeta: crate::TypeMeta, RelatedMeta: crate::TypeMeta, LocalField>
BuiltMorphToMany<'a, Parent, Pivot, ParentMeta, RelatedMeta, LocalField>
{
pub fn morph_name(self, morph_name: &'static str) -> Self {
Self {
morph_name: Some(morph_name),
..self
}
}
}
impl<'a, Parent, Pivot, ParentMeta: crate::TypeMeta, RelatedMeta: crate::TypeMeta, LocalField>
BuiltMorphedByMany<'a, Parent, Pivot, ParentMeta, RelatedMeta, LocalField>
{
pub fn morph_name(self, morph_name: &'static str) -> Self {
Self {
morph_name: Some(morph_name),
..self
}
}
}
impl<'a, Parent> HasManyBuilder<'a, Parent> {
pub fn foreign_key<Field>(self, field: Field) -> Field::Output
where
Field: IntoHasManyBuilder<'a, Parent>,
{
field.into_builder(self.parent)
}
}
impl<'a, Parent> HasOneBuilder<'a, Parent> {
pub fn foreign_key<Field>(self, field: Field) -> Field::Output
where
Field: IntoHasOneBuilder<'a, Parent>,
{
field.into_builder(self.parent)
}
}
impl<'a, Parent> MorphManyBuilder<'a, Parent> {
pub fn foreign_key<Field>(self, field: Field) -> Field::Output
where
Field: IntoMorphManyBuilder<'a, Parent>,
{
field.into_builder(self.parent)
}
}
impl<'a, Parent> MorphOneBuilder<'a, Parent> {
pub fn foreign_key<Field>(self, field: Field) -> Field::Output
where
Field: IntoMorphOneBuilder<'a, Parent>,
{
field.into_builder(self.parent)
}
}
impl<'a, Child: 'a, ForeignKey, ForeignMeta: crate::TypeMeta> IntoBelongsToBuilder<'a, Child>
for PersistedField<Child, ForeignKey, ForeignMeta, RequiredField>
{
type Output = RequiredBelongsToBuilder<'a, Child, ForeignKey, ForeignMeta>;
fn into_builder(self, child: &'a Child) -> Self::Output {
RequiredBelongsToBuilder {
child,
foreign_key: self,
}
}
}
impl<'a, Child: 'a, ForeignKey, ForeignMeta: crate::TypeMeta> IntoBelongsToBuilder<'a, Child>
for PersistedField<Child, Option<ForeignKey>, ForeignMeta, NullableField>
{
type Output = NullableBelongsToBuilderImpl<'a, Child, ForeignKey, ForeignMeta>;
fn into_builder(self, child: &'a Child) -> Self::Output {
NullableBelongsToBuilderImpl {
child,
foreign_key: self,
}
}
}
impl<'a, Child: Draftable + 'a, ForeignKey, ForeignMeta: crate::TypeMeta>
IntoBelongsToMutBuilder<'a, Child>
for PersistedField<Child, ForeignKey, ForeignMeta, RequiredField>
{
type Output = RequiredBelongsToMutBuilder<'a, Child, ForeignKey, ForeignMeta>;
fn into_builder(self, child: &'a mut Child) -> Self::Output {
RequiredBelongsToMutBuilder {
child,
foreign_key: self,
}
}
}
impl<'a, Child: 'a, ForeignKey, ForeignMeta: crate::TypeMeta> IntoMorphToBuilder<'a, Child>
for PersistedField<Child, ForeignKey, ForeignMeta, RequiredField>
{
type Output = RequiredMorphToBuilder<'a, Child, ForeignKey, ForeignMeta>;
fn into_builder(self, child: &'a Child) -> Self::Output {
RequiredMorphToBuilder {
child,
foreign_key: self,
}
}
}
impl<'a, Child: 'a, ForeignKey, ForeignMeta: crate::TypeMeta> IntoMorphToBuilder<'a, Child>
for PersistedField<Child, Option<ForeignKey>, ForeignMeta, NullableField>
{
type Output = NullableMorphToBuilder<'a, Child, ForeignKey, ForeignMeta>;
fn into_builder(self, child: &'a Child) -> Self::Output {
NullableMorphToBuilder {
child,
foreign_key: self,
}
}
}
impl<'a, Child: Draftable + 'a, ForeignKey, ForeignMeta: crate::TypeMeta>
IntoMorphToMutBuilder<'a, Child>
for PersistedField<Child, ForeignKey, ForeignMeta, RequiredField>
{
type Output = RequiredMorphToMutBuilder<'a, Child, ForeignKey, ForeignMeta>;
fn into_builder(self, child: &'a mut Child) -> Self::Output {
RequiredMorphToMutBuilder {
child,
foreign_key: self,
}
}
}
impl<'a, Child: Draftable + 'a, ForeignKey, ForeignMeta: crate::TypeMeta>
IntoMorphToMutBuilder<'a, Child>
for PersistedField<Child, Option<ForeignKey>, ForeignMeta, NullableField>
{
type Output = NullableMorphToMutBuilder<'a, Child, ForeignKey, ForeignMeta>;
fn into_builder(self, child: &'a mut Child) -> Self::Output {
NullableMorphToMutBuilder {
child,
foreign_key: self,
}
}
}
impl<'a, Parent: 'a, Child, ForeignValue, ForeignMeta: crate::TypeMeta, Kind>
IntoHasManyBuilder<'a, Parent> for PersistedField<Child, ForeignValue, ForeignMeta, Kind>
{
type Output = HasManyFieldsBuilder<
'a,
Parent,
Child,
PersistedField<Child, ForeignValue, ForeignMeta, Kind>,
>;
fn into_builder(self, parent: &'a Parent) -> Self::Output {
HasManyFieldsBuilder {
parent,
foreign_key: self,
_marker: PhantomData,
}
}
}
impl<'a, Parent: 'a, Child, ForeignValue, ForeignMeta: crate::TypeMeta, Kind>
IntoHasOneBuilder<'a, Parent> for PersistedField<Child, ForeignValue, ForeignMeta, Kind>
{
type Output = HasOneFieldsBuilder<
'a,
Parent,
Child,
PersistedField<Child, ForeignValue, ForeignMeta, Kind>,
>;
fn into_builder(self, parent: &'a Parent) -> Self::Output {
HasOneFieldsBuilder {
parent,
foreign_key: self,
_marker: PhantomData,
}
}
}
impl<'a, Parent: 'a, Child, ForeignValue, ForeignMeta: crate::TypeMeta, Kind>
IntoMorphManyBuilder<'a, Parent> for PersistedField<Child, ForeignValue, ForeignMeta, Kind>
{
type Output = MorphManyFieldsBuilder<
'a,
Parent,
Child,
PersistedField<Child, ForeignValue, ForeignMeta, Kind>,
>;
fn into_builder(self, parent: &'a Parent) -> Self::Output {
MorphManyFieldsBuilder {
parent,
foreign_key: self,
_marker: PhantomData,
}
}
}
impl<'a, Parent: 'a, Child, ForeignValue, ForeignMeta: crate::TypeMeta, Kind>
IntoMorphOneBuilder<'a, Parent> for PersistedField<Child, ForeignValue, ForeignMeta, Kind>
{
type Output = MorphOneFieldsBuilder<
'a,
Parent,
Child,
PersistedField<Child, ForeignValue, ForeignMeta, Kind>,
>;
fn into_builder(self, parent: &'a Parent) -> Self::Output {
MorphOneFieldsBuilder {
parent,
foreign_key: self,
_marker: PhantomData,
}
}
}
impl<'a, Child: Draftable + 'a, ForeignKey, ForeignMeta: crate::TypeMeta>
IntoBelongsToMutBuilder<'a, Child>
for PersistedField<Child, Option<ForeignKey>, ForeignMeta, NullableField>
{
type Output = NullableBelongsToMutBuilderImpl<'a, Child, ForeignKey, ForeignMeta>;
fn into_builder(self, child: &'a mut Child) -> Self::Output {
NullableBelongsToMutBuilderImpl {
child,
foreign_key: self,
}
}
}
pub(super) fn model_key_field<Parent>() -> ModelField<
Parent,
<Parent as ModelKey>::Key,
<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta,
>
where
Parent: ModelKey,
<Parent as ModelKey>::Key: crate::DefaultMeta,
{
ModelField::new(
expression::Column::new(<Parent as ModelKey>::__qraft_key_column()),
<Parent as ModelKey>::__qraft_key,
)
}
pub(super) fn build_belongs_to_many_query<
Parent,
Pivot,
Related,
ParentMeta,
RelatedMeta,
LocalField,
>(
parent: &Parent,
pivot_table: query::Table<Pivot>,
parent_key: expression::Column<Pivot, ParentMeta>,
related_key: expression::Column<Pivot, RelatedMeta>,
local_key: LocalField,
) -> QueryOf<Related>
where
Parent: Qrafting,
Pivot: Qrafting,
Related: Qrafting + FromRow + ModelKey,
<Related as ModelKey>::Key: crate::DefaultMeta,
<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta: Comparable + crate::Nullability,
crate::expression::As<expression::Column<Pivot, RelatedMeta>>:
crate::LowerCompatible<<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta>,
LocalField: ReadableFieldInfo<Parent>
+ ReadableField<
Parent,
<LocalField as ReadableFieldInfo<Parent>>::Value,
<LocalField as ReadableFieldInfo<Parent>>::Meta,
> + Copy,
<LocalField as ReadableFieldInfo<Parent>>::Value: crate::Compatible<ParentMeta>,
ParentMeta: Comparable + crate::Nullability,
RelatedMeta: Comparable + crate::Nullability,
crate::BinaryType<crate::NullOf<ParentMeta>, crate::NullOf<ParentMeta>>: crate::PredicateType,
crate::BinaryType<
crate::NullOf<<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta>,
crate::NullOf<<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta>,
>: crate::PredicateType,
crate::BinaryType<crate::NullOf<RelatedMeta>, crate::NullOf<RelatedMeta>>: crate::PredicateType,
{
let pivot = pivot_table.alias("__qraft_belongs_to_many_pivot");
<Related as Qrafting>::__qraft_query()
.inner_join(
pivot.on(model_key_field::<Related>()
.column()
.eq(pivot.col(related_key))),
)
.filter(pivot.col(parent_key).eq((local_key.getter())(parent)))
}
pub(super) fn build_morph_to_many_query<
Parent,
Pivot,
Related,
ParentMeta,
RelatedMeta,
LocalField,
>(
parent: &Parent,
parts: MorphToManyQueryParts<Pivot, ParentMeta, RelatedMeta, LocalField>,
) -> QueryOf<Related>
where
Parent: Qrafting,
Pivot: Qrafting,
Related: Qrafting + FromRow + ModelKey,
<Related as ModelKey>::Key: crate::DefaultMeta,
<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta: Comparable + crate::Nullability,
crate::expression::As<expression::Column<Pivot, RelatedMeta>>:
crate::LowerCompatible<<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta>,
LocalField: ReadableFieldInfo<Parent>
+ ReadableField<
Parent,
<LocalField as ReadableFieldInfo<Parent>>::Value,
<LocalField as ReadableFieldInfo<Parent>>::Meta,
> + Copy,
<LocalField as ReadableFieldInfo<Parent>>::Value: crate::Compatible<ParentMeta>,
ParentMeta: Comparable + crate::Nullability,
RelatedMeta: Comparable + crate::Nullability,
&'static str: crate::LowerCompatible<crate::Text>,
crate::BinaryType<crate::NullOf<ParentMeta>, crate::NullOf<ParentMeta>>: crate::PredicateType,
crate::BinaryType<
crate::NullOf<<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta>,
crate::NullOf<<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta>,
>: crate::PredicateType,
crate::BinaryType<crate::NullOf<RelatedMeta>, crate::NullOf<RelatedMeta>>: crate::PredicateType,
crate::BinaryType<crate::NullOf<crate::Text>, crate::NullOf<crate::Text>>: crate::PredicateType,
{
let MorphToManyQueryParts {
pivot_table,
parent_key,
morph_type,
related_key,
local_key,
morph_name,
} = parts;
let pivot = pivot_table.alias("__qraft_morph_to_many_pivot");
<Related as Qrafting>::__qraft_query()
.inner_join(
pivot.on(model_key_field::<Related>()
.column()
.eq(pivot.col(related_key))),
)
.filter(pivot.col(parent_key).eq((local_key.getter())(parent)))
.filter(pivot.col(morph_type).eq(morph_name))
}
pub(super) struct MorphToManyQueryParts<Pivot, ParentMeta: crate::TypeMeta, RelatedMeta: crate::TypeMeta, LocalField> {
pub(super) pivot_table: query::Table<Pivot>,
pub(super) parent_key: expression::Column<Pivot, ParentMeta>,
pub(super) morph_type: expression::Column<Pivot, crate::Text>,
pub(super) related_key: expression::Column<Pivot, RelatedMeta>,
pub(super) local_key: LocalField,
pub(super) morph_name: &'static str,
}
struct SkipRelationFieldVisitor<'a, V> {
inner: &'a mut V,
fields: &'a [&'static str],
}
impl<'a, 'v, V> VisitParam<'v> for SkipRelationFieldVisitor<'a, V>
where
V: VisitParam<'v>,
{
fn param(&mut self, field: &'static str, param: impl quex::Encode) {
if self.fields.contains(&field) {
return;
}
self.inner.param(field, param)
}
fn param_typed<T>(
&mut self,
field: &'static str,
value: &'v (impl crate::Compatible<T> + ?Sized),
) where
T: crate::TypeMeta,
{
if self.fields.contains(&field) {
return;
}
self.inner.param_typed::<T>(field, value)
}
}
pub(super) struct InjectRelationValues<'a, Parent, V, ForeignField, LocalField> {
pub(super) parent: &'a Parent,
pub(super) values: V,
pub(super) foreign_key: ForeignField,
pub(super) local_key: LocalField,
}
impl<'a, Parent, Child, V, ForeignField, LocalField> Insertable<Child>
for InjectRelationValues<'a, Parent, V, ForeignField, LocalField>
where
Child: Qrafting,
V: Insertable<Child>,
ForeignField: ReadableFieldInfo<Child>
+ ReadableField<
Child,
<ForeignField as ReadableFieldInfo<Child>>::Value,
<ForeignField as ReadableFieldInfo<Child>>::Meta,
> + Copy,
LocalField: ReadableFieldInfo<Parent>
+ ReadableField<
Parent,
<LocalField as ReadableFieldInfo<Parent>>::Value,
<LocalField as ReadableFieldInfo<Parent>>::Meta,
> + Copy,
<LocalField as ReadableFieldInfo<Parent>>::Value:
crate::Compatible<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
{
fn values<'v>(&'v self, visitor: &mut impl VisitParam<'v>) {
let field = self.foreign_key.column().name();
visitor.param_typed::<<ForeignField as ReadableFieldInfo<Child>>::Meta>(
field,
(self.local_key.getter())(self.parent),
);
let mut visitor = SkipRelationFieldVisitor {
inner: visitor,
fields: &[field],
};
self.values.values(&mut visitor)
}
}