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

Add a save method to the _Model protocol #19

Merged
merged 1 commit into from
Feb 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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