#data-loader #load #pattern #queries #async-await #avoiding #batch

async_dataloader

Powerful tool for avoiding N+1 queries using async/await, based on the DataLoader pattern

4 releases

0.1.3 Mar 22, 2021
0.1.2 Mar 22, 2021
0.1.1 Mar 22, 2021
0.1.0 Mar 22, 2021

#994 in Asynchronous

MIT license

20KB
367 lines

async_dataloader

Powerful tool for avoiding N+1 queries using async/await, based on the DataLoader pattern.

data_loader batches loads which occur during a single "poll" - no artificial delay required.

Design inspired by https://github.com/exAspArk/batch-loader and https://github.com/graphql/dataloader


lib.rs:

Powerful for avoiding N+1 queries with async/await, based on the DataLoader pattern.

data_loader batches loads which occur during a single "poll", without requiring an artificial delay.

Design inspired by https://github.com/exAspArk/batch-loader and https://github.com/graphql/dataloader

Usage

use async_dataloader::{def_batch_loader, batched};

def_batch_loader! {
    pub async fn loader(inputs: u64) -> String {
        inputs.map(|input| {
             input.to_string()
        })
    }
}

batched(async {
    assert_eq!(*loader(1).await, "1".to_owned());
}).await

Dependencies

~1MB
~16K SLoC