Skip to content
This repository has been archived by the owner on Jan 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #19 from OpenKitten/feature/save-on-model
Browse files Browse the repository at this point in the history
Add a save method to the _Model protocol
  • Loading branch information
Obbut authored Feb 6, 2019
2 parents 4dbb90d + 508570b commit 6e9dc27
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Sources/Meow/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void>

// MARK: - Serialization

/// The collection name instances of the model live in. A default implementation is provided.
Expand All @@ -26,6 +29,10 @@ public protocol Model: _Model {

// MARK: - Default implementations
public extension Model {
public func save(to context: Context) -> EventLoopFuture<Void> {
return context.save(self)
}

static var collectionName: String {
return String(describing: Self.self) // Will be the name of the type
}
Expand Down

0 comments on commit 6e9dc27

Please sign in to comment.