Created
February 22, 2018 21:50
-
-
Save pedantix/4f425ef7a87f83023d7916275bfe0ff4 to your computer and use it in GitHub Desktop.
A Futuristic Eagerload idea for fluent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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