Skip to content

Instantly share code, notes, and snippets.

@BrettRToomey
Created December 31, 2016 08:10
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/2e25a6cf77376955a4ef4761d2d5ddd3 to your computer and use it in GitHub Desktop.
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.
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