feat: implement surrealdb and redis
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use surrealdb::{engine::remote::ws::Client, Surreal};
|
||||
use utoipa::{IntoParams, ToSchema};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
|
||||
@@ -35,3 +36,12 @@ pub struct ResponseListSuccessDto<T: Serialize> {
|
||||
pub data: T,
|
||||
pub meta: Option<MetaResponseDto>,
|
||||
}
|
||||
|
||||
pub type SurrealClient = Surreal<Client>;
|
||||
pub type RedisClient = redis::Client;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
pub surrealdb: SurrealClient,
|
||||
pub redisdb: RedisClient,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
pub mod error {
|
||||
use axum::http::StatusCode;
|
||||
use axum::response::IntoResponse;
|
||||
use axum::response::Response;
|
||||
use axum::Json;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("database error")]
|
||||
Db,
|
||||
}
|
||||
|
||||
impl IntoResponse for Error {
|
||||
fn into_response(self) -> Response {
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, Json(self.to_string()))
|
||||
.into_response()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<surrealdb::Error> for Error {
|
||||
fn from(error: surrealdb::Error) -> Self {
|
||||
eprintln!("{error}");
|
||||
Self::Db
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
pub mod common_dto;
|
||||
pub mod error_dto;
|
||||
|
||||
pub use common_dto::*;
|
||||
pub use error_dto::*;
|
||||
|
||||
Reference in New Issue
Block a user