Skip to content

Instantly share code, notes, and snippets.

View patelgaurav4u's full-sized avatar

Gaurav Patel patelgaurav4u

  • Ahmedabad,Gujarat,India
View GitHub Profile
@vzsg
vzsg / 1_Fetch.swift
Last active June 25, 2021 10:37
A solution for the N+1 problem when fetching children for parents (Fluent 3)
import Fluent
func fetchChildren<Parent, ParentID, Child: Model, Result>(
of parents: [Parent],
idKey: KeyPath<Parent, ParentID?>,
via reference: KeyPath<Child, ParentID>,
on conn: DatabaseConnectable,
combining: @escaping (Parent, [Child]) -> Result) -> Future<[Result]> where ParentID: Hashable & Encodable {
let parentIDs = parents.compactMap { $0[keyPath: idKey] }
let children = Child.query(on: conn)
import Foundation
import UIKit
public class Checkmark: UIView {
// MARK: Public variables
public var initialLayerColor: UIColor = UIColor.blue {
didSet {
initialLayer.strokeColor = initialLayerColor.cgColor
}