pub struct OsvDb(/* private fields */);Implementations§
Source§impl OsvDb
impl OsvDb
Sourcepub fn new(
ecosystems: OsvGsEcosystems,
path: impl AsRef<Path>,
) -> Result<Self, OsvDbNewErr>
pub fn new( ecosystems: OsvGsEcosystems, path: impl AsRef<Path>, ) -> Result<Self, OsvDbNewErr>
Creates a new OsvDb rooted at path targeting the given ecosystems.
Pass OsvGsEcosystems::all to cover all ecosystems, or build a specific set
with OsvGsEcosystems::add.
If path does not exist it is created (including all parent directories).
§Errors
Sourcepub fn ecosystems(&self) -> &OsvGsEcosystems
pub fn ecosystems(&self) -> &OsvGsEcosystems
Returns the set of ecosystems this database targets.
An empty set (i.e. OsvGsEcosystems::is_all is true) means all ecosystems.
Sourcepub fn last_modified(&self) -> DateTime<Utc>
pub fn last_modified(&self) -> DateTime<Utc>
Returns the latest modified timestamp seen across all records in the database.
The value reflects the most recent download_latest or
sync call. Returns the Unix epoch if the database has not yet
been populated.
Sourcepub fn get_record(
&self,
id: &OsvRecordId,
) -> Result<Option<OsvRecord>, GetRecordErr>
pub fn get_record( &self, id: &OsvRecordId, ) -> Result<Option<OsvRecord>, GetRecordErr>
Looks up a single OSV record by its OsvRecordId.
Returns Ok(None) if no record matching id exists.
§Errors
Returns an error if the record file cannot be opened or deserialized.
Sourcepub fn records(
&self,
) -> Result<impl Iterator<Item = Result<OsvRecord, ReadRecordErr>> + Send, RecordsIterErr>
pub fn records( &self, ) -> Result<impl Iterator<Item = Result<OsvRecord, ReadRecordErr>> + Send, RecordsIterErr>
Sourcepub async fn download_latest(
&self,
chunk_size: u64,
) -> Result<(), DownloadLatestErr>
pub async fn download_latest( &self, chunk_size: u64, ) -> Result<(), DownloadLatestErr>
Downloads a full, latest OSV database for all configured ecosystems.
- For each targeted ecosystem (or the global archive when all ecosystems are
selected), downloads the latest archive into a temporary subdirectory of
locationand extracts all records into a single flat directory. - Atomically replaces the current records directory with the newly downloaded one.
- Updates
self.last_modifiedwith the maximummodifiedtimestamp seen across all targeted ecosystems.
Sourcepub async fn sync(
&self,
) -> Result<impl Iterator<Item = Result<OsvRecord, ReadRecordErr>> + Send, SyncErr>
pub async fn sync( &self, ) -> Result<impl Iterator<Item = Result<OsvRecord, ReadRecordErr>> + Send, SyncErr>
Sync with the latest OSV data, downloads only the records that have been modified
since Self::last_modified and updates the local database files
accordingly.
Fetches the modified_id.csv index for the configured ecosystem (or all
ecosystems if None). The file is sorted in reverse chronological order, so
parsing stops as soon as a timestamp at or before Self::last_modified is
encountered, avoiding a full re-download. After all new records are saved,
Self::last_modified is updated to the highest timestamp seen.
Returns an Iterator that yields each newly added or updated OsvRecord.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for OsvDb
impl RefUnwindSafe for OsvDb
impl Send for OsvDb
impl Sync for OsvDb
impl Unpin for OsvDb
impl UnsafeUnpin for OsvDb
impl UnwindSafe for OsvDb
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more