|
1 | | -use crate::{prelude::W, utils::macros::map}; |
| 1 | +use crate::utils::macros::map; |
2 | 2 | use chrono::{DateTime, Utc}; |
3 | 3 | use serde::{Deserialize, Serialize}; |
4 | 4 | use std::{collections::BTreeMap, sync::Arc}; |
5 | 5 | use surrealdb::{ |
6 | 6 | dbs::{Response, Session}, |
7 | 7 | kvs::Datastore, |
8 | | - sql::{thing, Array, Object, Value}, |
| 8 | + sql::{thing, Value}, |
9 | 9 | }; |
10 | 10 |
|
11 | 11 | #[derive(Debug, Serialize, Deserialize)] |
@@ -66,37 +66,35 @@ impl DB { |
66 | 66 | Ok(res) |
67 | 67 | } |
68 | 68 |
|
69 | | - pub async fn add_task(&self, title: &str) -> Result<Object, crate::error::Error> { |
| 69 | + pub async fn add_task(&self, title: &str) -> Result<serde_json::Value, crate::error::Error> { |
70 | 70 | let sql = "CREATE tasks SET title = $title, completed = false, created_at = time::now()"; |
71 | 71 | let vars: BTreeMap<String, Value> = map!["title".into() => Value::Strand(title.into())]; |
72 | 72 | let res = self.execute(sql, Some(vars)).await?; |
73 | 73 |
|
74 | 74 | let first_res = res.into_iter().next().expect("Did not get a response"); |
75 | 75 |
|
76 | | - W(first_res.result?.first()).try_into() |
| 76 | + Ok(first_res.result?.into_json()) |
77 | 77 | } |
78 | 78 |
|
79 | | - pub async fn get_task(&self, id: &str) -> Result<Object, crate::error::Error> { |
| 79 | + pub async fn get_task(&self, id: &str) -> Result<serde_json::Value, crate::error::Error> { |
80 | 80 | let sql = "SELECT * FROM $th"; |
81 | 81 | let tid = format!("{}", id); |
82 | 82 | let vars: BTreeMap<String, Value> = map!["th".into() => thing(&tid)?.into()]; |
83 | 83 | let ress = self.execute(sql, Some(vars)).await?; |
84 | 84 |
|
85 | 85 | let first_res = ress.into_iter().next().expect("Did not get a response"); |
86 | 86 |
|
87 | | - W(first_res.result?.first()).try_into() |
| 87 | + Ok(first_res.result?.into_json()) |
88 | 88 | } |
89 | 89 |
|
90 | | - pub async fn get_all_tasks(&self) -> Result<Vec<Object>, crate::error::Error> { |
| 90 | + pub async fn get_all_tasks(&self) -> Result<serde_json::Value, crate::error::Error> { |
91 | 91 | let sql = "SELECT * FROM tasks ORDER BY created_at ASC;"; |
92 | 92 |
|
93 | 93 | let res = self.execute(sql, None).await?; |
94 | 94 |
|
95 | 95 | let first_res = res.into_iter().next().expect("Did not get a response"); |
96 | 96 |
|
97 | | - let array: Array = W(first_res.result?).try_into()?; |
98 | | - |
99 | | - array.into_iter().map(|value| W(value).try_into()).collect() |
| 97 | + Ok(first_res.result?.into_json()) |
100 | 98 | } |
101 | 99 |
|
102 | 100 | pub async fn toggle_task(&self, id: &str) -> Result<AffectedRows, crate::error::Error> { |
|
0 commit comments