default-dest-table #677
@ -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
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user