Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 0c1d73e3 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

DB: Add base files for the DB implem using rust with the diesel crate

parent 94bd7ed2
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!193AMADEUS: Implementation of lkt-lib
Pipeline #3249 en échec
...@@ -4,7 +4,8 @@ version = "0.1.0" ...@@ -4,7 +4,8 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[lib] [lib]
crate-type = ["staticlib"] crate-type = [ "staticlib" ]
[dependencies] [dependencies]
libc = "0.2.0" libc = "0.2.0"
diesel = { version = "2", features = [ "sqlite" ] }
\ No newline at end of file
# 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"
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;
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)
);
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;
}
// @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,
);
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter