-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RawComputedFields and distinct (#57)
- Loading branch information
1 parent
13aa3d7
commit c6582b2
Showing
4 changed files
with
212 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// | ||
// People.swift | ||
// MongoDriverTests | ||
// | ||
// Created by Valerio Mazzeo on 25/10/2018. | ||
// | ||
|
||
import Foundation | ||
import Fluent | ||
|
||
final class Adult: Entity { | ||
|
||
public let name: String | ||
|
||
public init(name: String) { | ||
self.name = name | ||
} | ||
|
||
// MARK: Storable | ||
|
||
public let storage = Storage() | ||
|
||
// MARK: RowConvertible | ||
|
||
public convenience init(row: Row) throws { | ||
|
||
self.init( | ||
name: try row.get("name") | ||
) | ||
} | ||
|
||
public func makeRow() throws -> Row { | ||
|
||
var row = Row() | ||
|
||
try row.set(Adult.idKey, self.id) | ||
try row.set("name", self.name) | ||
|
||
return row | ||
} | ||
} | ||
|
||
final class Child: Entity { | ||
|
||
public let name: String | ||
|
||
public var age: Int | ||
|
||
public var parentId: Identifier | ||
|
||
public init(name: String, age: Int, parentId: Identifier) { | ||
self.name = name | ||
self.age = age | ||
self.parentId = parentId | ||
} | ||
|
||
// MARK: Storable | ||
|
||
public let storage = Storage() | ||
|
||
// MARK: RowConvertible | ||
|
||
public convenience init(row: Row) throws { | ||
|
||
self.init( | ||
name: try row.get("name"), | ||
age: try row.get("age"), | ||
parentId: try row.get("parentId") | ||
) | ||
} | ||
|
||
public func makeRow() throws -> Row { | ||
|
||
var row = Row() | ||
|
||
try row.set(Child.idKey, self.id) | ||
try row.set("name", self.name) | ||
try row.set("age", self.age) | ||
try row.set("parentId", self.parentId) | ||
|
||
return row | ||
} | ||
} |
This file contains 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