Skip to content

Commit

Permalink
Update to anansi 0.14.0 (TechEmpower#7989)
Browse files Browse the repository at this point in the history
* Update to anansi 0.14.0

* Fixed db test for anansi

---------

Co-authored-by: sarutora <example.com>
  • Loading branch information
saru-tora authored Mar 7, 2023
1 parent 62b10d9 commit 062ab19
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion frameworks/Rust/anansi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ edition = "2021"
raw = []

[dependencies]
anansi = { git = "https://github.com/saru-tora/anansi", rev = "18fc179", features = ["postgres", "minimal", "redis"] }
anansi = { git = "https://github.com/saru-tora/anansi", rev = "bcbd687", features = ["postgres", "minimal", "redis"] }
async-trait = "0.1.57"
rand = "0.8.4"
serde = "1"
Expand Down
4 changes: 2 additions & 2 deletions frameworks/Rust/anansi/src/hello/world/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn base<R: Request>(_req: &mut R) -> Result<Response> {}
#[viewer]
impl<R: Request> WorldView<R> {
async fn get_world(req: &R) -> Result<PgDbRow> {
prep!(req, "world", "SELECT * FROM world WHERE id = $1", &[&random_num()], fetch_one)
anansi::db::postgres::PgStatement::raw_one(0, &[&random_num()], req.raw().pool()).await
}
async fn get_worlds(req: &R) -> Result<Vec<World>> {
let q = get_query(req.params());
Expand Down Expand Up @@ -83,7 +83,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 = prep!(req, "fortune", "SELECT * FROM fortune", &[], fetch_all)?;
let rows = anansi::db::postgres::PgStatement::raw_all(1, &[], req.raw().pool()).await?;
let mut fortunes = vec![Fortune {
id: 0,
message: Cow::Borrowed("Additional fortune added at request time.")
Expand Down
28 changes: 15 additions & 13 deletions frameworks/Rust/anansi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ apps! {
app_statics! {}

min_main!(server, {
{
use anansi::cache::prelude::*;
use hello::records::World;
use anansi::records::Record;
let worlds = World::get_all().raw_query(&server.pool).await.expect("problem fetching worlds");
let mut items = vec![];
for world in worlds {
let id = world.pk().to_string();
let mut bytes = serde_json::to_vec(&world).expect("problem serializing world");
bytes.push(',' as u8);
items.push((id, bytes));
}
server.cache.set_many(&items).await.expect("problem caching world");
use anansi::cache::prelude::*;
use hello::records::World;
use anansi::records::Record;
if cfg!(feature = "raw") {
server.pool.2.write().unwrap().push(Arc::new(anansi::db::postgres::PgStatement::new("SELECT * FROM world WHERE id = $1", &server.pool).await.unwrap()));
server.pool.2.write().unwrap().push(Arc::new(anansi::db::postgres::PgStatement::new("SELECT * FROM fortune", &server.pool).await.unwrap()));
}
let worlds = World::get_all().raw_query(&server.pool).await.expect("problem fetching worlds");
let mut items = vec![];
for world in worlds {
let id = world.pk().to_string();
let mut bytes = serde_json::to_vec(&world).expect("problem serializing world");
bytes.push(',' as u8);
items.push((id, bytes));
}
server.cache.set_many(&items).await.expect("problem caching world");
});

0 comments on commit 062ab19

Please sign in to comment.