Skip to content

Commit

Permalink
Use db
Browse files Browse the repository at this point in the history
  • Loading branch information
ghasemi committed Jul 4, 2023
1 parent bb2a9cd commit 4219f90
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 14 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL=music-player.sqlite
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target/
/music-player.sqlite
12 changes: 12 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/sqldialects.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 96 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
[package]
name = "rust-test"
name = "music-player"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies.gtk]
package = "gtk4"
version = "0.6.6"
features = ["v4_10"]
[dependencies]
gtk = { package = "gtk4", version = "0.6.6", features = ["v4_10"] }
diesel = { version = "2.1.0", features = ["sqlite"] }
dotenvy = { version = "0.15.7" }
9 changes: 9 additions & 0 deletions diesel.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# For documentation on how to configure this file,
# see https://diesel.rs/guides/configuring-diesel-cli

[print_schema]
file = "src/schema.rs"
custom_type_derives = ["diesel::query_builder::QueryId"]

[migrations_directory]
dir = "migrations"
Empty file added migrations/.keep
Empty file.
1 change: 1 addition & 0 deletions migrations/2023-06-10-132201_collection/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
drop table collections;
7 changes: 7 additions & 0 deletions migrations/2023-06-10-132201_collection/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
create table collections
(
id integer not null
constraint collections_pk
primary key autoincrement,
path TEXT not null
);
11 changes: 11 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
mod choose_file;
mod schema;
mod models;

use std::env::var;
use diesel::{Connection, RunQueryDsl, SqliteConnection};
use dotenvy::dotenv;
use gtk::{Application, ApplicationWindow, Button, Grid};
use gtk::prelude::{ApplicationExt, ApplicationExtManual, GtkWindowExt};
use gtk::traits::{ButtonExt, GridExt};
use crate::choose_file::choose;
use crate::models::Collection;
use crate::schema::collection::dsl::collections;

fn main() {
dotenv().ok();
let database_url = var("DATABASE_URL").expect("DATABASE_URL must be set");
let connection = &mut SqliteConnection::establish(&database_url)
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url));
let application = Application::builder().application_id("eu.agoor.music-player").build();
application.connect_activate(|app| {
let grid = Grid::builder().build();
Expand Down
10 changes: 10 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use diesel::prelude::*;

#[derive(Queryable, Selectable)]
#[diesel(table_name = crate::schema::collections)]
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
#[derive(Debug)]
pub struct Collection {
pub id: i32,
pub path: String,
}
8 changes: 8 additions & 0 deletions src/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @generated automatically by Diesel CLI.

diesel::table! {
collections (id) {
id -> Integer,
path -> Text,
}
}

0 comments on commit 4219f90

Please sign in to comment.