Skip to content

Commit 481b547

Browse files
committed
models/krate: Add async_top_versions() fn
1 parent a7d1ef4 commit 481b547

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/models/krate.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,24 @@ impl Crate {
341341
}
342342
}
343343

344+
/// Return both the newest (most recently updated) and
345+
/// highest version (in semver order) for the current crate,
346+
/// where all top versions are not yanked.
347+
pub async fn async_top_versions(
348+
&self,
349+
conn: &mut AsyncPgConnection,
350+
) -> QueryResult<TopVersions> {
351+
use diesel_async::RunQueryDsl;
352+
353+
Ok(TopVersions::from_date_version_pairs(
354+
Version::belonging_to(self)
355+
.filter(versions::yanked.eq(false))
356+
.select((versions::created_at, versions::num))
357+
.load(conn)
358+
.await?,
359+
))
360+
}
361+
344362
/// Return both the newest (most recently updated) and
345363
/// highest version (in semver order) for the current crate,
346364
/// where all top versions are not yanked.

0 commit comments

Comments
 (0)