From 508570b95f7650c4ba7510285c375fcdcc86a6ae Mon Sep 17 00:00:00 2001 From: Robbert Brandsma Date: Tue, 5 Feb 2019 15:19:31 +0100 Subject: [PATCH] Add a save method to the _Model protocol --- Sources/Meow/Model.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sources/Meow/Model.swift b/Sources/Meow/Model.swift index cf722d5..8b5f81d 100644 --- a/Sources/Meow/Model.swift +++ b/Sources/Meow/Model.swift @@ -3,6 +3,9 @@ import MongoKitten /// Private base protocol for `Model` without Self or associated type requirements public protocol _Model: class, Codable { + /// Saves the instance to the given context, calling `context.save(self)` + func save(to context: Context) -> EventLoopFuture + // MARK: - Serialization /// The collection name instances of the model live in. A default implementation is provided. @@ -26,6 +29,10 @@ public protocol Model: _Model { // MARK: - Default implementations public extension Model { + public func save(to context: Context) -> EventLoopFuture { + return context.save(self) + } + static var collectionName: String { return String(describing: Self.self) // Will be the name of the type }