Struct db_dump::Loader[][src]

pub struct Loader<'a> { /* fields omitted */ }
Expand description

Perform a streaming load of only relevant database tables.

Example

This example loads just the version_downloads.csv table, in which each row is the download count for a single version of a single crate on a single day. We do not store the rows individually in memory but instead stream from the csv to accumulate just a total count per day across all crates, which requires far less memory.

use chrono::NaiveDate;
use std::collections::BTreeMap as Map;

fn main() -> db_dump::Result<()> {
    let mut downloads = Map::<NaiveDate, u64>::new();
    db_dump::Loader::new()
        .version_downloads(|row| {
            *downloads.entry(row.date).or_default() += row.downloads;
        })
        .load("./db-dump.tar.gz")?;

    for (date, count) in downloads {
        println!("{},{}", date, count);
    }

    Ok(())
}

Implementations

Trait Implementations

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.