Last active
December 31, 2016 08:14
-
-
Save BrettRToomey/772e8a3425125868605b52d3be2cfe3a to your computer and use it in GitHub Desktop.
A basic User model example.
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
import Vapor | |
import Fluent | |
struct User: Model { | |
var id: Node? | |
var name: String | |
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(entity) { | |
$0.id() | |
$0.string("name") | |
} | |
} | |
static func revert(_ database: Database) throws { | |
try database.delete(entity) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment