diff --git a/src/rust/liblektor-rs/Cargo.toml b/src/rust/liblektor-rs/Cargo.toml index 5ffadb986a312bc95420751afb2023b004d4207c..58bfc5710ed29173cbdb303a18c8b523f15ffb12 100644 --- a/src/rust/liblektor-rs/Cargo.toml +++ b/src/rust/liblektor-rs/Cargo.toml @@ -4,7 +4,8 @@ version = "0.1.0" edition = "2021" [lib] -crate-type = ["staticlib"] +crate-type = [ "staticlib" ] [dependencies] -libc = "0.2.0" +libc = "0.2.0" +diesel = { version = "2", features = [ "sqlite" ] } \ No newline at end of file diff --git a/src/rust/liblektor-rs/diesel.toml b/src/rust/liblektor-rs/diesel.toml new file mode 100644 index 0000000000000000000000000000000000000000..35a12ff0dbc6cb89ff1d400570145f9ed5fcda54 --- /dev/null +++ b/src/rust/liblektor-rs/diesel.toml @@ -0,0 +1,8 @@ +# For documentation on how to configure this file, +# see https://diesel.rs/guides/configuring-diesel-cli + +[print_schema] +file = "src/schema.rs" + +[migrations_directory] +dir = "migrations" diff --git a/src/rust/liblektor-rs/migrations/.keep b/src/rust/liblektor-rs/migrations/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/rust/liblektor-rs/migrations/2022-09-30-204512_create_posts/down.sql b/src/rust/liblektor-rs/migrations/2022-09-30-204512_create_posts/down.sql new file mode 100644 index 0000000000000000000000000000000000000000..5a2e360002d48d846f949ea2695257288c7b9033 --- /dev/null +++ b/src/rust/liblektor-rs/migrations/2022-09-30-204512_create_posts/down.sql @@ -0,0 +1,9 @@ +DROP TABLE repo; +DROP TABLE kara_repo; +DROP TABLE kara; +DROP TABLE kara_makers; +DROP TABLE kara_tag; +DROP TABLE tag; +DROP TABLE kara_tags; +DROP TABLE queue_1; +DROP TABLE history; diff --git a/src/rust/liblektor-rs/migrations/2022-09-30-204512_create_posts/up.sql b/src/rust/liblektor-rs/migrations/2022-09-30-204512_create_posts/up.sql new file mode 100644 index 0000000000000000000000000000000000000000..33a7c418d772ccd4fe40c7638080ddec3cf91c8b --- /dev/null +++ b/src/rust/liblektor-rs/migrations/2022-09-30-204512_create_posts/up.sql @@ -0,0 +1,51 @@ +CREATE TABLE repo + ( name TEXT NOT NULL + , id INTEGER NOT NULL + ); + +CREATE TABLE repo_kara + ( repo_id INTEGER NOT NULL REFERENCES repo(id) + , repo_kara_id INTEGER NOT NULL + , local_kara_id INTEGER NOT NULL REFERENCES kara(id) + , PRIMARY KEY (repo_id, repo_kara_id, local_kara_id) + ); + +CREATE TABLE kara + ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT + , is_dl BOOLEAN NOT NULL DEFAULT false + , song_title TEXT NOT NULL + , song_type TEXT NOT NULL + , song_origin TEXT NOT NULL + , source_name TEXT NOT NULL + , language TEXT NOT NULL + , kara_hash TEXT NOT NULL -- TEXT ABOVE + HASH OF FILE IN FS + ); + +CREATE TABLE kara_makers + ( id INTEGER NOT NULL REFERENCES kara ON DELETE CASCADE + , name TEXT NOT NULL + , PRIMARY KEY (id, name) + ); + +CREATE TABLE tag + ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT + , name TEXT NOT NULL + ); + +CREATE TABLE kara_tags + ( kara_id INTEGER NOT NULL REFERENCES kara(id) ON DELETE CASCADE + , tag_id INTEGER NOT NULL REFERENCES tag(id) ON DELETE CASCADE + , value TEXT + , PRIMARY KEY (kara_id, tag_id, value) + ); + +CREATE TABLE queue_1 + ( id INTEGER NOT NULL REFERENCES kara(id) ON DELETE CASCADE + , position INTEGER NOT NULL CHECK(position > 0) + ); + +CREATE TABLE history + ( id INTEGER NOT NULL REFERENCES kara(id) ON DELETE CASCADE + , epoch INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT + , PRIMARY KEY (id, epoch) + ); diff --git a/src/rust/liblektor-rs/src/database.rs b/src/rust/liblektor-rs/src/database.rs deleted file mode 100644 index 8ddcedc18fccec35ec329940f9804109ce624ece..0000000000000000000000000000000000000000 --- a/src/rust/liblektor-rs/src/database.rs +++ /dev/null @@ -1,45 +0,0 @@ -use crate::*; - -pub(crate) type LktDbPtr = *mut c_void; - -#[repr(C)] -pub(crate) struct LktQueueState { - volume: c_int, - paused: c_int, - random: c_int, - repeat: c_int, - single: c_int, - current: c_int, - duration: c_int, - consume: c_int, - length: c_int, -} - -extern "C" { - pub(crate) fn database_queue_toggle_pause(db: LktDbPtr) -> c_void; - - /* Update stuff */ - pub(crate) fn database_get_update( - db: LktDbPtr, - timestamp: *mut c_long, - job: *mut c_long, - current: *mut c_int, - ) -> c_void; - pub(crate) fn database_stamp(db: LktDbPtr) -> c_void; - pub(crate) fn database_updated(db: LktDbPtr) -> c_void; - pub(crate) fn database_deleted_kara( - db: LktDbPtr, - kara_id: *mut *mut c_int, - len: *mut size_t, - ) -> c_void; - pub(crate) fn database_total_playtime(db: LktDbPtr, seconds: *mut u64) -> c_void; - - /* Get information on the queue and currently playing kara */ - pub(crate) fn database_queue_state(db: LktDbPtr, res: *mut LktQueueState) -> bool; - pub(crate) fn database_queue_current_kara( - db: LktDbPtr, - res: *mut mkv::LktKaraMetadata, - id: *mut c_int, - ) -> bool; - pub(crate) fn database_queue_playtime(db: LktDbPtr, seconds: *mut u64) -> c_void; -} diff --git a/src/rust/liblektor-rs/src/database/mod.rs b/src/rust/liblektor-rs/src/database/mod.rs new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/rust/liblektor-rs/src/schema.rs b/src/rust/liblektor-rs/src/schema.rs new file mode 100644 index 0000000000000000000000000000000000000000..fda66f5553d1b4bc772b42e51908fae6af3a2e00 --- /dev/null +++ b/src/rust/liblektor-rs/src/schema.rs @@ -0,0 +1,45 @@ +// @generated automatically by Diesel CLI. + +diesel::table! { + kara (id) { + id -> Integer, + song_title -> Text, + song_type -> Text, + song_origin -> Text, + source_name -> Text, + language -> Text, + } +} + +diesel::table! { + kara_makers (id, name) { + id -> Integer, + name -> Text, + } +} + +diesel::table! { + kara_tags (kara_id, tag_id, value) { + kara_id -> Integer, + tag_id -> Integer, + value -> Nullable<Text>, + } +} + +diesel::table! { + tag (id) { + id -> Integer, + name -> Text, + } +} + +diesel::joinable!(kara_makers -> kara (id)); +diesel::joinable!(kara_tags -> kara (kara_id)); +diesel::joinable!(kara_tags -> tag (tag_id)); + +diesel::allow_tables_to_appear_in_same_query!( + kara, + kara_makers, + kara_tags, + tag, +);