-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPost.swift
40 lines (32 loc) · 863 Bytes
/
Post.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import Vapor
import Fluent
final class Post: Model {
var id: Node? // required to conform Fluent protocol
var _id: Node? // required to store correct value in db
var text: String
// used by fluent internally
var exists: Bool = false
init(text: String) {
self.text = text
}
init(node: Node, in context: Context) throws {
id = try node.extract("id")
_id = try node.extract("_id")
text = try node.extract("text")
}
func makeNode(context: Context) throws -> Node {
return try Node(node: [
"_id": id, // we don't want to double values in response
"text": text
])
}
func merge(_ updates: Post) {
text = updates.text
}
static func prepare(_ database: Database) throws {
// implementation is not needed in case of mongodb
}
static func revert(_ database: Database) throws {
//
}
}