|
1 | | -use tracing::{debug, error, info}; |
2 | | - |
3 | | -pub async fn save_kv(pool: &sqlx::PgPool, key: &str, value: String) { |
4 | | - let query = sqlx::query!( |
5 | | - "\ |
6 | | -INSERT INTO kv_store (id, content) |
7 | | - VALUES ($1, $2) |
8 | | - ON CONFLICT(id) |
9 | | - DO UPDATE SET |
10 | | - content = EXCLUDED.content;", |
11 | | - key, |
12 | | - value |
13 | | - ); |
14 | | - match query.execute(pool).await { |
15 | | - Ok(query_result) => { |
16 | | - if query_result.rows_affected() == 1 { |
17 | | - debug!("Save completed for key: {key}"); |
18 | | - } else { |
19 | | - error!( |
20 | | - ?key, |
21 | | - "Expected 1 row to be affected by save but got: {}", |
22 | | - query_result.rows_affected() |
23 | | - ) |
24 | | - } |
25 | | - } |
26 | | - Err(err_msg) => error!( |
27 | | - ?err_msg, |
28 | | - "Failed to save content for key: {key} to kv store" |
29 | | - ), |
30 | | - } |
| 1 | +pub async fn save_kv(key: &str, value: String) { |
| 2 | + todo!("save to disk") |
| 3 | + // let query = sqlx::query!( |
| 4 | + // "\ |
| 5 | + // INSERT INTO kv_store (id, content) |
| 6 | + // VALUES ($1, $2) |
| 7 | + // ON CONFLICT(id) |
| 8 | + // DO UPDATE SET |
| 9 | + // content = EXCLUDED.content;", |
| 10 | + // key, |
| 11 | + // value |
| 12 | + // ); |
| 13 | + // match query.execute(pool).await { |
| 14 | + // Ok(query_result) => { |
| 15 | + // if query_result.rows_affected() == 1 { |
| 16 | + // debug!("Save completed for key: {key}"); |
| 17 | + // } else { |
| 18 | + // error!( |
| 19 | + // ?key, |
| 20 | + // "Expected 1 row to be affected by save but got: {}", |
| 21 | + // query_result.rows_affected() |
| 22 | + // ) |
| 23 | + // } |
| 24 | + // } |
| 25 | + // Err(err_msg) => error!( |
| 26 | + // ?err_msg, |
| 27 | + // "Failed to save content for key: {key} to kv store" |
| 28 | + // ), |
| 29 | + // } |
31 | 30 | } |
32 | 31 |
|
33 | | -pub async fn load_kv(pool: &sqlx::PgPool, key: &str) -> Option<String> { |
34 | | - match sqlx::query!("SELECT content FROM kv_store where id = $1", key) |
35 | | - .fetch_optional(pool) |
36 | | - .await |
37 | | - { |
38 | | - Ok(Some(record)) => Some(record.content), |
39 | | - Ok(None) => { |
40 | | - info!("No content found in DB for key: {key}"); |
41 | | - None |
42 | | - } |
43 | | - Err(err_msg) => { |
44 | | - error!(?err_msg, "Failed to get content for key: {key}"); |
45 | | - None |
46 | | - } |
47 | | - } |
| 32 | +pub async fn load_kv(key: &str) -> Option<String> { |
| 33 | + todo!("load from disk") |
| 34 | + // match sqlx::query!("SELECT content FROM kv_store where id = $1", key) |
| 35 | + // .fetch_optional(pool) |
| 36 | + // .await |
| 37 | + // { |
| 38 | + // Ok(Some(record)) => Some(record.content), |
| 39 | + // Ok(None) => { |
| 40 | + // info!("No content found in DB for key: {key}"); |
| 41 | + // None |
| 42 | + // } |
| 43 | + // Err(err_msg) => { |
| 44 | + // error!(?err_msg, "Failed to get content for key: {key}"); |
| 45 | + // None |
| 46 | + // } |
| 47 | + // } |
48 | 48 | } |
0 commit comments