Crate deque_loader[][src]

Expand description
use async_graphql::SimpleObject;
use deque_loader::diesel::{DieselError, DieselLoader, DieselHandler};
use db::schema::users;
use diesel::prelude::*;
use diesel_connection::PooledConnection;
use std::{collections::HashMap, sync::Arc};

derive_id! {
  #[table_name = "users"]
  #[graphql(name = "UserID")]
  pub struct UserId( #[column_name = "id"] i32);

#[derive(SimpleObject, Loadable, Identifiable, Associations, Queryable, Debug, Clone)]
#[data_loader(handler = "DieselHandler<UserLoader>")]
#[belongs_to(UserId, foreign_key = "id")]
#[table_name = "users"]
pub struct User {
  pub id: i32,
  pub name: String,

#[data_loader(handler = "DieselHandler<UserLoader>")]
pub struct UserLoader;

impl DieselLoader for UserLoader {
  type Key = UserId;
  type Value = User;
  fn load(
    conn: PooledConnection,
    keys: Vec<UserId>,
  ) -> Result<HashMap<Self::Key, Arc<Self::Value>>, DieselError> {
    let users: Vec<User> = User::belonging_to(&keys)

    let users = users.into_iter().map(Arc::new);

    let mut data: HashMap<UserId, Arc<User>> = HashMap::new();





Register cache factory for a TaskHandler using inventory. This will require adding inventory to your dependencies as well.


Params to [crate::Loadable::load_by]; typically i32 or newtype wrapper

Derive Macros