show track locations from mixxx db

This commit is contained in:
crunk 2024-04-02 17:35:06 +02:00
parent cf2d560ac7
commit 64a8fe77be
5 changed files with 39 additions and 7 deletions

View File

@ -1,2 +1,3 @@
[print_schema] [print_schema]
generate_missing_sql_type_definitions = true
filter = { only_tables = ["library", "track_locations"] } filter = { only_tables = ["library", "track_locations"] }

View File

@ -1,13 +1,12 @@
use diesel::prelude::*;
use diesel::sqlite::SqliteConnection; use diesel::sqlite::SqliteConnection;
use diesel::Connection;
use dotenvy::dotenv; use dotenvy::dotenv;
use std::env; use std::env;
pub mod schema;
pub fn establish_connection() -> SqliteConnection { pub fn establish_connection() -> SqliteConnection {
dotenv().ok(); dotenv().ok();
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set"); let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
SqliteConnection::establish(&database_url) SqliteConnection::establish(&database_url)
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url)) .expect(&format!("Error connecting to {}", database_url))
} }

View File

@ -1,3 +1,24 @@
use crate::db::establish_connection;
use crate::models::TrackLocations;
use diesel::prelude::*;
mod db;
mod models;
mod schema;
fn main() { fn main() {
println!("Hello, world!"); use schema::track_locations::dsl::*;
let mut connection = establish_connection();
let results = track_locations
.limit(5)
.load::<TrackLocations>(&mut connection)
.expect("Error loading track locations");
println!("Displaying {} tracks", results.len());
for track in results {
println!("{:?}", track.location);
println!("-----------\n");
println!("{:?}", track.directory);
}
} }

View File

@ -0,0 +1,14 @@
use diesel::prelude::*;
#[derive(Queryable, Selectable)]
#[diesel(table_name = crate::schema::track_locations)]
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
pub struct TrackLocations {
pub id: Option<i32>,
pub location: Option<String>,
pub filename: Option<String>,
pub directory: Option<String>,
pub filesize: Option<i32>,
pub fs_deleted: Option<i32>,
pub needs_verification: Option<i32>,
}

View File

@ -1,7 +1,4 @@
// @generated automatically by Diesel CLI. // @generated automatically by Diesel CLI.
//diesel::table! {
// create
//}
diesel::table! { diesel::table! {
itunes_library (id) { itunes_library (id) {