Last active
December 20, 2016 18:02
-
-
Save calebkleveter/d27c59f8de86aae9c971ad2403e23baa to your computer and use it in GitHub Desktop.
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 VaporPostgreSQL | |
import Fluent | |
final class User { | |
var id: Node? | |
var username: String | |
var password: String | |
init(username: String, password: String) { | |
self.id = nil | |
self.username = username | |
self.password = password | |
} | |
init(node: Node, in context: Context) throws { | |
id = try node.extract("id") | |
username = try node.extract("username") | |
password = try node.extract("password") | |
} | |
} | |
extension User: Model { | |
func makeNode(context: Context) throws -> Node { | |
return try Node(node: [ | |
"id": id, | |
"username": username, | |
"password": password | |
]) | |
} | |
} | |
extension User: Preparation { | |
static func prepare(_ database: Database) throws { | |
try database.create("users", closure: { (user) in | |
user.id() | |
user.string("username") | |
user.string("password") | |
}) | |
} | |
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