multidb
This commit is contained in:
+7
-11
@@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use slug::slugify;
|
use slug::slugify;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db,
|
db, queries,
|
||||||
state::{NoteUpdate, SharedState},
|
state::{NoteUpdate, SharedState},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -214,12 +214,10 @@ pub async fn restore(
|
|||||||
Json(payload): Json<RestoreRequest>,
|
Json(payload): Json<RestoreRequest>,
|
||||||
) -> Result<Json<serde_json::Value>, ApiError> {
|
) -> Result<Json<serde_json::Value>, ApiError> {
|
||||||
let (workspace, note) = authorized_note(&state, &workspace_slug, ¬e_slug, payload.password.as_deref()).await?;
|
let (workspace, note) = authorized_note(&state, &workspace_slug, ¬e_slug, payload.password.as_deref()).await?;
|
||||||
let content: Option<String> = sqlx::query_scalar(
|
let content: Option<String> = sqlx::query_scalar(queries::get(state.db.kind(), queries::Q028))
|
||||||
"SELECT content FROM note_revisions WHERE id = ? AND note_id = ?",
|
|
||||||
)
|
|
||||||
.bind(payload.revision_id)
|
.bind(payload.revision_id)
|
||||||
.bind(note.id)
|
.bind(note.id)
|
||||||
.fetch_optional(&state.db)
|
.fetch_optional(state.db.pool())
|
||||||
.await?;
|
.await?;
|
||||||
let content = content.ok_or_else(ApiError::not_found_revision)?;
|
let content = content.ok_or_else(ApiError::not_found_revision)?;
|
||||||
let (revision_id, updated_at) =
|
let (revision_id, updated_at) =
|
||||||
@@ -445,18 +443,16 @@ pub async fn pad_restore(
|
|||||||
Json(payload): Json<RestoreRequest>,
|
Json(payload): Json<RestoreRequest>,
|
||||||
) -> Result<Json<serde_json::Value>, ApiError> {
|
) -> Result<Json<serde_json::Value>, ApiError> {
|
||||||
let pad = authorized_pad(&state, &slug, payload.password.as_deref()).await?;
|
let pad = authorized_pad(&state, &slug, payload.password.as_deref()).await?;
|
||||||
let content: Option<String> = sqlx::query_scalar(
|
let content: Option<String> = sqlx::query_scalar(queries::get(state.db.kind(), queries::Q029))
|
||||||
"SELECT content FROM revisions WHERE id = ? AND pad_id = ?",
|
|
||||||
)
|
|
||||||
.bind(payload.revision_id)
|
.bind(payload.revision_id)
|
||||||
.bind(pad.id)
|
.bind(pad.id)
|
||||||
.fetch_optional(&state.db)
|
.fetch_optional(state.db.pool())
|
||||||
.await?;
|
.await?;
|
||||||
let content = content.ok_or_else(ApiError::not_found_revision)?;
|
let content = content.ok_or_else(ApiError::not_found_revision)?;
|
||||||
let owner_map: Option<String> = sqlx::query_scalar("SELECT owner_map FROM revisions WHERE id = ? AND pad_id = ?")
|
let owner_map: Option<String> = sqlx::query_scalar(queries::get(state.db.kind(), queries::Q030))
|
||||||
.bind(payload.revision_id)
|
.bind(payload.revision_id)
|
||||||
.bind(pad.id)
|
.bind(pad.id)
|
||||||
.fetch_optional(&state.db)
|
.fetch_optional(state.db.pool())
|
||||||
.await?;
|
.await?;
|
||||||
let owner_map = owner_map.unwrap_or_else(|| "[]".into());
|
let owner_map = owner_map.unwrap_or_else(|| "[]".into());
|
||||||
let (revision_id, updated_at) = db::save_pad_revision(&state.db, pad.id, &content, Some("restore"), &owner_map).await?;
|
let (revision_id, updated_at) = db::save_pad_revision(&state.db, pad.id, &content, Some("restore"), &owner_map).await?;
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ pub const Q024: &str = "SELECT file_token FROM notes WHERE id = ?";
|
|||||||
pub const Q025: &str = "UPDATE notes SET file_token = ? WHERE id = ? AND file_token IS NULL";
|
pub const Q025: &str = "UPDATE notes SET file_token = ? WHERE id = ? AND file_token IS NULL";
|
||||||
pub const Q026: &str = "SELECT id FROM pads WHERE file_token = ?";
|
pub const Q026: &str = "SELECT id FROM pads WHERE file_token = ?";
|
||||||
pub const Q027: &str = "SELECT id FROM notes WHERE file_token = ?";
|
pub const Q027: &str = "SELECT id FROM notes WHERE file_token = ?";
|
||||||
|
pub const Q028: &str = "SELECT content FROM note_revisions WHERE id = ? AND note_id = ?";
|
||||||
|
pub const Q029: &str = "SELECT content FROM revisions WHERE id = ? AND pad_id = ?";
|
||||||
|
pub const Q030: &str = "SELECT owner_map FROM revisions WHERE id = ? AND pad_id = ?";
|
||||||
|
|
||||||
static POSTGRES_QUERIES: OnceLock<Mutex<HashMap<&'static str, &'static str>>> = OnceLock::new();
|
static POSTGRES_QUERIES: OnceLock<Mutex<HashMap<&'static str, &'static str>>> = OnceLock::new();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user