|
|
@ -52,14 +52,16 @@ public extension QueryInterfaceRequest where RowDecoder: FetchableRecord & Table
|
|
|
|
@discardableResult
|
|
|
|
@discardableResult
|
|
|
|
func updateAllAndConfig(
|
|
|
|
func updateAllAndConfig(
|
|
|
|
_ db: Database,
|
|
|
|
_ db: Database,
|
|
|
|
|
|
|
|
calledFromConfig: Bool = false,
|
|
|
|
_ assignments: ConfigColumnAssignment...
|
|
|
|
_ assignments: ConfigColumnAssignment...
|
|
|
|
) throws -> Int {
|
|
|
|
) throws -> Int {
|
|
|
|
return try updateAllAndConfig(db, assignments)
|
|
|
|
return try updateAllAndConfig(db, calledFromConfig: calledFromConfig, assignments)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@discardableResult
|
|
|
|
@discardableResult
|
|
|
|
func updateAllAndConfig(
|
|
|
|
func updateAllAndConfig(
|
|
|
|
_ db: Database,
|
|
|
|
_ db: Database,
|
|
|
|
|
|
|
|
calledFromConfig: Bool = false,
|
|
|
|
_ assignments: [ConfigColumnAssignment]
|
|
|
|
_ assignments: [ConfigColumnAssignment]
|
|
|
|
) throws -> Int {
|
|
|
|
) throws -> Int {
|
|
|
|
let targetAssignments: [ColumnAssignment] = assignments.map { $0.assignment }
|
|
|
|
let targetAssignments: [ColumnAssignment] = assignments.map { $0.assignment }
|
|
|
@ -69,7 +71,7 @@ public extension QueryInterfaceRequest where RowDecoder: FetchableRecord & Table
|
|
|
|
return try self.updateAll(db, targetAssignments)
|
|
|
|
return try self.updateAll(db, targetAssignments)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return try self.updateAndFetchAllAndUpdateConfig(db, assignments).count
|
|
|
|
return try self.updateAndFetchAllAndUpdateConfig(db, calledFromConfig: calledFromConfig, assignments).count
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MARK: -- updateAndFetchAll
|
|
|
|
// MARK: -- updateAndFetchAll
|
|
|
@ -77,21 +79,26 @@ public extension QueryInterfaceRequest where RowDecoder: FetchableRecord & Table
|
|
|
|
@discardableResult
|
|
|
|
@discardableResult
|
|
|
|
func updateAndFetchAllAndUpdateConfig(
|
|
|
|
func updateAndFetchAllAndUpdateConfig(
|
|
|
|
_ db: Database,
|
|
|
|
_ db: Database,
|
|
|
|
|
|
|
|
calledFromConfig: Bool = false,
|
|
|
|
_ assignments: ConfigColumnAssignment...
|
|
|
|
_ assignments: ConfigColumnAssignment...
|
|
|
|
) throws -> [RowDecoder] {
|
|
|
|
) throws -> [RowDecoder] {
|
|
|
|
return try updateAndFetchAllAndUpdateConfig(db, assignments)
|
|
|
|
return try updateAndFetchAllAndUpdateConfig(db, calledFromConfig: calledFromConfig, assignments)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@discardableResult
|
|
|
|
@discardableResult
|
|
|
|
func updateAndFetchAllAndUpdateConfig(
|
|
|
|
func updateAndFetchAllAndUpdateConfig(
|
|
|
|
_ db: Database,
|
|
|
|
_ db: Database,
|
|
|
|
|
|
|
|
calledFromConfig: Bool = false,
|
|
|
|
_ assignments: [ConfigColumnAssignment]
|
|
|
|
_ assignments: [ConfigColumnAssignment]
|
|
|
|
) throws -> [RowDecoder] {
|
|
|
|
) throws -> [RowDecoder] {
|
|
|
|
// First perform the actual updates
|
|
|
|
// First perform the actual updates
|
|
|
|
let updatedData: [RowDecoder] = try self.updateAndFetchAll(db, assignments.map { $0.assignment })
|
|
|
|
let updatedData: [RowDecoder] = try self.updateAndFetchAll(db, assignments.map { $0.assignment })
|
|
|
|
|
|
|
|
|
|
|
|
// Then check if any of the changes could affect the config
|
|
|
|
// Then check if any of the changes could affect the config
|
|
|
|
guard SessionUtil.assignmentsRequireConfigUpdate(assignments) else { return updatedData }
|
|
|
|
guard
|
|
|
|
|
|
|
|
!calledFromConfig &&
|
|
|
|
|
|
|
|
SessionUtil.assignmentsRequireConfigUpdate(assignments)
|
|
|
|
|
|
|
|
else { return updatedData }
|
|
|
|
|
|
|
|
|
|
|
|
defer {
|
|
|
|
defer {
|
|
|
|
// If we changed a column that requires a config update then we may as well automatically
|
|
|
|
// If we changed a column that requires a config update then we may as well automatically
|
|
|
|