Skip to content

use homebrew postgres driver. #7243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions frameworks/Rust/xitca-web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ xitca-http-codegen = "0.1"
xitca-server = "0.1"
xitca-service = "0.1"
xitca-web = "0.1"
xitca-postgres = "0.1"

ahash = { version = "0.7.6", features = ["compile-time-rng"] }
atoi = "0.4.0"
core_affinity = "0.5.10"
diesel = { git = "https://github.com/diesel-rs/diesel.git", rev = "37ec18f46ced2d6e9197414156fdb705d7a61426", default-features = false }
diesel = { version = "2", default-features = false }
diesel-async = { version = "0.1.0", features = ["postgres"], default-features = false }
futures-util = { version = "0.3.18", default-features = false, features = ["alloc"] }
mimalloc = { version = "0.1.27", default-features = false }
rand = { version = "0.8", default-features = false, features = ["min_const_gen", "small_rng"] }
sailfish = "0.3.3"
sailfish = "0.3.4"
serde = "1"
simd-json = "0.4.8"
tang-rs = "0.2"
tokio = { version = "1.14", features = ["macros", "rt"] }
tokio-postgres = "0.7.5"

[profile.release]
lto = true
Expand All @@ -40,15 +40,13 @@ codegen-units = 1
panic = "abort"

[patch.crates-io]
xitca-http = { git = "https://github.com/fakeshadow/xitca-web.git", rev = "59827177f6c319c6fa9940fe5f146754fff90aad" }
xitca-http-codegen = { git = "https://github.com/fakeshadow/xitca-web.git", rev = "59827177f6c319c6fa9940fe5f146754fff90aad" }
xitca-io = { git = "https://github.com/fakeshadow/xitca-web.git", rev = "59827177f6c319c6fa9940fe5f146754fff90aad" }
xitca-server = { git = "https://github.com/fakeshadow/xitca-web.git", rev = "59827177f6c319c6fa9940fe5f146754fff90aad" }
xitca-service = { git = "https://github.com/fakeshadow/xitca-web.git", rev = "59827177f6c319c6fa9940fe5f146754fff90aad" }
xitca-web = { git = "https://github.com/fakeshadow/xitca-web.git", rev = "59827177f6c319c6fa9940fe5f146754fff90aad" }

diesel = { git = "https://github.com/diesel-rs/diesel.git", rev = "37ec18f46ced2d6e9197414156fdb705d7a61426" }
diesel-async = { git = "https://github.com/weiznich/diesel_async.git", rev = "06b3416826dbc8ce404f6d613daea989b23549ca" }

# this is not right. but not much can be done when the maintainer is unactive.
sailfish = { git = "https://github.com/jdrouet/sailfish", rev = "7d2b59247eaab10b67311d6c1c7d50a7d751d791" }
xitca-http = { git = "https://github.com/fakeshadow/xitca-web.git", rev = "e1debcd4630196669923f94c7693e5519f34db52" }
xitca-http-codegen = { git = "https://github.com/fakeshadow/xitca-web.git", rev = "e1debcd4630196669923f94c7693e5519f34db52" }
xitca-io = { git = "https://github.com/fakeshadow/xitca-web.git", rev = "e1debcd4630196669923f94c7693e5519f34db52" }
xitca-postgres = { git = "https://github.com/fakeshadow/xitca-web.git", rev = "e1debcd4630196669923f94c7693e5519f34db52" }
xitca-server = { git = "https://github.com/fakeshadow/xitca-web.git", rev = "e1debcd4630196669923f94c7693e5519f34db52" }
xitca-service = { git = "https://github.com/fakeshadow/xitca-web.git", rev = "e1debcd4630196669923f94c7693e5519f34db52" }
xitca-web = { git = "https://github.com/fakeshadow/xitca-web.git", rev = "e1debcd4630196669923f94c7693e5519f34db52" }

diesel = { git = "https://github.com/fakeshadow/diesel.git", rev = "ed2ceeb377c986c1013c6261e44658e3f43725d3" }
diesel-async = { git = "https://github.com/fakeshadow/diesel_async.git", rev = "dc2e77677299aa6b406353960a9eab7a7bd5bc72" }
36 changes: 28 additions & 8 deletions frameworks/Rust/xitca-web/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,51 @@ use ahash::AHashMap;
use futures_util::stream::{FuturesUnordered, StreamExt, TryStreamExt};
use rand::{rngs::SmallRng, Rng, SeedableRng};
use tokio::pin;
use tokio_postgres::{types::ToSql, NoTls, Statement};
use xitca_postgres::{Postgres, Statement, ToSql};

use super::ser::{Fortune, Fortunes, World};

pub struct Client {
client: tokio_postgres::Client,
client: xitca_postgres::Client,
rng: RefCell<SmallRng>,
fortune: Statement,
world: Statement,
updates: AHashMap<u16, Statement>,
}

impl Drop for Client {
fn drop(&mut self) {
drop(self.fortune.clone().into_guarded(&self.client));

drop(self.world.clone().into_guarded(&self.client));

for (_, stmt) in std::mem::take(&mut self.updates) {
drop(stmt.into_guarded(&self.client))
}
}
}

pub async fn create(config: &str) -> Client {
let (client, conn) = tokio_postgres::connect(config, NoTls).await.unwrap();
let (client, conn) = Postgres::new(config).connect().await.unwrap();

tokio::task::spawn_local(async move {
let _ = conn.await;
});

let fortune = client.prepare("SELECT * FROM fortune").await.unwrap();
let fortune = client
.prepare("SELECT * FROM fortune", &[])
.await
.unwrap()
.leak();

let world = client
.prepare("SELECT * FROM world WHERE id=$1")
.prepare("SELECT * FROM world WHERE id=$1", &[])
.await
.unwrap();
.unwrap()
.leak();

let mut updates = AHashMap::new();

for num in 1..=500u16 {
let mut pl = 1;
let mut q = String::new();
Expand All @@ -45,7 +65,7 @@ pub async fn create(config: &str) -> Client {
q.pop();
q.push(')');

let st = client.prepare(&q).await.unwrap();
let st = client.prepare(&q, &[]).await.unwrap().leak();
updates.insert(num, st);
}

Expand Down Expand Up @@ -130,7 +150,7 @@ impl Client {

let stream = self
.client
.query_raw::<_, _, &[i32; 0]>(&self.fortune, &[])
.query_raw::<_, &[i32; 0]>(&self.fortune, &[])
.await?;

pin!(stream);
Expand Down
4 changes: 1 addition & 3 deletions frameworks/Rust/xitca-web/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use self::util::{
TEXT_HEADER_VALUE,
};

type Request = http::Request<RequestBody>;
type Request = xitca_http::Request<RequestBody>;

type Response = http::Response<ResponseBody>;

Expand Down Expand Up @@ -162,14 +162,12 @@ impl HttpService {
}
}

#[inline]
async fn _fortunes(&self) -> Result<Bytes, Box<dyn Error>> {
use sailfish::TemplateOnce;
let fortunes = self.state.client().tell_fortune().await?.render_once()?;
Ok(fortunes.into())
}

#[inline]
fn _json<S>(&self, req: Request, value: &S) -> Result<Response, Infallible>
where
S: ?Sized + Serialize,
Expand Down
6 changes: 3 additions & 3 deletions frameworks/Rust/xitca-web/src/main_diesel.rs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod schema;
mod ser;
mod util;

use std::{error::Error, io};
use std::{convert::Infallible, error::Error, io};

use serde::Serialize;
use xitca_web::{
Expand Down Expand Up @@ -37,8 +37,8 @@ async fn main() -> io::Result<()> {

HttpServer::new(move || {
App::with_async_state(move || async move {
let pool = create(config).await.map_err(|_| ())?;
Ok(AppState::new(pool))
let pool = create(config).await.unwrap();
Ok::<_, Infallible>(AppState::new(pool))
})
.service(fn_service(handle))
})
Expand Down
4 changes: 2 additions & 2 deletions frameworks/Rust/xitca-web/xitca-web-diesel.dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM rust:1.58
FROM rust:1.59

ADD ./ /xitca-web
WORKDIR /xitca-web

RUN rustup default nightly-2022-01-26
RUN rustup default nightly-2022-03-24
RUN cargo clean
RUN RUSTFLAGS="-C target-cpu=native" cargo build --release --bin xitca-web-diesel

Expand Down
4 changes: 2 additions & 2 deletions frameworks/Rust/xitca-web/xitca-web.dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM rust:1.58
FROM rust:1.59

ADD ./ /xitca-web
WORKDIR /xitca-web

RUN rustup default nightly-2022-01-26
RUN rustup default nightly-2022-03-24
RUN cargo clean
RUN RUSTFLAGS="-C target-cpu=native" cargo build --release --bin xitca-web

Expand Down