Skip to content

Implementation of Facebook's DataLoader in Golang

License

Notifications You must be signed in to change notification settings

telrikk/dataloader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DataLoader

GoDoc Build Status Coverage

This is an implementation of Facebook's DataLoader in Golang.

Status

This project is a work in progress. Feedback is encouraged.

Usage

// setup batch function
batchFn := func(keys []string) []dataloader.Result {
  var results []dataloader.Result
  // do some aync work to get data for specified keys
  // append to this list resolved values
  return results
}

// create Loader with an in-memory cache
loader := dataloader.NewBatchedLoader(batchFn)

/**
 * Use loader
 *
 * A thunk is a function returned from a function that is a 
 * closure over a value (in this case a `Result` struct).
 * When called, it will block until the value is resolved.
 */
thunk := loader.Load("key1")
result := thunk()
if result.Error != nil {
  // handle data error
}

log.Printf("value: %#v", result.Data)

Cache

This implementation contains a very basic cache that is intended only to be used for short lived DataLoaders (i.e. DataLoaders that ony exsist for the life of an http request). You may use your own implementation if you want.

it also has a NoCache type that implements the cache interface but all methods are noop. If you do not wish to cache anyting.

Examples

There are a few basic examples in the example folder. More coming soon!

TODO

  • Write More Tests

About

Implementation of Facebook's DataLoader in Golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%