default-dest-table #677

Merged
philipp merged 3 commits from default-dest-table into main 2024-08-18 20:53:11 +02:00
2 changed files with 15 additions and 2 deletions
Showing only changes of commit d7e5731753 - Show all commits

View File

@ -9,10 +9,22 @@ pub struct Distance {
}
impl Distance {
/// Return all default `distance`s, ordered by usage in logbook entries
pub async fn all(db: &SqlitePool) -> Vec<Self> {
sqlx::query_as!(
Self,
"SELECT id, destination, distance_in_km FROM distance;"
"SELECT
d.id,
d.destination,
d.distance_in_km
FROM
distance d
LEFT JOIN
logbook l ON d.destination = l.destination AND d.distance_in_km = l.distance_in_km
GROUP BY
d.id, d.destination, d.distance_in_km
ORDER BY
COUNT(l.id) DESC, d.destination ASC;"
)
.fetch_all(db)
.await

View File

@ -53,7 +53,8 @@
id="destination"
name="destination"
value=""
data-relation="distance_in_km" />
data-relation="distance_in_km"
autocomplete="off" />
<datalist id="destinations">
{% for distance in distances %}<option value="{{ distance.destination }}" distance="{{ distance.distance_in_km}}" />{% endfor %}
</datalist>