Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,4 @@ jobs:
secrets: inherit
with:
with_android: true
with_linting: true
18 changes: 10 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ let package = Package(
]
)

var swiftSettings: [SwiftSetting] { [
.enableUpcomingFeature("ExistentialAny"),
// .enableUpcomingFeature("InternalImportsByDefault"),
.enableUpcomingFeature("MemberImportVisibility"),
.enableUpcomingFeature("InferIsolatedConformances"),
// .enableUpcomingFeature("NonisolatedNonsendingByDefault"),
.enableUpcomingFeature("ImmutableWeakCaptures"),
] }
var swiftSettings: [SwiftSetting] {
[
.enableUpcomingFeature("ExistentialAny"),
// .enableUpcomingFeature("InternalImportsByDefault"),
.enableUpcomingFeature("MemberImportVisibility"),
.enableUpcomingFeature("InferIsolatedConformances"),
// .enableUpcomingFeature("NonisolatedNonsendingByDefault"),
.enableUpcomingFeature("ImmutableWeakCaptures"),
]
}
20 changes: 10 additions & 10 deletions Sources/FluentBenchmark/FluentBenchmarker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public final class FluentBenchmarker {

public init(databases: Databases) {
precondition(databases.ids().count >= 2, "FluentBenchmarker Databases instance must have 2 or more registered databases")

self.databases = databases
self.database = self.databases.database(
logger: .init(label: "codes.vapor.fluent.benchmarker"),
Expand Down Expand Up @@ -54,17 +54,17 @@ public final class FluentBenchmarker {
// MARK: Utilities

func runTest(
_ name: String,
_ migrations: [any Migration],
_ test: () throws -> ()
_ name: String,
_ migrations: [any Migration],
_ test: () throws -> Void
) throws {
try self.runTest(name, migrations, { _ in try test() })
}

func runTest(
_ name: String,
_ migrations: [any Migration],
_ test: (any Database) throws -> ()
_ test: (any Database) throws -> Void
) throws {
// This re-initialization is required to make the middleware tests work thanks to ridiculous design flaws
self.database = self.databases.database(
Expand All @@ -73,12 +73,12 @@ public final class FluentBenchmarker {
)!
try self.runTest(name, migrations, on: self.database, test)
}

func runTest(
_ name: String,
_ migrations: [any Migration],
on database: any Database,
_ test: (any Database) throws -> ()
_ test: (any Database) throws -> Void
) throws {
database.logger.notice("Running \(name)...")

Expand All @@ -91,7 +91,7 @@ public final class FluentBenchmarker {
database.logger.error("\(name): Error: \(String(reflecting: error))")
throw error
}

let result = Result { try test(database) }

// Revert migrations
Expand All @@ -106,7 +106,7 @@ public final class FluentBenchmarker {
throw error
}
}

if case .failure(let error) = result {
database.logger.error("\(name): Error: \(String(reflecting: error))")
throw error
Expand Down
44 changes: 23 additions & 21 deletions Sources/FluentBenchmark/SolarSystem/GalacticJurisdiction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,53 @@ import NIOCore

public final class GalacticJurisdiction: Model, @unchecked Sendable {
public static let schema = "galaxy_jurisdictions"

public final class IDValue: Fields, Hashable, @unchecked Sendable {
@Parent(key: "galaxy_id")
public var galaxy: Galaxy

@Parent(key: "jurisdiction_id")
public var jurisdiction: Jurisdiction

@Field(key: "rank")
public var rank: Int

public init() {}

public convenience init(galaxy: Galaxy, jurisdiction: Jurisdiction, rank: Int) throws {
try self.init(galaxyId: galaxy.requireID(), jurisdictionId: jurisdiction.requireID(), rank: rank)
}

public init(galaxyId: Galaxy.IDValue, jurisdictionId: Jurisdiction.IDValue, rank: Int) {
self.$galaxy.id = galaxyId
self.$jurisdiction.id = jurisdictionId
self.rank = rank
}

public static func == (lhs: IDValue, rhs: IDValue) -> Bool {
lhs.$galaxy.id == rhs.$galaxy.id && lhs.$jurisdiction.id == rhs.$jurisdiction.id && lhs.rank == rhs.rank
}

public func hash(into hasher: inout Hasher) {
hasher.combine(self.$galaxy.id)
hasher.combine(self.$jurisdiction.id)
hasher.combine(self.rank)
}
}

@CompositeID()
public var id: IDValue?

public init() {}

public init(id: IDValue) {
self.id = id
}
}

public struct GalacticJurisdictionMigration: Migration {
public init() {}

public func prepare(on database: any Database) -> EventLoopFuture<Void> {
database.schema(GalacticJurisdiction.schema)
.field("galaxy_id", .uuid, .required, .references(Galaxy.schema, .id, onDelete: .cascade, onUpdate: .cascade))
Expand All @@ -59,7 +59,7 @@ public struct GalacticJurisdictionMigration: Migration {
.compositeIdentifier(over: "galaxy_id", "jurisdiction_id", "rank")
.create()
}

public func revert(on database: any Database) -> EventLoopFuture<Void> {
database.schema(GalacticJurisdiction.schema)
.delete()
Expand All @@ -68,11 +68,11 @@ public struct GalacticJurisdictionMigration: Migration {

public struct GalacticJurisdictionSeed: Migration {
public init() {}

public func prepare(on database: any Database) -> EventLoopFuture<Void> {
database.eventLoop.flatSubmit {
Galaxy.query(on: database).all().and(
Jurisdiction.query(on: database).all())
Jurisdiction.query(on: database).all())
}.flatMap { galaxies, jurisdictions in
[
("Milky Way", "Old", 0),
Expand All @@ -86,16 +86,18 @@ public struct GalacticJurisdictionSeed: Migration {
]
.reduce(database.eventLoop.makeSucceededVoidFuture()) { future, data in
future.flatMap {
GalacticJurisdiction.init(id: try! .init(
galaxy: galaxies.first(where: { $0.name == data.0 })!,
jurisdiction: jurisdictions.first(where: { $0.title == data.1 })!,
rank: data.2
)).create(on: database)
GalacticJurisdiction.init(
id: try! .init(
galaxy: galaxies.first(where: { $0.name == data.0 })!,
jurisdiction: jurisdictions.first(where: { $0.title == data.1 })!,
rank: data.2
)
).create(on: database)
}
}
}
}

public func revert(on database: any Database) -> EventLoopFuture<Void> {
GalacticJurisdiction.query(on: database).delete()
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/FluentBenchmark/SolarSystem/Galaxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import XCTest

public final class Galaxy: Model, @unchecked Sendable {
public static let schema = "galaxies"

@ID
public var id: UUID?

Expand All @@ -14,7 +14,7 @@ public final class Galaxy: Model, @unchecked Sendable {

@Children(for: \.$galaxy)
public var stars: [Star]

@Siblings(through: GalacticJurisdiction.self, from: \.$id.$galaxy, to: \.$id.$jurisdiction)
public var jurisdictions: [Jurisdiction]

Expand Down Expand Up @@ -49,7 +49,7 @@ public struct GalaxySeed: AsyncMigration {
"Andromeda",
"Milky Way",
"Pinwheel Galaxy",
"Messier 82"
"Messier 82",
]
.map { Galaxy(name: $0) }
.create(on: database)
Expand Down
29 changes: 15 additions & 14 deletions Sources/FluentBenchmark/SolarSystem/Governor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public final class Governor: Model, @unchecked Sendable {
@Parent(key: "planet_id")
public var planet: Planet

public init() { }
public init() {}

public init(id: IDValue? = nil, name: String) {
self.id = id
Expand Down Expand Up @@ -45,22 +45,23 @@ public struct GovernorMigration: Migration {
}

public struct GovernorSeed: Migration {
public init() { }
public init() {}

public func prepare(on database: any Database) -> EventLoopFuture<Void> {
Planet.query(on: database).all().flatMap { planets in
.andAllSucceed(planets.map { planet in
let governor: Governor?
switch planet.name {
case "Mars":
governor = .init(name: "John Doe")
case "Earth":
governor = .init(name: "Jane Doe")
default:
return database.eventLoop.makeSucceededVoidFuture()
}
return planet.$governor.create(governor!, on: database)
}, on: database.eventLoop)
.andAllSucceed(
planets.map { planet in
let governor: Governor?
switch planet.name {
case "Mars":
governor = .init(name: "John Doe")
case "Earth":
governor = .init(name: "Jane Doe")
default:
return database.eventLoop.makeSucceededVoidFuture()
}
return planet.$governor.create(governor!, on: database)
}, on: database.eventLoop)
}
}

Expand Down
18 changes: 9 additions & 9 deletions Sources/FluentBenchmark/SolarSystem/Jurisdiction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import XCTest

public final class Jurisdiction: Model, @unchecked Sendable {
public static let schema = "jurisdictions"

@ID(key: .id)
public var id: UUID?

@Field(key: "title")
public var title: String

@Siblings(through: GalacticJurisdiction.self, from: \.$id.$jurisdiction, to: \.$id.$galaxy)
public var galaxies: [Galaxy]

public init() {}

public init(id: IDValue? = nil, title: String) {
self.id = id
self.title = title
Expand All @@ -25,15 +25,15 @@ public final class Jurisdiction: Model, @unchecked Sendable {

public struct JurisdictionMigration: Migration {
public init() {}

public func prepare(on database: any Database) -> EventLoopFuture<Void> {
database.schema(Jurisdiction.schema)
.field(.id, .uuid, .identifier(auto: false), .required)
.field("title", .string, .required)
.unique(on: "title")
.create()
}

public func revert(on database: any Database) -> EventLoopFuture<Void> {
database.schema(Jurisdiction.schema)
.delete()
Expand All @@ -42,7 +42,7 @@ public struct JurisdictionMigration: Migration {

public struct JurisdictionSeed: Migration {
public init() {}

public func prepare(on database: any Database) -> EventLoopFuture<Void> {
[
"Old",
Expand All @@ -54,7 +54,7 @@ public struct JurisdictionSeed: Migration {
.map { Jurisdiction(title: $0) }
.create(on: database)
}

public func revert(on database: any Database) -> EventLoopFuture<Void> {
Jurisdiction.query(on: database)
.delete()
Expand Down
Loading
Loading