Created
December 31, 2016 08:10
-
-
Save BrettRToomey/2e25a6cf77376955a4ef4761d2d5ddd3 to your computer and use it in GitHub Desktop.
An example of a custom save call for an automatic updated_at field.
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 | |
import Foundation | |
struct User: Model { | |
var updated_at: Int | |
//... | |
mutating func save() throws { | |
updated_at = Int(Date().timeIntervalSince1970) | |
try User.query().save(&self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment