audiot_core 0.2.0

Library that helps build the search database through the CLI, and eventually can be used to read data from that same database.
Documentation
use log::debug;
use rusqlite::{Connection, params};

use crate::brainz::Release;

pub fn batch_insert_release_urls(conn: &mut Connection, batch: &[Release]) {
    let tx = conn.transaction().unwrap();

    debug!("Starting writing batch urls to SQLite");

    for release in batch.iter() {
        let url_insert = "insert or ignore into release_group_urls (release_group_id, url_id, url, url_type) values (?1, ?2, ?3, ?4)";

        for url_relation in release.streaming_urls().into_iter() {
            tx.execute(
                url_insert,
                params![
                    &release.release_group_id(),
                    &url_relation.url.id,
                    &url_relation.url.resource,
                    &url_relation.relation_type
                ],
            )
            .unwrap();
        }
    }

    debug!("Finished writing batch urls to SQLite");

    tx.commit().unwrap();
}