Created
December 10, 2016 13:14
-
-
Save kateinoigakukun/17453dc31dc829f4a8585ebe8266aba3 to your computer and use it in GitHub Desktop.
Fluent試してみたけどModelの記述量が多すぎる #CodePiece
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
import Foundation | |
import Fluent | |
final class User: Entity { | |
var id: Node? | |
var name: String | |
var exists: Bool = false | |
init(name: String) { | |
self.name = name | |
} | |
init(node: Node, in context: Context) throws { | |
id = try node.extract("id") | |
name = try node.extract("name") | |
} | |
func makeNode(context: Context) throws -> Node { | |
return try Node(node: [ | |
"id": id, | |
"name": name | |
]) | |
} | |
static func prepare(_ database: Database) throws { | |
try database.create("users") { users in | |
users.id() | |
users.string("name") | |
} | |
} | |
static func revert(_ database: Database) throws { | |
try database.delete("users") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment