我需要对不同的表进行大量查询,并在一个响应中返回结果。我想知道我可以展平极其嵌套的函数吗?
final class CodeController {
internal func indexCodes(_ req: Request) throws -> EventLoopFuture<Response> {
CodeCountry.query(on: req).sort(\.name).all().flatMap { countries -> EventLoopFuture<Response> in
CodeFloor.query(on: req).sort(\.name).all().flatMap { floors -> EventLoopFuture<Response> in
CodeRegion.query(on: req).sort(\.name).all().flatMap { regions -> EventLoopFuture<Response> in
CodeObjectType.query(on: req).sort(\.name).all().flatMap { objectTypes -> EventLoopFuture<Response> in
CodePropertyType.query(on: req).sort(\.name).all().flatMap { propertyTypes -> EventLoopFuture<Response> in
CodeRooms.query(on: req).sort(\.name).all().flatMap { rooms -> EventLoopFuture<Response> in
let codes = CodesContent(
countries: countries,
floors: floors,
regions: regions,
objectTypes: objectTypes,
propertyTypes: propertyTypes,
rooms: rooms
)
return codes.encode(status: .ok, for: req)
}
}
}
}
}
}
}
}