Added surrealdb
This commit is contained in:
parent
0177c07833
commit
0dbbb889f6
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,6 +4,7 @@
|
||||
/dist/
|
||||
/static/
|
||||
/.dioxus/
|
||||
database/
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
2594
Cargo.lock
generated
2594
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -11,6 +11,11 @@ serde = { version = "1.0.197", features = ["derive"] }
|
||||
|
||||
dioxus = { version = "0.5", features = ["fullstack", "router"] }
|
||||
|
||||
tokio = { version = "1.38.1", features = ["macros", "rt-multi-thread"], optional = true }
|
||||
axum = { version = "0.7.5", optional = true }
|
||||
once_cell = { version = "1.19.0", optional = true }
|
||||
surrealdb = { version = "1.5.4", features = ["kv-speedb"], optional = true }
|
||||
|
||||
# Debug
|
||||
tracing = "0.1.40"
|
||||
dioxus-logger = "0.5.0"
|
||||
@ -18,5 +23,5 @@ manganis = "0.2.2"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
server = ["dioxus/axum"]
|
||||
server = [ "dioxus/axum", "tokio", "axum", "once_cell", "surrealdb" ]
|
||||
web = ["dioxus/web"]
|
||||
|
@ -1100,6 +1100,10 @@ html {
|
||||
margin-inline-start: calc(var(--border-btn) * -1);
|
||||
}
|
||||
|
||||
.static {
|
||||
position: static;
|
||||
}
|
||||
|
||||
.flex {
|
||||
display: flex;
|
||||
}
|
||||
|
@ -3,9 +3,11 @@
|
||||
{
|
||||
# https://devenv.sh/basics/
|
||||
env.GREET = "devenv";
|
||||
env.LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
|
||||
env.BINDGEN_EXTRA_CLANG_ARGS = "-I ${pkgs.llvmPackages.libclang.lib}/lib/clang/17/include";
|
||||
|
||||
# https://devenv.sh/packages/
|
||||
packages = [ pkgs.openssl pkgs.git pkgs.dioxus-cli pkgs.tailwindcss pkgs.watchexec ];
|
||||
packages = [ pkgs.openssl pkgs.git pkgs.dioxus-cli pkgs.tailwindcss pkgs.watchexec pkgs.llvmPackages.libclang pkgs.clang ];
|
||||
|
||||
# https://devenv.sh/scripts/
|
||||
scripts.hello.exec = "echo hello from $GREET";
|
||||
|
34
src/main.rs
34
src/main.rs
@ -1,11 +1,12 @@
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
mod components;
|
||||
mod util;
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use tracing::{info, Level};
|
||||
|
||||
// Include routes
|
||||
// Use routes
|
||||
use components::home::Home;
|
||||
|
||||
#[derive(Clone, Routable, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
@ -20,6 +21,37 @@ const _TAILWIND_URL: &str = manganis::mg!(file("assets/tailwind.css"));
|
||||
fn main() {
|
||||
// Init logger
|
||||
dioxus_logger::init(Level::INFO).expect("failed to init logger");
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
{
|
||||
use axum::routing::*;
|
||||
|
||||
// Spawn main tokio runtime
|
||||
tokio::runtime::Runtime::new()
|
||||
.unwrap()
|
||||
.block_on(async move {
|
||||
// Initialize surrealdb connection
|
||||
util::surrealdb::initialize()
|
||||
.await
|
||||
.expect("Error while initializing surrealdb");
|
||||
|
||||
// Create axum app
|
||||
let app = Router::new()
|
||||
.serve_dioxus_application(ServeConfig::builder().build(), || {
|
||||
VirtualDom::new(App)
|
||||
})
|
||||
.await;
|
||||
|
||||
// Run axum app
|
||||
let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080));
|
||||
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
|
||||
|
||||
axum::serve(listener, app.into_make_service())
|
||||
.await
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
launch(App);
|
||||
}
|
||||
|
||||
|
2
src/util.rs
Normal file
2
src/util.rs
Normal file
@ -0,0 +1,2 @@
|
||||
#[cfg(feature = "server")]
|
||||
pub mod surrealdb;
|
19
src/util/surrealdb.rs
Normal file
19
src/util/surrealdb.rs
Normal file
@ -0,0 +1,19 @@
|
||||
use once_cell::sync::Lazy;
|
||||
use surrealdb::engine::local::{Db, SpeeDb};
|
||||
use surrealdb::Surreal;
|
||||
|
||||
pub static DB: Lazy<Surreal<Db>> = Lazy::new(|| Surreal::init());
|
||||
|
||||
pub async fn initialize() -> surrealdb::Result<()> {
|
||||
DB.connect::<SpeeDb>("./database").await?;
|
||||
|
||||
DB.use_ns("xvmcmm").use_db("xvmcmm").await?;
|
||||
|
||||
apply_queries().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn apply_queries() -> surrealdb::Result<()> {
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue
Block a user