Browse Source

show track locations from mixxx db

main
crunk 3 weeks ago
parent
commit
64a8fe77be
  1. 1
      diesel.toml
  2. 5
      src/db.rs
  3. 23
      src/main.rs
  4. 14
      src/models.rs
  5. 3
      src/schema.rs

1
diesel.toml

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

5
src/lib.rs → src/db.rs

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

23
src/main.rs

@ -1,3 +1,24 @@
use crate::db::establish_connection;
use crate::models::TrackLocations;
use diesel::prelude::*;
mod db;
mod models;
mod schema;
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);
}
}

14
src/models.rs

@ -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>,
}

3
src/schema.rs

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

Loading…
Cancel
Save