Skip to content

Instantly share code, notes, and snippets.

@pedantix
Created February 22, 2018 21:50
Show Gist options
  • Save pedantix/4f425ef7a87f83023d7916275bfe0ff4 to your computer and use it in GitHub Desktop.
Save pedantix/4f425ef7a87f83023d7916275bfe0ff4 to your computer and use it in GitHub Desktop.
A Futuristic Eagerload idea for fluent
// Per Tanner
let cache = \User.pets.prefetchCache()
let users = User.query(on: ...).filter(...).prefetching(\.pets, into: cache).all() // await
for user in users {
let pets = user.pets.get(from: cache)
}
// Shaun's idea
struct User: Model {
var pets: Childeren<User, Pet>?
var children: Childeren<User, User>?
var creditCards: Childeren<User, CreditCard>?
}
// Query For Users and Kids, not credit cards those need to be secure
let cacheService = req.make(CacheService.self)
let userQueryBuilder = /// your user query
let user = userQueryBuilder.prefetch(\.pets, \.children, into: cacheService).first().blockingAway()
user.pets // has pets data
user.children // has child data
user.creditCards // is nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment