database setup + other stuff not rlly important
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
use diesel::prelude::*;
|
||||
use dotenvy::dotenv;
|
||||
use std::env;
|
||||
|
||||
pub mod models;
|
||||
pub mod schema;
|
||||
|
||||
pub fn establish_connection() -> SqliteConnection {
|
||||
dotenv().ok();
|
||||
|
||||
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
|
||||
SqliteConnection::establish(&database_url)
|
||||
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
use diesel::prelude::*;
|
||||
|
||||
#[derive(Queryable, Selectable)]
|
||||
#[diesel(table_name = crate::db::schema::app)]
|
||||
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
|
||||
pub struct App {
|
||||
pub id: String, // uuid
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
pub address: String,
|
||||
pub ssh_address: Option<String>, // default to normal address
|
||||
}
|
||||
|
||||
#[derive(Queryable, Selectable)]
|
||||
#[diesel(table_name = crate::db::schema::blog)]
|
||||
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
|
||||
pub struct Blog {
|
||||
pub id: String, // uuid
|
||||
pub title: String,
|
||||
pub content: String,
|
||||
pub reference: Option<String>, // uuid
|
||||
}
|
||||
|
||||
#[derive(Queryable, Selectable)]
|
||||
#[diesel(table_name = crate::db::schema::identities)]
|
||||
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
|
||||
pub struct Identity {
|
||||
pub id: String, // uuid
|
||||
pub common_name: String,
|
||||
pub username: String,
|
||||
pub public_key: String,
|
||||
pub private_key: String,
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// @generated automatically by Diesel CLI.
|
||||
|
||||
diesel::table! {
|
||||
app (id) {
|
||||
id -> Text,
|
||||
name -> Text,
|
||||
description -> Nullable<Text>,
|
||||
address -> Text,
|
||||
ssh_address -> Nullable<Text>,
|
||||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
blog (id) {
|
||||
id -> Text,
|
||||
title -> Text,
|
||||
content -> Text,
|
||||
reference -> Nullable<Text>,
|
||||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
identities (id) {
|
||||
id -> Text,
|
||||
common_name -> Text,
|
||||
username -> Text,
|
||||
public_key -> Text,
|
||||
private_key -> Text,
|
||||
}
|
||||
}
|
||||
|
||||
diesel::joinable!(blog -> app (reference));
|
||||
|
||||
diesel::allow_tables_to_appear_in_same_query!(app, blog, identities,);
|
||||
@@ -1,3 +1,5 @@
|
||||
mod db;
|
||||
|
||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||
#[tauri::command]
|
||||
fn greet(name: &str) -> String {
|
||||
|
||||
Reference in New Issue
Block a user