Browse Source

Update anansi (#7936)

* Update to anansi 0.13.1

* Update to anansi 0.13.2

* Fixed anansi

---------

Co-authored-by: sarutora <example.com>
saru-tora 2 years ago
parent
commit
7f98f8109d

+ 2 - 1
frameworks/Rust/anansi/Cargo.toml

@@ -12,8 +12,9 @@ edition = "2021"
 raw = []
 
 [dependencies]
-anansi = { git = "https://github.com/saru-tora/anansi", rev = "7098e09", features = ["postgres", "minimal", "redis"] }
+anansi = { git = "https://github.com/saru-tora/anansi", rev = "94cae98", features = ["postgres", "minimal", "redis"] }
 async-trait = "0.1.57"
 rand = "0.8.4"
 serde = { version = "1.0", features = ["derive"] }
 serde_json = "1.0"
+tokio-postgres = "0.7.7"

+ 0 - 1
frameworks/Rust/anansi/settings.toml

@@ -16,4 +16,3 @@ name = "hello_world"
 user = "benchmarkdbuser"
 password = "benchmarkdbpass"
 address = "tfb-database"
-max_conn = 512

+ 2 - 2
frameworks/Rust/anansi/src/hello/records.rs

@@ -15,7 +15,7 @@ pub struct World {
 
 #[async_trait]
 impl<R: BaseRequest> Relate<R> for World {
-    async fn on_save(&self, _req: &R) -> Result<()> {
+    async fn on_save(&self, _req: &mut R) -> Result<()> {
         unimplemented!();
     }
     async fn on_delete(&self, _req: &R) -> Result<()> {
@@ -38,7 +38,7 @@ impl Fortune {
 
 #[async_trait]
 impl<R: BaseRequest> Relate<R> for Fortune {
-    async fn on_save(&self, _req: &R) -> Result<()> {
+    async fn on_save(&self, _req: &mut R) -> Result<()> {
         unimplemented!();
     }
     async fn on_delete(&self, _req: &R) -> Result<()> {

+ 12 - 8
frameworks/Rust/anansi/src/hello/world/raw.rs

@@ -7,6 +7,7 @@ use std::borrow::Cow;
 use anansi::db::DbRow;
 use rand::Rng;
 use std::fmt::Write;
+use tokio_postgres::types::ToSql;
 
 thread_local!(static UPDATES: Vec<Cow<'static, str>> = {
     let mut updates = vec![Cow::from("")];
@@ -55,8 +56,7 @@ fn base<R: Request>(_req: &mut R) -> Result<Response> {}
 #[viewer]
 impl<R: Request> WorldView<R> {
     async fn get_world(req: &R) -> Result<PgDbRow> {
-        PgQuery::new("SELECT * FROM world WHERE id = $1")
-            .bind(random_num())
+        PgQuery::new("SELECT * FROM world WHERE id = $1", &[&random_num()])
             .fetch_one(req)
             .await
     }
@@ -90,7 +90,7 @@ impl<R: Request> WorldView<R> {
     #[view(Site::is_visitor)]
     pub async fn raw_fortunes(req: &mut R) -> Result<Response> {
         let title = "Fortunes";
-        let rows = PgQuery::new("SELECT * FROM fortune")
+        let rows = PgQuery::new("SELECT * FROM fortune", &[])
             .fetch_all(req)
             .await?;
         let mut fortunes = vec![Fortune {
@@ -113,21 +113,25 @@ impl<R: Request> WorldView<R> {
         UPDATES.with(|u| {
             update = u[q].clone();
         });
-        let mut updates = PgQuery::new(&update);
+        let mut params: Vec<&(dyn ToSql + Sync)> = Vec::with_capacity(q * 3);
         for _ in 0..q {
             let row = Self::get_world(req).await?;
             let world = World {
                 id: row.try_i32("id")?,
                 randomnumber: random_num(),
             };
-            updates = updates.bind(world.id)
-                .bind(world.randomnumber);
             worlds.push(world);
         }
         for world in &worlds {
-            updates = updates.bind(world.id);
+            params.push(&world.id);
+            params.push(&world.randomnumber);
         }
-        updates.execute(req).await?;
+        for world in &worlds {
+            params.push(&world.id);
+        }
+        PgQuery::new(&update, params.as_slice())
+            .execute(req)
+            .await?;
         Response::json(&worlds)
     }
 }

+ 1 - 1
frameworks/Rust/anansi/src/hello/world/templates/.parsed/base.in

@@ -6,4 +6,4 @@
         <body>
                 ");_c.push_str(&_base_args._content);_c.push_str("
         </body>
-</html>");Ok(anansi::web::Response::new(200, _c.into_bytes()))}
+</html>");_c.into_bytes()}

+ 1 - 1
frameworks/Rust/anansi/src/http_errors/templates/.parsed/not_found.in

@@ -8,4 +8,4 @@
 		<h1>404</h1>
 		<p>Page not found.</p>
 	</body>
-</html>");Ok(anansi::web::Response::new(200, _c.into_bytes()))}
+</html>");_c.into_bytes()}