Sync everything before trying sqlx
This commit is contained in:
parent
05a62bb456
commit
bfc5a6f90d
8 changed files with 103 additions and 13 deletions
2
.cargo/config.toml
Normal file
2
.cargo/config.toml
Normal file
|
@ -0,0 +1,2 @@
|
|||
[env]
|
||||
RUST_BACKTRACE = "1"
|
60
Cargo.lock
generated
60
Cargo.lock
generated
|
@ -266,6 +266,33 @@ dependencies = [
|
|||
"inout",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "color-eyre"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"color-spantrace",
|
||||
"eyre",
|
||||
"indenter",
|
||||
"once_cell",
|
||||
"owo-colors",
|
||||
"tracing-error",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "color-spantrace"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ba75b3d9449ecdccb27ecbc479fdc0b87fa2dd43d2f8298f9bf0e59aacc8dce"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"owo-colors",
|
||||
"tracing-core",
|
||||
"tracing-error",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cookie"
|
||||
version = "0.18.0"
|
||||
|
@ -444,6 +471,16 @@ version = "1.0.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||
|
||||
[[package]]
|
||||
name = "eyre"
|
||||
version = "0.6.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c2b6b5a29c02cdc822728b7d7b8ae1bab3e3b05d44522770ddd49722eeac7eb"
|
||||
dependencies = [
|
||||
"indenter",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "filetime"
|
||||
version = "0.2.22"
|
||||
|
@ -670,6 +707,12 @@ dependencies = [
|
|||
"want",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indenter"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.1.0"
|
||||
|
@ -783,6 +826,7 @@ dependencies = [
|
|||
"axum-macros",
|
||||
"axum_csrf",
|
||||
"base64",
|
||||
"color-eyre",
|
||||
"cookie",
|
||||
"deadpool",
|
||||
"deadpool-diesel",
|
||||
|
@ -966,6 +1010,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.1"
|
||||
|
@ -1633,6 +1683,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.1.4"
|
||||
|
|
|
@ -32,4 +32,10 @@ tower-livereload = "0.8.2"
|
|||
argon2 = { version = "0.5.2", features = ["std"] }
|
||||
thiserror = "1.0.50"
|
||||
axum-macros = "0.3.8"
|
||||
color-eyre = "0.6.2"
|
||||
|
||||
# color-eyre
|
||||
# irust
|
||||
# bacon
|
||||
# sqlx (sea orm?)
|
||||
# poem-openapi?
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
|
||||
rustfmt
|
||||
rustPackages.clippy
|
||||
rustPackages.bacon
|
||||
rust-analyzer
|
||||
nodePackages_latest.vscode-langservers-extracted
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{instrumentation, router, server::listen};
|
||||
|
||||
pub async fn run() -> Result<(), anyhow::Error> {
|
||||
instrumentation::setup_trace_logger();
|
||||
instrumentation::init();
|
||||
listen(router::new().await?).await;
|
||||
Ok(())
|
||||
}
|
||||
|
|
15
src/error.rs
15
src/error.rs
|
@ -1,9 +1,13 @@
|
|||
use std::fmt::Display;
|
||||
|
||||
use axum::{
|
||||
http::StatusCode,
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use thiserror::Error;
|
||||
|
||||
pub struct AppError(anyhow::Error);
|
||||
#[derive(Error, Debug)]
|
||||
pub struct AppError(#[from] anyhow::Error);
|
||||
|
||||
impl IntoResponse for AppError {
|
||||
fn into_response(self) -> Response {
|
||||
|
@ -15,11 +19,8 @@ impl IntoResponse for AppError {
|
|||
}
|
||||
}
|
||||
|
||||
impl<E> From<E> for AppError
|
||||
where
|
||||
E: Into<anyhow::Error>,
|
||||
{
|
||||
fn from(err: E) -> Self {
|
||||
Self(err.into())
|
||||
impl Display for AppError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_fmt(format!("app error"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
use tracing::{instrument, trace};
|
||||
use tracing_subscriber::{filter::LevelFilter, EnvFilter};
|
||||
|
||||
pub fn init() {
|
||||
color_eyre::install();
|
||||
setup_trace_logger();
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
pub fn setup_trace_logger() {
|
||||
let filter = EnvFilter::builder()
|
||||
|
|
25
src/views.rs
25
src/views.rs
|
@ -1,11 +1,15 @@
|
|||
use std::{error::Error, sync::Arc};
|
||||
|
||||
use axum::{
|
||||
extract::State,
|
||||
response::{Html, IntoResponse},
|
||||
};
|
||||
use axum_csrf::CsrfToken;
|
||||
use axum_macros::debug_handler;
|
||||
use deadpool_diesel::InteractError;
|
||||
use diesel::{QueryDsl, RunQueryDsl, SelectableHelper};
|
||||
use maud::html;
|
||||
use thiserror::Error;
|
||||
use tracing::instrument;
|
||||
|
||||
use crate::{
|
||||
|
@ -98,21 +102,32 @@ pub async fn login(csrf: CsrfToken) -> impl IntoResponse {
|
|||
.into_response()
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
enum AllUsersError {
|
||||
#[error("other application error")]
|
||||
App(#[from] AppError),
|
||||
#[error("failed to retrieve users")]
|
||||
DB(#[from] InteractError),
|
||||
}
|
||||
|
||||
#[debug_handler]
|
||||
pub async fn all_users(
|
||||
State(state): State<crate::state::State>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
) -> Result<Html<String>, AllUsersError> {
|
||||
use crate::schema::users::dsl::*;
|
||||
|
||||
let conn = state.database.pool.get().await?;
|
||||
let cc = |c| {
|
||||
let cc = |c| -> Vec<User> {
|
||||
users
|
||||
.select(User::as_select())
|
||||
.load(c)
|
||||
.expect("error loading users")
|
||||
};
|
||||
|
||||
let all_users = conn.interact(cc).await?;
|
||||
let all_users: Vec<User> = match conn.interact(cc).await {
|
||||
Ok(u) => u,
|
||||
Err(e) => return Err(("failed to retrieve users")),
|
||||
};
|
||||
|
||||
// @if let Some(name) = u.name {
|
||||
// name
|
||||
|
@ -125,9 +140,9 @@ pub async fn all_users(
|
|||
main class="prose" {
|
||||
h1 { "Users" }
|
||||
ul {
|
||||
@for u in &all_users {
|
||||
@for u in all_users {
|
||||
li {
|
||||
(u.username)
|
||||
(u)
|
||||
"("
|
||||
")"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue