Skip to content

Commit 7848017

Browse files
committed
store: Combine ChildKey::IdAsc and ChildKey::IdDesc
1 parent 4f2b3f8 commit 7848017

File tree

1 file changed

+25
-60
lines changed

1 file changed

+25
-60
lines changed

store/postgres/src/relational_queries.rs

Lines changed: 25 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3111,8 +3111,7 @@ pub enum ChildKey<'a> {
31113111
Single(ChildKeyDetails<'a>),
31123112
/// First column is the primary key of the parent
31133113
Many(dsl::Column<'a>, Vec<ChildKeyDetails<'a>>),
3114-
IdAsc(ChildIdDetails<'a>, UseBlockColumn),
3115-
IdDesc(ChildIdDetails<'a>, UseBlockColumn),
3114+
Id(SortDirection, ChildIdDetails<'a>, UseBlockColumn),
31163115
ManyIdAsc(Vec<ChildIdDetails<'a>>, UseBlockColumn),
31173116
ManyIdDesc(Vec<ChildIdDetails<'a>>, UseBlockColumn),
31183117
}
@@ -3204,24 +3203,13 @@ impl<'a> fmt::Display for SortKey<'a> {
32043203
})
32053204
}
32063205

3207-
ChildKey::IdAsc(details, UseBlockColumn::No) => {
3208-
write!(f, "{}", details.child_table.primary_key())
3206+
ChildKey::Id(direction, details, UseBlockColumn::No) => {
3207+
write!(f, "{}{}", details.child_table.primary_key(), direction)
32093208
}
3210-
ChildKey::IdAsc(details, UseBlockColumn::Yes) => {
3209+
ChildKey::Id(direction, details, UseBlockColumn::Yes) => {
32113210
write!(
32123211
f,
3213-
"{}, {}",
3214-
details.child_table.primary_key(),
3215-
details.child_br
3216-
)
3217-
}
3218-
ChildKey::IdDesc(details, UseBlockColumn::No) => {
3219-
write!(f, "{} desc", details.child_table.primary_key(),)
3220-
}
3221-
ChildKey::IdDesc(details, UseBlockColumn::Yes) => {
3222-
write!(
3223-
f,
3224-
"{} desc, {} desc",
3212+
"{}{direction}, {}{direction}",
32253213
details.child_table.primary_key(),
32263214
details.child_br
32273215
)
@@ -3357,33 +3345,20 @@ impl<'a> SortKey<'a> {
33573345
let child_pk = child_table.primary_key();
33583346
let child_br = child_table.block_column();
33593347
let child_at_block = child_table.at_block(block);
3360-
use SortDirection::*;
3361-
return match direction {
3362-
Asc => Ok(SortKey::ChildKey(ChildKey::IdAsc(
3363-
ChildIdDetails {
3364-
child_table,
3365-
child_from,
3366-
parent_join_column: parent_column,
3367-
child_join_column: child_column,
3368-
child_pk,
3369-
child_br,
3370-
child_at_block,
3371-
},
3372-
use_block_column,
3373-
))),
3374-
Desc => Ok(SortKey::ChildKey(ChildKey::IdDesc(
3375-
ChildIdDetails {
3376-
child_table,
3377-
child_from,
3378-
parent_join_column: parent_column,
3379-
child_join_column: child_column,
3380-
child_pk,
3381-
child_br,
3382-
child_at_block,
3383-
},
3384-
use_block_column,
3385-
))),
3386-
};
3348+
3349+
return Ok(SortKey::ChildKey(ChildKey::Id(
3350+
direction,
3351+
ChildIdDetails {
3352+
child_table,
3353+
child_from,
3354+
parent_join_column: parent_column,
3355+
child_join_column: child_column,
3356+
child_pk,
3357+
child_br,
3358+
child_at_block,
3359+
},
3360+
use_block_column,
3361+
)));
33873362
}
33883363

33893364
let child_table = child_table.child(1);
@@ -3716,13 +3691,11 @@ impl<'a> SortKey<'a> {
37163691
}
37173692
ChildKey::ManyIdAsc(_, UseBlockColumn::No)
37183693
| ChildKey::ManyIdDesc(_, UseBlockColumn::No) => { /* nothing to do */ }
3719-
ChildKey::IdAsc(child, UseBlockColumn::Yes)
3720-
| ChildKey::IdDesc(child, UseBlockColumn::Yes) => {
3694+
ChildKey::Id(_, child, UseBlockColumn::Yes) => {
37213695
out.push_sql(", ");
37223696
child.child_br.walk_ast(out.reborrow())?;
37233697
}
3724-
ChildKey::IdAsc(_, UseBlockColumn::No)
3725-
| ChildKey::IdDesc(_, UseBlockColumn::No) => { /* nothing to do */ }
3698+
ChildKey::Id(_, _, UseBlockColumn::No) => { /* nothing to do */ }
37263699
}
37273700

37283701
if let SelectStatementLevel::InnerStatement = select_statement_level {
@@ -3793,21 +3766,13 @@ impl<'a> SortKey<'a> {
37933766
SortKey::multi_sort_id_expr(children, Desc, *use_block_column, out)
37943767
}
37953768

3796-
ChildKey::IdAsc(child, use_block_column) => {
3797-
child.child_pk.walk_ast(out.reborrow())?;
3798-
if UseBlockColumn::Yes == *use_block_column {
3799-
out.push_sql(", ");
3800-
child.child_br.walk_ast(out.reborrow())?;
3801-
}
3802-
Ok(())
3803-
}
3804-
ChildKey::IdDesc(child, use_block_column) => {
3769+
ChildKey::Id(direction, child, use_block_column) => {
38053770
child.child_pk.walk_ast(out.reborrow())?;
3806-
out.push_sql(" desc");
3771+
out.push_sql(direction.as_sql());
38073772
if UseBlockColumn::Yes == *use_block_column {
38083773
out.push_sql(", ");
38093774
child.child_br.walk_ast(out.reborrow())?;
3810-
out.push_sql(" desc");
3775+
out.push_sql(direction.as_sql());
38113776
}
38123777
Ok(())
38133778
}
@@ -4075,7 +4040,7 @@ impl<'a> SortKey<'a> {
40754040
)?;
40764041
}
40774042
}
4078-
ChildKey::IdAsc(child, _) | ChildKey::IdDesc(child, _) => {
4043+
ChildKey::Id(_, child, _) => {
40794044
add(
40804045
&child.child_from,
40814046
&child.child_join_column,

0 commit comments

Comments
 (0)