| 30 | #[async_trait::async_trait] |
| 31 | impl ProxyDatabaseTrait for ProxyDb { |
| 32 | async fn query(&self, statement: Statement) -> Result<Vec<ProxyRow>, DbErr> { |
| 33 | println!("SQL query: {:?}", statement); |
| 34 | let sql = statement.sql.clone(); |
| 35 | |
| 36 | let mut ret: Vec<ProxyRow> = vec![]; |
| 37 | async_std::task::block_on(async { |
| 38 | for payload in self.mem.lock().unwrap().execute(sql).await.unwrap().iter() { |
| 39 | match payload { |
| 40 | gluesql::prelude::Payload::Select { labels, rows } => { |
| 41 | for row in rows.iter() { |
| 42 | let mut map = BTreeMap::new(); |
| 43 | for (label, column) in labels.iter().zip(row.iter()) { |
| 44 | map.insert( |
| 45 | label.to_owned(), |
| 46 | match column { |
| 47 | gluesql::prelude::Value::I64(val) => { |
| 48 | sea_orm::Value::BigInt(Some(*val)) |
| 49 | } |
| 50 | gluesql::prelude::Value::Str(val) => { |
| 51 | sea_orm::Value::String(Some(Box::new(val.to_owned()))) |
| 52 | } |
| 53 | _ => unreachable!("Unsupported value: {:?}", column), |
| 54 | }, |
| 55 | ); |
| 56 | } |
| 57 | ret.push(map.into()); |
| 58 | } |
| 59 | } |
| 60 | _ => unreachable!("Unsupported payload: {:?}", payload), |
| 61 | } |
| 62 | } |
| 63 | }); |
| 64 | |
| 65 | Ok(ret) |
| 66 | } |
| 67 | |
| 68 | async fn execute(&self, statement: Statement) -> Result<ProxyExecResult, DbErr> { |
| 69 | let sql = if let Some(values) = statement.values { |