Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 4 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ let package = Package(
.library(name: "XCTFluent", targets: ["XCTFluent"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", from: "2.79.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.6.2"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.81.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.6.3"),
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.32.0"),
.package(url: "https://github.com/vapor/async-kit.git", from: "1.20.0"),
],
Expand All @@ -26,7 +26,9 @@ let package = Package(
name: "FluentKit",
dependencies: [
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOPosix", package: "swift-nio"),
.product(name: "Logging", package: "swift-log"),
.product(name: "AsyncKit", package: "async-kit"),
.product(name: "SQLKit", package: "sql-kit"),
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentKit/Database/Database.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension Database {
public func query<Model>(_ model: Model.Type) -> QueryBuilder<Model>
where Model: FluentKit.Model
{
return .init(database: self)
.init(database: self)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentKit/Database/DatabaseOutput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension DatabaseOutput {
}

public func cascading(to output: any DatabaseOutput) -> any DatabaseOutput {
return CombinedOutput(first: self, second: output)
CombinedOutput(first: self, second: output)
}
}

Expand Down
18 changes: 9 additions & 9 deletions Sources/FluentKit/Database/KeyPrefixingStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,37 @@ public enum KeyPrefixingStrategy: CustomStringConvertible, Sendable {
public var description: String {
switch self {
case .none:
return ".useDefaultKeys"
".useDefaultKeys"
case .camelCase:
return ".camelCase"
".camelCase"
case .snakeCase:
return ".snakeCase"
".snakeCase"
case .custom(_):
return ".custom(...)"
".custom(...)"
}
}

/// Apply this prefixing strategy and the given prefix to the given key, and return the result.
public func apply(prefix: FieldKey, to key: FieldKey) -> FieldKey {
switch self {
case .none:
return .prefix(prefix, key)
.prefix(prefix, key)

// This strategy converts `.id` and `.aggregate` keys (but not prefixes) into generic `.string()`s.
case .camelCase:
switch key {
case .id, .aggregate, .string(_):
return .prefix(prefix, .string(key.description.withUppercasedFirstCharacter()))
.prefix(prefix, .string(key.description.withUppercasedFirstCharacter()))

case .prefix(let originalPrefix, let originalSuffix):
return .prefix(self.apply(prefix: prefix, to: originalPrefix), originalSuffix)
.prefix(self.apply(prefix: prefix, to: originalPrefix), originalSuffix)
}

case .snakeCase:
return .prefix(.prefix(prefix, .string("_")), key)
.prefix(.prefix(prefix, .string("_")), key)

case .custom(let closure):
return closure(prefix, key)
closure(prefix, key)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentKit/Enum/EnumProperty.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public final class EnumProperty<Model, Value>
public let field: FieldProperty<Model, String>

public var projectedValue: EnumProperty<Model, Value> {
return self
self
}

public var wrappedValue: Value {
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentKit/Enum/OptionalEnumProperty.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public final class OptionalEnumProperty<Model, WrappedValue>
public let field: OptionalFieldProperty<Model, String>

public var projectedValue: OptionalEnumProperty<Model, WrappedValue> {
return self
self
}

public var wrappedValue: WrappedValue? {
Expand Down
20 changes: 10 additions & 10 deletions Sources/FluentKit/FluentError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@ public enum FluentError: Error, LocalizedError, CustomStringConvertible, CustomD
public var description: String {
switch self {
case .idRequired:
return "ID required"
"ID required"
case .missingField(let name):
return "field missing: \(name)"
"field missing: \(name)"
case .relationNotLoaded(let name):
return "relation not loaded: \(name)"
"relation not loaded: \(name)"
case .missingParent(let model, let parent, let key, let id):
return "parent missing: \(model).\(key): \(parent).\(id)"
"parent missing: \(model).\(key): \(parent).\(id)"
case .invalidField(let name, let valueType, let error):
return "invalid field: '\(name)', type: \(valueType), error: \(String(describing: error))"
"invalid field: '\(name)', type: \(valueType), error: \(String(describing: error))"
case .noResults:
return "Query returned no results"
"Query returned no results"
}
}

// `CustomDebugStringConvertible` conformance.
public var debugDescription: String {
switch self {
case .idRequired, .missingField(_), .relationNotLoaded(_), .missingParent(_, _, _, _), .noResults:
return self.description
self.description
case .invalidField(let name, let valueType, let error):
return "invalid field: '\(name)', type: \(valueType), error: \(String(reflecting: error))"
"invalid field: '\(name)', type: \(valueType), error: \(String(reflecting: error))"
}
}

Expand Down Expand Up @@ -119,9 +119,9 @@ public enum SiblingsPropertyError: Error, LocalizedError, CustomStringConvertibl
public var description: String {
switch self {
case .owningModelIdRequired(property: let property):
return "siblings relation \(property) is missing owning model's ID (owner likely unsaved)"
"siblings relation \(property) is missing owning model's ID (owner likely unsaved)"
case .operandModelIdRequired(property: let property):
return "operant model for siblings relation \(property) has no ID (attach/detach/etc. model likely unsaved)"
"operant model for siblings relation \(property) has no ID (attach/detach/etc. model likely unsaved)"
}
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/FluentKit/Migration/Migration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public protocol Migration: Sendable {

extension Migration {
public var name: String {
return defaultName
self.defaultName
}

internal var defaultName: String {
#if compiler(<6)
#if compiler(<6.1)
/// `String.init(reflecting:)` creates a `Mirror` unconditionally, but
/// when the parameter is a metatype (such as is the case here), that
/// mirror is never actually used for anything. Unfortunately, just
Expand Down
3 changes: 2 additions & 1 deletion Sources/FluentKit/Migration/Migrator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public struct Migrator: Sendable {

public func previewRevertBatch() -> EventLoopFuture<[(any Migration, DatabaseID?)]> {
self.migrators() { migrator in
return migrator.previewPrepareBatch().and(value: migrator.id)
// This is not correct, but can't be fixed as it would require changing this API's parameters.
migrator.previewPrepareBatch().and(value: migrator.id)
}.map {
$0.flatMap { migrations, id in migrations.map { ($0, id) } }
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentKit/Model/EagerLoad.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ extension EagerLoadable {
withDeleted: Bool,
to builder: Builder
) where Builder: EagerLoadBuilder, Builder.Model == From {
return Self.eagerLoad(relationKey, to: builder)
Self.eagerLoad(relationKey, to: builder)
}
}
3 changes: 1 addition & 2 deletions Sources/FluentKit/Model/Fields.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ extension Fields {
///
/// Returns a dictionary of field keys and associated values representing all "pending"
/// data - e.g. all fields (if any) which have been changed by something other than Fluent.
@_spi(FluentSQLSPI)
public/*package*/ func collectInput(withDefaultedValues defaultedValues: Bool = false) -> [FieldKey: DatabaseQuery.Value] {
package func collectInput(withDefaultedValues defaultedValues: Bool = false) -> [FieldKey: DatabaseQuery.Value] {
let input = DictionaryInput(wantsUnmodifiedKeys: defaultedValues)
self.input(to: input)
return input.storage
Expand Down
22 changes: 11 additions & 11 deletions Sources/FluentKit/Model/Model+CRUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import protocol SQLKit.SQLDatabase
extension Model {
public func save(on database: any Database) -> EventLoopFuture<Void> {
if self._$idExists {
return self.update(on: database)
self.update(on: database)
} else {
return self.create(on: database)
self.create(on: database)
}
}

Expand Down Expand Up @@ -47,7 +47,7 @@ extension Model {
}

public func update(on database: any Database) -> EventLoopFuture<Void> {
return database.configuration.middleware.chainingTo(Self.self) { event, model, db in
database.configuration.middleware.chainingTo(Self.self) { event, model, db in
try model.handle(event, on: db)
}.handle(.update, self, on: database)
}
Expand Down Expand Up @@ -97,7 +97,7 @@ extension Model {
}

public func restore(on database: any Database) -> EventLoopFuture<Void> {
return database.configuration.middleware.chainingTo(Self.self) { event, model, db in
database.configuration.middleware.chainingTo(Self.self) { event, model, db in
try model.handle(event, on: db)
}.handle(.restore, self, on: database)
}
Expand Down Expand Up @@ -125,15 +125,15 @@ extension Model {
private func handle(_ event: ModelEvent, on db: any Database) throws -> EventLoopFuture<Void> {
switch event {
case .create:
return _create(on: db)
_create(on: db)
case .delete(let force):
return try _delete(force: force, on: db)
try _delete(force: force, on: db)
case .restore:
return try _restore(on: db)
try _restore(on: db)
case .softDelete:
return try _delete(force: false, on: db)
try _delete(force: false, on: db)
case .update:
return try _update(on: db)
try _update(on: db)
}
}
}
Expand Down Expand Up @@ -207,7 +207,7 @@ private struct SavedInput: DatabaseOutput {
}

func schema(_ schema: String) -> any DatabaseOutput {
return self
self
}

func contains(_ key: FieldKey) -> Bool {
Expand Down Expand Up @@ -253,6 +253,6 @@ private struct SavedInput: DatabaseOutput {
}

var description: String {
return self.input.description
self.input.description
}
}
4 changes: 2 additions & 2 deletions Sources/FluentKit/Model/Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extension Schema {
self.alias ?? self.schema
}

static var spaceIfNotAliased: String? {
return self.alias == nil ? self.space : nil
public static var spaceIfNotAliased: String? {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intended?

Copy link
Member Author

@gwynne gwynne Mar 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It certainly is. But I completely forgot to mention it in the commit log or the PR description 😅

self.alias == nil ? self.space : nil
}
}
36 changes: 18 additions & 18 deletions Sources/FluentKit/Properties/BooleanPropertyFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public struct IntegerBooleanPropertyFormat<T: FixedWidthInteger & Codable & Send

public func parse(_ value: T) -> Bool? {
switch value {
case .zero: return false
case .zero.advanced(by: 1): return true
default: return nil
case .zero: false
case .zero.advanced(by: 1): true
default: nil
}
}

Expand All @@ -56,9 +56,9 @@ public struct OneZeroBooleanPropertyFormat: BooleanPropertyFormat {

public func parse(_ value: String) -> Bool? {
switch value {
case "0": return false
case "1": return true
default: return nil
case "0": false
case "1": true
default: nil
}
}

Expand All @@ -77,9 +77,9 @@ public struct YNBooleanPropertyFormat: BooleanPropertyFormat {

public func parse(_ value: String) -> Bool? {
switch value.lowercased() {
case "n": return false
case "y": return true
default: return nil
case "n": false
case "y": true
default: nil
}
}

Expand All @@ -99,9 +99,9 @@ public struct YesNoBooleanPropertyFormat: BooleanPropertyFormat {

public func parse(_ value: String) -> Bool? {
switch value.lowercased() {
case "no": return false
case "yes": return true
default: return nil
case "no": false
case "yes": true
default: nil
}
}

Expand All @@ -120,9 +120,9 @@ public struct OnOffBooleanPropertyFormat: BooleanPropertyFormat {

public func parse(_ value: String) -> Bool? {
switch value.lowercased() {
case "off": return false
case "on": return true
default: return nil
case "off": false
case "on": true
default: nil
}
}

Expand All @@ -141,9 +141,9 @@ public struct TrueFalseBooleanPropertyFormat: BooleanPropertyFormat {

public func parse(_ value: String) -> Bool? {
switch value.lowercased() {
case "false": return false
case "true": return true
default: return nil
case "false": false
case "true": true
default: nil
}
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/FluentKit/Properties/Field.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ extension FieldProperty: Property {
if let value = self.inputValue {
switch value {
case .bind(let bind):
return bind as? Value
bind as? Value
case .enumCase(let string):
return string as? Value
string as? Value
case .default:
fatalError("Cannot access default field for '\(Model.self).\(key)' before it is initialized or fetched")
default:
fatalError("Unexpected input value type for '\(Model.self).\(key)': \(value)")
}
} else if let value = self.outputValue {
return value
value
} else {
return nil
nil
}
}
set {
Expand Down
8 changes: 4 additions & 4 deletions Sources/FluentKit/Properties/FieldKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ extension FieldKey: CustomStringConvertible {
public var description: String {
switch self {
case .id:
return "id"
"id"
case .string(let name):
return name
name
case .aggregate:
return "aggregate"
"aggregate"
case .prefix(let prefix, let key):
return prefix.description + key.description
prefix.description + key.description
}
}
}
Expand Down
Loading
Loading