5 changed files with 39 additions and 7 deletions
@ -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"] } |
||||
|
@ -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)) |
||||
} |
} |
@ -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); |
||||
|
} |
||||
} |
} |
||||
|
@ -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>, |
||||
|
} |
Loading…
Reference in new issue