Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

Commit

Permalink
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Sources/Sugar/Helpers/Model.swift
Original file line number Diff line number Diff line change
@@ -11,13 +11,13 @@ public extension Model {
.unwrap(or: Abort(.notFound, reason: "\(Self.self) with id \(id) not found"))
}

public func saveOrUpdate<T>(
given values: [KeyPath<Self, T>: T],
public func saveOrUpdate (
given filters: [Self.Database.QueryFilter],
on db: DatabaseConnectable
) throws -> Future<Self> where T: Encodable {
) throws -> Future<Self> {
var query = Self.query(on: db)
for (field, value) in values {
query = query.filter(field == value)
for filter in filters {
query = query.filter(filter)
}

return query.first().flatMap(to: Self.self) { result in

0 comments on commit 74356ac

Please sign in to comment.