mirror of
https://github.com/docker/awesome-compose.git
synced 2025-04-26 10:43:35 +02:00
refacto(react-rust-postgres): replace rocket by actix-web (#153)
Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com>
This commit is contained in:
parent
0ae9d4cea7
commit
a13fabe604
14 changed files with 114 additions and 172 deletions
|
@ -1,18 +1,25 @@
|
|||
#![allow(proc_macro_derive_resolution_fallback)]
|
||||
use tokio_postgres::{Error, GenericClient, Row};
|
||||
|
||||
use diesel;
|
||||
use diesel::prelude::*;
|
||||
use super::schema::users;
|
||||
|
||||
#[derive(Queryable, AsChangeset, Serialize, Deserialize)]
|
||||
#[table_name = "users"]
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
pub struct User {
|
||||
pub id: i32,
|
||||
pub login: String,
|
||||
}
|
||||
|
||||
impl User {
|
||||
pub fn all(connection: &PgConnection) -> QueryResult<Vec<User>> {
|
||||
users::table.load::<User>(&*connection)
|
||||
impl From<Row> for User {
|
||||
fn from(row: Row) -> Self {
|
||||
Self {
|
||||
id: row.get(0),
|
||||
login: row.get(1),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl User {
|
||||
pub async fn all<C: GenericClient>(client: &C) -> Result<Vec<User>, Error> {
|
||||
let stmt = client.prepare("SELECT id, login FROM users").await?;
|
||||
let rows = client.query(&stmt, &[]).await?;
|
||||
|
||||
Ok(rows.into_iter().map(User::from).collect())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue