From 77c946249c1e6ddf5e11ab43ab77d341b45166c5 Mon Sep 17 00:00:00 2001 From: hank Date: Wed, 31 Jul 2024 16:24:35 +0800 Subject: [PATCH] update --- Cargo.lock | 157 ++++++++++++++++++++++++++++++++---- Cargo.toml | 50 +++++++----- src/config.rs | 2 +- src/db.rs | 9 ++- src/handler/user_handler.rs | 2 +- src/main.rs | 3 +- src/router.rs | 2 +- 7 files changed, 184 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3ca8988..29cfc78 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.22.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" dependencies = [ "gimli", ] @@ -176,12 +176,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "anyhow" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" - [[package]] name = "argon2" version = "0.5.3" @@ -256,9 +250,9 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "backtrace" -version = "0.3.73" +version = "0.3.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" dependencies = [ "addr2line", "cc", @@ -525,6 +519,33 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +[[package]] +name = "color-eyre" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55146f5e46f237f7423d74111267d4597b59b0dad0ffaf7303bce9945d843ad5" +dependencies = [ + "backtrace", + "color-spantrace", + "eyre", + "indenter", + "once_cell", + "owo-colors", + "tracing-error", +] + +[[package]] +name = "color-spantrace" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd6be1b2a7e382e2b98b43b2adcca6bb0e465af0bdd38123873ae61eb17a72c2" +dependencies = [ + "once_cell", + "owo-colors", + "tracing-core", + "tracing-error", +] + [[package]] name = "colorchoice" version = "1.0.2" @@ -820,6 +841,16 @@ version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" +[[package]] +name = "eyre" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" +dependencies = [ + "indenter", + "once_cell", +] + [[package]] name = "fastrand" version = "2.1.0" @@ -1017,9 +1048,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.29.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] name = "glob" @@ -1307,6 +1338,12 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + [[package]] name = "indexmap" version = "2.2.6" @@ -1720,9 +1757,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.2" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f203fa8daa7bb185f760ae12bd8e097f63d17041dcdcaf675ac54cdf863170e" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" dependencies = [ "memchr", ] @@ -1831,6 +1868,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" +[[package]] +name = "owo-colors" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" + [[package]] name = "parking_lot" version = "0.12.3" @@ -2194,14 +2237,15 @@ dependencies = [ name = "realm" version = "0.1.0" dependencies = [ - "anyhow", "argon2", "chrono", "clap", + "color-eyre", "const_format", "mlua", "salvo", "sea-orm", + "sea-orm-migration", "serde", "serde_json", "sonyflake", @@ -2662,7 +2706,6 @@ version = "0.68.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e6c62e31abf82bdf467bf14b6f78909ad308639e7e01861d9f6a3d96f7152c1" dependencies = [ - "anyhow", "async-trait", "base64 0.22.1", "brotli", @@ -2670,6 +2713,7 @@ dependencies = [ "cookie", "encoding_rs", "enumflags2", + "eyre", "flate2", "form_urlencoded", "futures-channel", @@ -2807,6 +2851,23 @@ dependencies = [ "uuid", ] +[[package]] +name = "sea-orm-cli" +version = "1.0.0-rc.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76cf2bfe983fad4c67500ef7c9da9b65c94efbbe40293b5cc21936c66aa7f3fe" +dependencies = [ + "chrono", + "clap", + "dotenvy", + "glob", + "regex", + "sea-schema", + "tracing", + "tracing-subscriber", + "url", +] + [[package]] name = "sea-orm-macros" version = "1.0.0-rc.7" @@ -2821,6 +2882,23 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sea-orm-migration" +version = "1.0.0-rc.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db7a1850f21ecb01eaa913e8e62bdacd233fab5ee8cad07bd872a8b87262fb0f" +dependencies = [ + "async-trait", + "clap", + "dotenvy", + "futures", + "sea-orm", + "sea-orm-cli", + "sea-schema", + "tracing", + "tracing-subscriber", +] + [[package]] name = "sea-query" version = "0.31.0-rc.9" @@ -2833,6 +2911,7 @@ dependencies = [ "inherent", "ordered-float 3.9.2", "rust_decimal", + "sea-query-derive", "serde_json", "time", "uuid", @@ -2854,6 +2933,42 @@ dependencies = [ "uuid", ] +[[package]] +name = "sea-query-derive" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a82fcb49253abcb45cdcb2adf92956060ec0928635eb21b4f7a6d8f25ab0bc" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "syn 2.0.72", + "thiserror", +] + +[[package]] +name = "sea-schema" +version = "0.15.0-rc.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d26463bcf02ab6fe334ca814d8ec06bc2a8c69e190890a25b109fa5c50c7018" +dependencies = [ + "futures", + "sea-query", + "sea-schema-derive", +] + +[[package]] +name = "sea-schema-derive" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6f686050f76bffc4f635cda8aea6df5548666b830b52387e8bc7de11056d11e" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "seahash" version = "4.1.0" @@ -3667,6 +3782,16 @@ dependencies = [ "valuable", ] +[[package]] +name = "tracing-error" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e" +dependencies = [ + "tracing", + "tracing-subscriber", +] + [[package]] name = "tracing-log" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index 467fb1b..a7e21f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,35 +4,49 @@ version = "0.1.0" edition = "2021" [dependencies] -salvo = { version = "0.68", features = [ +tokio = { version = "1", features = ["full"] } +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } +mlua = { version = "0.9", features = ["lua54", "vendored", "serialize"] } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1" +const_format = "0.2" +clap = { version = "4", features = ["derive"] } +chrono = { version = "0.4", features = ["serde"] } +sonyflake = { version = "0.2.0" } +argon2 = "0.5" +color-eyre = "0.6" + +[dependencies.salvo] +version = "0.68" +features = [ "oapi", - "anyhow", + "eyre", "websocket", "logging", "basic-auth", "compression", "affix", -] } +] -sea-orm = { version = "1.0.0-rc.7", features = [ - "debug-print", +[dependencies.sea-orm] +version = "1.0.0-rc.7" +features = [ "runtime-tokio", "sqlx-postgres", + "debug-print", "macros", "with-uuid", "with-json", "with-chrono", -] } +] -tokio = { version = "1", features = ["full"] } -tracing = "0.1" -tracing-subscriber = { version = "0.3", features = ["env-filter"] } -mlua = { version = "0.9", features = ["lua54", "vendored", "serialize"] } -anyhow = "1" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1" -const_format = "0.2" -clap = { version = "4", features = ["derive"] } -chrono = { version = "0.4", features = ["serde"] } -sonyflake = { version = "0.2.0"} -argon2 = "0.5" +[dependencies.sea-orm-migration] +version = "1.0.0-rc.7" +features = [ + # Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI. + # View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime. + # e.g. + "runtime-tokio", # `ASYNC_RUNTIME` feature + "sqlx-postgres", # `DATABASE_DRIVER` feature +] diff --git a/src/config.rs b/src/config.rs index c88cf27..3a6b86b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,4 +1,4 @@ -use anyhow::Result; +use color_eyre::Result; use mlua::{Lua, Table}; use serde::{Deserialize, Serialize}; use std::{env, path::Path}; diff --git a/src/db.rs b/src/db.rs index 99999e6..9105bf7 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,5 +1,5 @@ -use sea_orm::{Database, DatabaseConnection, DbErr}; -use anyhow::Result; +use sea_orm::{ConnectOptions, Database, DatabaseConnection, DbErr}; +use color_eyre::Result; use tracing::info; use crate::config::Config; @@ -20,6 +20,9 @@ pub async fn init(config: &Config) -> Result { ) }; + let mut opt = ConnectOptions::new(&db_url); + opt.sqlx_logging(true); + info!("Connecting to database at {}", db_url); - Database::connect(&db_url).await + Database::connect(opt).await } diff --git a/src/handler/user_handler.rs b/src/handler/user_handler.rs index 334414b..213a7f9 100644 --- a/src/handler/user_handler.rs +++ b/src/handler/user_handler.rs @@ -1,4 +1,4 @@ -use anyhow::Result; +use color_eyre::Result; use salvo::prelude::*; use crate::models::user::{ diff --git a/src/main.rs b/src/main.rs index d4be580..a52d6bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ pub mod state; pub mod utils; use crate::router::make_route; -use anyhow::Result; +use color_eyre::Result; use salvo::prelude::*; use tokio::signal; use tracing::info; @@ -19,6 +19,7 @@ use tracing_subscriber::EnvFilter; async fn main() -> Result<()> { let filter = EnvFilter::from_default_env(); tracing_subscriber::fmt().with_env_filter(filter).with_test_writer().init(); + color_eyre::install()?; // std::env::set_var("RUST_LOG", "trace"); // tracing_subscriber::fmt::init(); diff --git a/src/router.rs b/src/router.rs index 30e9e0c..e359857 100644 --- a/src/router.rs +++ b/src/router.rs @@ -2,7 +2,7 @@ use crate::config::Config; use crate::db; use crate::middleware::basic_auth::Validator; use crate::state::AppState; -use anyhow::Result; +use color_eyre::Result; use salvo::affix; use salvo::prelude::*; use tracing::info;