From c2b988a2681b840b7b9cb226d9b4c6315ab429fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8A=E6=AC=A7?= Date: Fri, 24 Nov 2023 10:39:22 +0800 Subject: [PATCH] refactor: Bump gluesql to 0.15 Relate to https://github.com/gluesql/gluesql/issues/1438 --- examples/proxy_gluesql_example/Cargo.toml | 5 +- examples/proxy_gluesql_example/src/main.rs | 60 ++++++++++++---------- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/examples/proxy_gluesql_example/Cargo.toml b/examples/proxy_gluesql_example/Cargo.toml index 1b30009e8..2a09fd8fe 100644 --- a/examples/proxy_gluesql_example/Cargo.toml +++ b/examples/proxy_gluesql_example/Cargo.toml @@ -21,10 +21,7 @@ sea-orm = { path = "../../", features = [ "runtime-async-std-native-tls", "debug-print", ] } -# Since it's newer version (0.14.0) locked the chrono's version to 0.4.23, -# we need to lock it on older version too. -# Related to https://github.com/gluesql/gluesql/pull/1427 -gluesql = { version = "0.13", default-features = false, features = [ +gluesql = { version = "0.15", default-features = false, features = [ "memory-storage", ] } diff --git a/examples/proxy_gluesql_example/src/main.rs b/examples/proxy_gluesql_example/src/main.rs index 616b612fa..06dceaa6b 100644 --- a/examples/proxy_gluesql_example/src/main.rs +++ b/examples/proxy_gluesql_example/src/main.rs @@ -33,37 +33,39 @@ impl ProxyDatabaseTrait for ProxyDb { let sql = statement.sql.clone(); let mut ret: Vec = vec![]; - for payload in self.mem.lock().unwrap().execute(sql).unwrap().iter() { - match payload { - gluesql::prelude::Payload::Select { labels, rows } => { - for row in rows.iter() { - let mut map = BTreeMap::new(); - for (label, column) in labels.iter().zip(row.iter()) { - map.insert( - label.to_owned(), - match column { - gluesql::prelude::Value::I64(val) => { - sea_orm::Value::BigInt(Some(*val)) - } - gluesql::prelude::Value::Str(val) => { - sea_orm::Value::String(Some(Box::new(val.to_owned()))) - } - _ => unreachable!("Unsupported value: {:?}", column), - }, - ); + async_std::task::block_on(async { + for payload in self.mem.lock().unwrap().execute(sql).await.unwrap().iter() { + match payload { + gluesql::prelude::Payload::Select { labels, rows } => { + for row in rows.iter() { + let mut map = BTreeMap::new(); + for (label, column) in labels.iter().zip(row.iter()) { + map.insert( + label.to_owned(), + match column { + gluesql::prelude::Value::I64(val) => { + sea_orm::Value::BigInt(Some(*val)) + } + gluesql::prelude::Value::Str(val) => { + sea_orm::Value::String(Some(Box::new(val.to_owned()))) + } + _ => unreachable!("Unsupported value: {:?}", column), + }, + ); + } + ret.push(map.into()); } - ret.push(map.into()); } + _ => unreachable!("Unsupported payload: {:?}", payload), } - _ => unreachable!("Unsupported payload: {:?}", payload), } - } + }); Ok(ret) } fn execute(&self, statement: Statement) -> Result { - if let Some(values) = statement.values { + let sql = if let Some(values) = statement.values { // Replace all the '?' with the statement values let mut new_sql = statement.sql.clone(); let mark_count = new_sql.matches('?').count(); @@ -73,12 +75,15 @@ impl ProxyDatabaseTrait for ProxyDb { } new_sql = new_sql.replacen('?', &v.to_string(), 1); } - println!("SQL execute: {}", new_sql); - - self.mem.lock().unwrap().execute(new_sql).unwrap(); + new_sql } else { - self.mem.lock().unwrap().execute(statement.sql).unwrap(); - } + statement.sql + }; + + println!("SQL execute: {}", sql); + async_std::task::block_on(async { + self.mem.lock().unwrap().execute(sql).await.unwrap(); + }); Ok(ProxyExecResult { last_insert_id: 1, @@ -101,6 +106,7 @@ async fn main() { ) "#, ) + .await .unwrap(); let db = Database::connect_proxy(