Skip to content

Instantly share code, notes, and snippets.

@BrettRToomey
Last active December 31, 2016 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrettRToomey/772e8a3425125868605b52d3be2cfe3a to your computer and use it in GitHub Desktop.
Save BrettRToomey/772e8a3425125868605b52d3be2cfe3a to your computer and use it in GitHub Desktop.
A basic User model example.
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