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