default-dest-table #676

Merged
philipp merged 4 commits from default-dest-table into staging 2024-08-18 20:53:09 +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 { impl Distance {
/// Return all default `distance`s, ordered by usage in logbook entries
pub async fn all(db: &SqlitePool) -> Vec<Self> { pub async fn all(db: &SqlitePool) -> Vec<Self> {
sqlx::query_as!( sqlx::query_as!(
Self, 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) .fetch_all(db)
.await .await

View File

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