diesel instead of sea-orm
sea-orm was getting to be bigger hassle I think and harder to compile, diesel seems simple and effective enough.
This commit is contained in:
parent
d308bd33b2
commit
37a2dbd986
12 changed files with 165 additions and 1766 deletions
1773
Cargo.lock
generated
1773
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -22,7 +22,7 @@ cxx-qt = "0.5.1"
|
|||
cxx-qt-lib = "0.5.1"
|
||||
# home = "0.5.4"
|
||||
dirs = "5.0.0"
|
||||
sea-orm = { version = "0.11.2", features = ["sqlx-sqlite", "sqlx", "runtime-async-std-rustls"] }
|
||||
diesel = { version = "2.0.3", features = ["sqlite"] }
|
||||
# ffmpeg-next = "6.0.0"
|
||||
|
||||
# cxx-qt-build generates C++ code from the `#[cxx_qt::bridge]` module
|
||||
|
|
8
diesel.toml
Normal file
8
diesel.toml
Normal file
|
@ -0,0 +1,8 @@
|
|||
# For documentation on how to configure this file,
|
||||
# see https://diesel.rs/guides/configuring-diesel-cli
|
||||
|
||||
[print_schema]
|
||||
file = "src/rust/schema.rs"
|
||||
|
||||
[migrations_directory]
|
||||
dir = "src/rust/migrations"
|
0
library-db.sqlite3
Normal file
0
library-db.sqlite3
Normal file
|
@ -53,6 +53,7 @@
|
|||
#include "cxx-qt-gen/slide_obj.cxxqt.h"
|
||||
#include "cxx-qt-gen/slide_model.cxxqt.h"
|
||||
#include "cxx-qt-gen/settings.cxxqt.h"
|
||||
#include "cxx-qt-gen/image_model.cxxqt.h"
|
||||
|
||||
static QWindow *windowFromEngine(QQmlApplicationEngine *engine)
|
||||
{
|
||||
|
@ -141,6 +142,8 @@ int main(int argc, char *argv[])
|
|||
// QScopedPointer<QQuickView> preswin(new QQuickView);
|
||||
QScopedPointer<ServiceItemModel> serviceItemModel(new ServiceItemModel);
|
||||
QScopedPointer<SlideObj> slideobject(new SlideObj);
|
||||
QScopedPointer<ImageModel> imageModel(new ImageModel);
|
||||
imageModel.get()->testDatabase();
|
||||
|
||||
Settings *settings = new Settings;
|
||||
settings->setup();
|
||||
|
|
|
@ -20,12 +20,6 @@ mod image_model {
|
|||
type QList_QString = cxx_qt_lib::QList<QString>;
|
||||
}
|
||||
|
||||
#[cxx_qt::qobject(base = "QAbstractListModel")]
|
||||
#[derive(Default, Debug)]
|
||||
pub struct ImageModel {
|
||||
images: Vec<Image>,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct Image {
|
||||
id: i32,
|
||||
|
@ -33,6 +27,12 @@ mod image_model {
|
|||
path: QString,
|
||||
}
|
||||
|
||||
#[cxx_qt::qobject(base = "QAbstractListModel")]
|
||||
#[derive(Default, Debug)]
|
||||
pub struct ImageModel {
|
||||
images: Vec<self::Image>,
|
||||
}
|
||||
|
||||
#[cxx_qt::qsignals(ImageModel)]
|
||||
pub enum Signals<'a> {
|
||||
#[inherit]
|
||||
|
@ -49,9 +49,14 @@ mod image_model {
|
|||
TitleRole,
|
||||
}
|
||||
|
||||
use crate::entities::{images, prelude::Images};
|
||||
use sea_orm::{ConnectionTrait, Database, DbBackend, DbErr, Statement, ActiveValue};
|
||||
// use crate::entities::{images, prelude::Images};
|
||||
// use sea_orm::{ConnectionTrait, Database, DbBackend, DbErr, Statement, ActiveValue};
|
||||
use crate::models::*;
|
||||
use diesel::prelude::*;
|
||||
use diesel::sqlite::SqliteConnection;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::image_model::image_model::Image;
|
||||
impl qobject::ImageModel {
|
||||
#[qinvokable]
|
||||
pub fn clear(mut self: Pin<&mut Self>) {
|
||||
|
@ -62,6 +67,27 @@ mod image_model {
|
|||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn test_database(&self) {
|
||||
use crate::schema::images::dsl::*;
|
||||
const DATABASE_URL: &str = "sqlite:///home/chris/.local/share/librepresenter/Libre Presenter/library-db.sqlite3";
|
||||
const DB_NAME: &str = "library_db";
|
||||
|
||||
let db = &mut SqliteConnection::establish(DATABASE_URL)
|
||||
.unwrap_or_else(|_| panic!("error connecting to {}", DATABASE_URL));
|
||||
|
||||
let results = images
|
||||
.load::<crate::models::Image>(db)
|
||||
.expect("Error loading images");
|
||||
|
||||
println!("SHOWING IMAGES");
|
||||
for image in results {
|
||||
println!("{}", image.title);
|
||||
println!("--------------\n");
|
||||
println!("{}", image.path);
|
||||
}
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn remove_item(mut self: Pin<&mut Self>, index: i32) {
|
||||
if index < 0 || (index as usize) >= self.images().len() {
|
||||
|
@ -77,26 +103,28 @@ mod image_model {
|
|||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub async fn add_item(mut self: Pin<&mut Self>, id: i32, title: QString, path: QString) -> Result<(), DBErr> {
|
||||
pub fn add_item(mut self: Pin<&mut Self>, id: i32, title: QString, path: QString) {
|
||||
const DATABASE_URL: &str = "sqlite://library-db.sqlite3";
|
||||
const DB_NAME: &str = "library_db";
|
||||
|
||||
let db = Database::connect(DATABASE_URL).await?;
|
||||
let image = Image { id, title, path };
|
||||
let model = images::ActiveModel {
|
||||
id: ActiveValue::set(id),
|
||||
title: ActiveValue::set(title.to_string()),
|
||||
path: ActiveValue::set(path.to_string()),
|
||||
..Default::default()
|
||||
};
|
||||
let res = Images::insert(model).exec(db).await?;
|
||||
let db = SqliteConnection::establish(DATABASE_URL)
|
||||
.unwrap_or_else(|_| panic!("error connecting to {}", DATABASE_URL));
|
||||
|
||||
let image = self::Image { id, title, path };
|
||||
// let model = images::ActiveModel {
|
||||
// id: ActiveValue::set(id),
|
||||
// title: ActiveValue::set(title.to_string()),
|
||||
// path: ActiveValue::set(path.to_string()),
|
||||
// ..Default::default()
|
||||
// };
|
||||
// let res = Images::insert(model).exec(db).await?;
|
||||
|
||||
self.as_mut().add_image(image);
|
||||
|
||||
Ok(())
|
||||
// Ok(())
|
||||
}
|
||||
|
||||
fn add_image(mut self: Pin<&mut Self>, image: Image) {
|
||||
fn add_image(mut self: Pin<&mut Self>, image: self::Image) {
|
||||
let index = self.as_ref().images().len() as i32;
|
||||
println!("{:?}", image);
|
||||
unsafe {
|
||||
|
@ -120,7 +148,7 @@ mod image_model {
|
|||
self.as_mut().insert_image(image, index);
|
||||
}
|
||||
|
||||
fn insert_image(mut self: Pin<&mut Self>, image: Image, id: i32) {
|
||||
fn insert_image(mut self: Pin<&mut Self>, image: self::Image, id: i32) {
|
||||
unsafe {
|
||||
self.as_mut()
|
||||
.begin_insert_rows(&QModelIndex::default(), id, id);
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
// assert_eq!(result, 4);
|
||||
// }
|
||||
// }
|
||||
const DATABASE_URL: &str = "sqlite://library-db.sqlite3";
|
||||
const DB_NAME: &str = "library_db";
|
||||
|
||||
// mod my_object;
|
||||
mod file_helper;
|
||||
|
@ -22,5 +20,7 @@ mod settings;
|
|||
mod slide_obj;
|
||||
mod slide_model;
|
||||
mod image_model;
|
||||
mod entities;
|
||||
mod models;
|
||||
mod schema;
|
||||
// mod entities;
|
||||
// mod video_thumbnail;
|
||||
|
|
0
src/rust/migrations/.keep
Normal file
0
src/rust/migrations/.keep
Normal file
|
@ -0,0 +1 @@
|
|||
-- This file should undo anything in `up.sql`
|
5
src/rust/migrations/2023-04-04-164359_library-db/up.sql
Normal file
5
src/rust/migrations/2023-04-04-164359_library-db/up.sql
Normal file
|
@ -0,0 +1,5 @@
|
|||
-- Your SQL goes here
|
||||
CREATE TABLE IF NOT EXISTS 'songs' ( 'id' INTEGER NOT NULL, 'title' TEXT NOT NULL, 'lyrics' TEXT, 'author' TEXT, 'ccli' TEXT, 'audio' TEXT, 'vorder' TEXT, 'background' TEXT, 'backgroundType' TEXT, horizontalTextAlignment, verticalTextAlignment, font TEXT, fontSize INTEGER, PRIMARY KEY(id));
|
||||
CREATE TABLE IF NOT EXISTS 'videos' ( 'id' INTEGER NOT NULL, 'title' TEXT NOT NULL, 'filePath' TEXT NOT NULL, startTime REAL, endTime REAL, loop BOOLEAN NOT NULL DEFAULT 0, PRIMARY KEY(id));
|
||||
CREATE TABLE IF NOT EXISTS 'images' ( 'id' INTEGER NOT NULL, 'title' TEXT NOT NULL, 'filePath' TEXT NOT NULL, PRIMARY KEY(id));
|
||||
CREATE TABLE IF NOT EXISTS 'presentations' ( 'id' INTEGER NOT NULL, 'title' TEXT NOT NULL, 'filePath' TEXT NOT NULL, pageCount INTEGER DEFAULT 1, PRIMARY KEY(id));
|
8
src/rust/models.rs
Normal file
8
src/rust/models.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
use diesel::prelude::*;
|
||||
|
||||
#[derive(Queryable)]
|
||||
pub struct Image {
|
||||
pub id: i32,
|
||||
pub title: String,
|
||||
pub path: String,
|
||||
}
|
55
src/rust/schema.rs
Normal file
55
src/rust/schema.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
// @generated automatically by Diesel CLI.
|
||||
|
||||
diesel::table! {
|
||||
images (id) {
|
||||
id -> Integer,
|
||||
title -> Text,
|
||||
filePath -> Text,
|
||||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
presentations (id) {
|
||||
id -> Integer,
|
||||
title -> Text,
|
||||
filePath -> Text,
|
||||
pageCount -> Nullable<Integer>,
|
||||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
songs (id) {
|
||||
id -> Integer,
|
||||
title -> Text,
|
||||
lyrics -> Nullable<Text>,
|
||||
author -> Nullable<Text>,
|
||||
ccli -> Nullable<Text>,
|
||||
audio -> Nullable<Text>,
|
||||
vorder -> Nullable<Text>,
|
||||
background -> Nullable<Text>,
|
||||
backgroundType -> Nullable<Text>,
|
||||
horizontalTextAlignment -> Nullable<Binary>,
|
||||
verticalTextAlignment -> Nullable<Binary>,
|
||||
font -> Nullable<Text>,
|
||||
fontSize -> Nullable<Integer>,
|
||||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
videos (id) {
|
||||
id -> Integer,
|
||||
title -> Text,
|
||||
filePath -> Text,
|
||||
startTime -> Nullable<Float>,
|
||||
endTime -> Nullable<Float>,
|
||||
#[sql_name = "loop"]
|
||||
loop_ -> Bool,
|
||||
}
|
||||
}
|
||||
|
||||
diesel::allow_tables_to_appear_in_same_query!(
|
||||
images,
|
||||
presentations,
|
||||
songs,
|
||||
videos,
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue