From a6c86ea7f7be760cc5c324159da4711a43c255f3 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Mon, 15 Apr 2024 04:45:51 -0500 Subject: [PATCH 1/6] Fix up FluentKit tests after SQLKit update --- .../AsyncTests/AsyncFluentKitTests.swift | 28 ++++++++-------- Tests/FluentKitTests/CompositeIDTests.swift | 2 +- Tests/FluentKitTests/FluentKitTests.swift | 32 +++++++++---------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Tests/FluentKitTests/AsyncTests/AsyncFluentKitTests.swift b/Tests/FluentKitTests/AsyncTests/AsyncFluentKitTests.swift index 5214134e..ab1683b4 100644 --- a/Tests/FluentKitTests/AsyncTests/AsyncFluentKitTests.swift +++ b/Tests/FluentKitTests/AsyncTests/AsyncFluentKitTests.swift @@ -119,12 +119,12 @@ final class AsyncFluentKitTests: XCTestCase { _ = try await Planet.query(on: db).unique().count(\.$name) XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"SELECT COUNT(DISTINCT("planets"."name")) AS "aggregate" FROM "planets" WHERE ("planets"."deleted_at" IS NULL OR "planets"."deleted_at" > $1)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"SELECT COUNT(DISTINCT "planets"."name") AS "aggregate" FROM "planets" WHERE ("planets"."deleted_at" IS NULL OR "planets"."deleted_at" > $1)"#) db.reset() _ = try await Planet.query(on: db).unique().sum(\.$id) XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"SELECT SUM(DISTINCT("planets"."id")) AS "aggregate" FROM "planets" WHERE ("planets"."deleted_at" IS NULL OR "planets"."deleted_at" > $1)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"SELECT SUM(DISTINCT "planets"."id") AS "aggregate" FROM "planets" WHERE ("planets"."deleted_at" IS NULL OR "planets"."deleted_at" > $1)"#) db.reset() } @@ -141,7 +141,7 @@ final class AsyncFluentKitTests: XCTestCase { .create() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("id" BIGINT NOT NULL)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("id" BIGINT NOT NULL)"#) } func testIdentifierFieldConstraint() async throws { @@ -151,7 +151,7 @@ final class AsyncFluentKitTests: XCTestCase { .create() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("id" BIGINT PRIMARY KEY)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("id" BIGINT PRIMARY KEY)"#) db.reset() try await db.schema("planets") @@ -159,7 +159,7 @@ final class AsyncFluentKitTests: XCTestCase { .create() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("id" BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("id" BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY)"#) } func testForeignKeyFieldConstraint() async throws { @@ -169,7 +169,7 @@ final class AsyncFluentKitTests: XCTestCase { .create() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("galaxy_id" BIGINT REFERENCES "galaxies" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("galaxy_id" BIGINT REFERENCES "galaxies" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)"#) db.reset() try await db.schema("planets") @@ -177,7 +177,7 @@ final class AsyncFluentKitTests: XCTestCase { .create() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("galaxy_id" BIGINT REFERENCES "galaxies" ("id") ON DELETE RESTRICT ON UPDATE CASCADE)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("galaxy_id" BIGINT REFERENCES "galaxies" ("id") ON DELETE RESTRICT ON UPDATE CASCADE)"#) } func testMultipleFieldConstraint() async throws { @@ -187,7 +187,7 @@ final class AsyncFluentKitTests: XCTestCase { .create() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("id" BIGINT NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("id" BIGINT NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY)"#) } func testUniqueTableConstraint() async throws { @@ -198,7 +198,7 @@ final class AsyncFluentKitTests: XCTestCase { .create() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("id" BIGINT, CONSTRAINT "uq:planets.id" UNIQUE ("id"))"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("id" BIGINT, CONSTRAINT "uq:planets.id" UNIQUE ("id"))"#) db.reset() try await db.schema("planets") @@ -208,7 +208,7 @@ final class AsyncFluentKitTests: XCTestCase { .create() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("id" BIGINT, "name" TEXT, CONSTRAINT "uq:planets.id+planets.name" UNIQUE ("id", "name"))"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("id" BIGINT, "name" TEXT, CONSTRAINT "uq:planets.id+planets.name" UNIQUE ("id", "name"))"#) } func testForeignKeyTableConstraint() async throws { @@ -219,7 +219,7 @@ final class AsyncFluentKitTests: XCTestCase { .create() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("galaxy_id" BIGINT, CONSTRAINT "fk:planets.galaxy_id+planets.id" FOREIGN KEY ("galaxy_id") REFERENCES "galaxies" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("galaxy_id" BIGINT, CONSTRAINT "fk:planets.galaxy_id+planets.id" FOREIGN KEY ("galaxy_id") REFERENCES "galaxies" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)"#) db.reset() try await db.schema("planets") @@ -233,7 +233,7 @@ final class AsyncFluentKitTests: XCTestCase { .create() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("galaxy_id" BIGINT, CONSTRAINT "fk:planets.galaxy_id+planets.id" FOREIGN KEY ("galaxy_id") REFERENCES "galaxies" ("id") ON DELETE RESTRICT ON UPDATE CASCADE)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("galaxy_id" BIGINT, CONSTRAINT "fk:planets.galaxy_id+planets.id" FOREIGN KEY ("galaxy_id") REFERENCES "galaxies" ("id") ON DELETE RESTRICT ON UPDATE CASCADE)"#) } func testIfNotExistsTableCreate() async throws { @@ -245,7 +245,7 @@ final class AsyncFluentKitTests: XCTestCase { XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE IF NOT EXISTS "planets"("galaxy_id" BIGINT)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE IF NOT EXISTS "planets" ("galaxy_id" BIGINT)"#) db.reset() try await db.schema("planets") @@ -254,7 +254,7 @@ final class AsyncFluentKitTests: XCTestCase { XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("galaxy_id" BIGINT)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("galaxy_id" BIGINT)"#) } func testCreateEmptyModelArrayDoesntQuery() async throws { diff --git a/Tests/FluentKitTests/CompositeIDTests.swift b/Tests/FluentKitTests/CompositeIDTests.swift index 53a0aa05..91955d92 100644 --- a/Tests/FluentKitTests/CompositeIDTests.swift +++ b/Tests/FluentKitTests/CompositeIDTests.swift @@ -83,7 +83,7 @@ final class CompositeIDTests: XCTestCase { let db = DummyDatabaseForTestSQLSerializer() try CompositePlanetTagMigration().prepare(on: db).wait() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "composite+planet+tag"("planet_id" UUID NOT NULL REFERENCES "planets" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, "tag_id" UUID NOT NULL REFERENCES "tags" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, "notation" TEXT NOT NULL, "createdAt" TIMESTAMPTZ, "updatedAt" TIMESTAMPTZ, "deletedAt" TIMESTAMPTZ, PRIMARY KEY ("planet_id", "tag_id"))"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "composite+planet+tag" ("planet_id" UUID NOT NULL REFERENCES "planets" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, "tag_id" UUID NOT NULL REFERENCES "tags" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, "notation" TEXT NOT NULL, "createdAt" TIMESTAMPTZ, "updatedAt" TIMESTAMPTZ, "deletedAt" TIMESTAMPTZ, PRIMARY KEY ("planet_id", "tag_id"))"#) } func testCompositeIDRelations() throws { diff --git a/Tests/FluentKitTests/FluentKitTests.swift b/Tests/FluentKitTests/FluentKitTests.swift index 0e540109..1fc25e3d 100644 --- a/Tests/FluentKitTests/FluentKitTests.swift +++ b/Tests/FluentKitTests/FluentKitTests.swift @@ -176,12 +176,12 @@ final class FluentKitTests: XCTestCase { _ = try? Planet.query(on: db).unique().count(\.$name).wait() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"SELECT COUNT(DISTINCT("planets"."name")) AS "aggregate" FROM "planets" WHERE ("planets"."deleted_at" IS NULL OR "planets"."deleted_at" > $1)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"SELECT COUNT(DISTINCT "planets"."name") AS "aggregate" FROM "planets" WHERE ("planets"."deleted_at" IS NULL OR "planets"."deleted_at" > $1)"#) db.reset() _ = try? Planet.query(on: db).unique().sum(\.$id).wait() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"SELECT SUM(DISTINCT("planets"."id")) AS "aggregate" FROM "planets" WHERE ("planets"."deleted_at" IS NULL OR "planets"."deleted_at" > $1)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"SELECT SUM(DISTINCT "planets"."id") AS "aggregate" FROM "planets" WHERE ("planets"."deleted_at" IS NULL OR "planets"."deleted_at" > $1)"#) db.reset() } @@ -198,7 +198,7 @@ final class FluentKitTests: XCTestCase { .create() .wait() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("id" BIGINT NOT NULL)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("id" BIGINT NOT NULL)"#) } func testIdentifierFieldConstraint() throws { @@ -208,7 +208,7 @@ final class FluentKitTests: XCTestCase { .create() .wait() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("id" BIGINT PRIMARY KEY)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("id" BIGINT PRIMARY KEY)"#) db.reset() try db.schema("planets") @@ -216,7 +216,7 @@ final class FluentKitTests: XCTestCase { .create() .wait() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("id" BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("id" BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY)"#) } func testForeignKeyFieldConstraint() throws { @@ -226,7 +226,7 @@ final class FluentKitTests: XCTestCase { .create() .wait() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("galaxy_id" BIGINT REFERENCES "galaxies" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("galaxy_id" BIGINT REFERENCES "galaxies" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)"#) db.reset() try db.schema("planets") @@ -234,7 +234,7 @@ final class FluentKitTests: XCTestCase { .create() .wait() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("galaxy_id" BIGINT REFERENCES "galaxies" ("id") ON DELETE RESTRICT ON UPDATE CASCADE)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("galaxy_id" BIGINT REFERENCES "galaxies" ("id") ON DELETE RESTRICT ON UPDATE CASCADE)"#) } func testMultipleFieldConstraint() throws { @@ -244,7 +244,7 @@ final class FluentKitTests: XCTestCase { .create() .wait() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("id" BIGINT NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("id" BIGINT NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY)"#) } func testUniqueTableConstraint() throws { @@ -255,7 +255,7 @@ final class FluentKitTests: XCTestCase { .create() .wait() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("id" BIGINT, CONSTRAINT "uq:planets.id" UNIQUE ("id"))"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("id" BIGINT, CONSTRAINT "uq:planets.id" UNIQUE ("id"))"#) db.reset() try db.schema("planets") @@ -265,7 +265,7 @@ final class FluentKitTests: XCTestCase { .create() .wait() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("id" BIGINT, "name" TEXT, CONSTRAINT "uq:planets.id+planets.name" UNIQUE ("id", "name"))"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("id" BIGINT, "name" TEXT, CONSTRAINT "uq:planets.id+planets.name" UNIQUE ("id", "name"))"#) } func testForeignKeyTableConstraint() throws { @@ -276,7 +276,7 @@ final class FluentKitTests: XCTestCase { .create() .wait() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("galaxy_id" BIGINT, CONSTRAINT "fk:planets.galaxy_id+planets.id" FOREIGN KEY ("galaxy_id") REFERENCES "galaxies" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("galaxy_id" BIGINT, CONSTRAINT "fk:planets.galaxy_id+planets.id" FOREIGN KEY ("galaxy_id") REFERENCES "galaxies" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)"#) db.reset() try db.schema("planets") @@ -290,7 +290,7 @@ final class FluentKitTests: XCTestCase { .create() .wait() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("galaxy_id" BIGINT, CONSTRAINT "fk:planets.galaxy_id+planets.id" FOREIGN KEY ("galaxy_id") REFERENCES "galaxies" ("id") ON DELETE RESTRICT ON UPDATE CASCADE)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("galaxy_id" BIGINT, CONSTRAINT "fk:planets.galaxy_id+planets.id" FOREIGN KEY ("galaxy_id") REFERENCES "galaxies" ("id") ON DELETE RESTRICT ON UPDATE CASCADE)"#) db.reset() try db.schema("planets") @@ -304,7 +304,7 @@ final class FluentKitTests: XCTestCase { .create() .wait() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("galaxy_id" BIGINT, "galaxy_name" TEXT, CONSTRAINT "fk:planets.galaxy_id+planets.galaxy_name+planets.id+planets.name" FOREIGN KEY ("galaxy_id", "galaxy_name") REFERENCES "galaxies" ("id", "name") ON DELETE NO ACTION ON UPDATE CASCADE)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("galaxy_id" BIGINT, "galaxy_name" TEXT, CONSTRAINT "fk:planets.galaxy_id+planets.galaxy_name+planets.id+planets.name" FOREIGN KEY ("galaxy_id", "galaxy_name") REFERENCES "galaxies" ("id", "name") ON DELETE NO ACTION ON UPDATE CASCADE)"#) } func testIfNotExistsTableCreate() throws { @@ -316,7 +316,7 @@ final class FluentKitTests: XCTestCase { .wait() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE IF NOT EXISTS "planets"("galaxy_id" BIGINT)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE IF NOT EXISTS "planets" ("galaxy_id" BIGINT)"#) db.reset() try db.schema("planets") @@ -325,7 +325,7 @@ final class FluentKitTests: XCTestCase { .wait() XCTAssertEqual(db.sqlSerializers.count, 1) - XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets"("galaxy_id" BIGINT)"#) + XCTAssertEqual(db.sqlSerializers.first?.sql, #"CREATE TABLE "planets" ("galaxy_id" BIGINT)"#) } func testDecodeWithoutID() throws { @@ -734,7 +734,7 @@ final class FluentKitTests: XCTestCase { _ = try Star.query(on: db).join(AltPlanet.self, on: \AltPlanet.$star.$id == \Star.$id).fields(for: Star.self).withDeleted().first().wait() XCTAssertEqual(db.sqlSerializers.count, 6) - XCTAssertEqual(db.sqlSerializers.dropFirst(0).first?.sql, #"CREATE TABLE "mirror_universe"."planets"("id" UUID PRIMARY KEY, "name" TEXT NOT NULL, "star_id" UUID REFERENCES "stars" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION NOT NULL, "possible_star_id" UUID REFERENCES "stars" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, "createdAt" TIMESTAMPTZ, "updatedAt" TIMESTAMPTZ, "deletedAt" TIMESTAMPTZ DEFAULT NULL)"#) + XCTAssertEqual(db.sqlSerializers.dropFirst(0).first?.sql, #"CREATE TABLE "mirror_universe"."planets" ("id" UUID PRIMARY KEY, "name" TEXT NOT NULL, "star_id" UUID REFERENCES "stars" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION NOT NULL, "possible_star_id" UUID REFERENCES "stars" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, "createdAt" TIMESTAMPTZ, "updatedAt" TIMESTAMPTZ, "deletedAt" TIMESTAMPTZ DEFAULT NULL)"#) XCTAssertEqual(db.sqlSerializers.dropFirst(1).first?.sql, #"SELECT "mirror_universe"."planets"."id" AS "mirror_universe_planets_id", "mirror_universe"."planets"."name" AS "mirror_universe_planets_name", "mirror_universe"."planets"."star_id" AS "mirror_universe_planets_star_id", "mirror_universe"."planets"."possible_star_id" AS "mirror_universe_planets_possible_star_id", "mirror_universe"."planets"."createdAt" AS "mirror_universe_planets_createdAt", "mirror_universe"."planets"."updatedAt" AS "mirror_universe_planets_updatedAt", "mirror_universe"."planets"."deletedAt" AS "mirror_universe_planets_deletedAt" FROM "mirror_universe"."planets" WHERE "mirror_universe"."planets"."name" = $1 AND ("mirror_universe"."planets"."deletedAt" IS NULL OR "mirror_universe"."planets"."deletedAt" > $2)"#) XCTAssertEqual(db.sqlSerializers.dropFirst(2).first?.sql, #"INSERT INTO "mirror_universe"."planets" ("id", "name", "star_id", "possible_star_id", "createdAt", "updatedAt", "deletedAt") VALUES ($1, $2, DEFAULT, DEFAULT, $3, $4, DEFAULT)"#) XCTAssertEqual(db.sqlSerializers.dropFirst(3).first?.sql, #"UPDATE "mirror_universe"."planets" SET "id" = $1, "name" = $2, "updatedAt" = $3 WHERE "mirror_universe"."planets"."id" = $4 AND ("mirror_universe"."planets"."deletedAt" IS NULL OR "mirror_universe"."planets"."deletedAt" > $5)"#) From 9bd0804a331c18044ceb8ea0cea6a7ce16f26bde Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Mon, 15 Apr 2024 04:51:58 -0500 Subject: [PATCH 2/6] Attempt to fix weird package name issues --- Package.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Package.swift b/Package.swift index a3958412..6daed046 100644 --- a/Package.swift +++ b/Package.swift @@ -23,6 +23,7 @@ let package = Package( ], targets: [ .target(name: "FluentKit", dependencies: [ + .product(name: "NIO", package: "swift-nio"), .product(name: "NIOCore", package: "swift-nio"), .product(name: "Logging", package: "swift-log"), .product(name: "AsyncKit", package: "async-kit"), From ccc44a47fa7d6e4cb1576a4442b8f6ef3fa90a0e Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Mon, 15 Apr 2024 04:58:34 -0500 Subject: [PATCH 3/6] Bump minimum Swift version --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 6daed046..3501cfa2 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.6 +// swift-tools-version:5.7 import PackageDescription let package = Package( From 81ea23dbd086b227b34a1ad3edfc5fecb75c6163 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Mon, 15 Apr 2024 05:01:15 -0500 Subject: [PATCH 4/6] Make FluentKit compliant with ExistentialAny --- .../FluentBenchmark/FluentBenchmarker.swift | 6 +- .../SolarSystem/GalacticJurisdiction.swift | 8 +-- .../FluentBenchmark/SolarSystem/Galaxy.swift | 8 +-- .../SolarSystem/Governor.swift | 8 +-- .../SolarSystem/Jurisdiction.swift | 8 +-- .../FluentBenchmark/SolarSystem/Moon.swift | 8 +-- .../FluentBenchmark/SolarSystem/Planet.swift | 8 +-- .../SolarSystem/PlanetTag.swift | 8 +-- .../SolarSystem/SolarSystem.swift | 12 ++-- .../FluentBenchmark/SolarSystem/Star.swift | 8 +-- Sources/FluentBenchmark/SolarSystem/Tag.swift | 8 +-- .../FluentBenchmark/Tests/ArrayTests.swift | 12 ++-- .../FluentBenchmark/Tests/ChildTests.swift | 24 +++---- .../FluentBenchmark/Tests/ChildrenTests.swift | 12 ++-- .../FluentBenchmark/Tests/ChunkTests.swift | 4 +- .../Tests/CompositeIDTests.swift | 10 +-- .../Tests/CompositeRelationTests.swift | 26 ++++---- .../Tests/EagerLoadTests.swift | 4 +- Sources/FluentBenchmark/Tests/EnumTests.swift | 16 ++--- .../FluentBenchmark/Tests/FilterTests.swift | 12 ++-- .../FluentBenchmark/Tests/GroupTests.swift | 8 +-- Sources/FluentBenchmark/Tests/IDTests.swift | 16 ++--- Sources/FluentBenchmark/Tests/JoinTests.swift | 32 +++++----- .../Tests/MiddlewareTests.swift | 26 ++++---- .../FluentBenchmark/Tests/MigratorTests.swift | 4 +- .../FluentBenchmark/Tests/ModelTests.swift | 28 ++++---- .../Tests/OptionalParentTests.swift | 8 +-- .../FluentBenchmark/Tests/ParentTests.swift | 2 +- .../Tests/PerformanceTests+Siblings.swift | 20 +++--- .../Tests/PerformanceTests.swift | 4 +- Sources/FluentBenchmark/Tests/SQLTests.swift | 8 +-- .../FluentBenchmark/Tests/SchemaTests.swift | 32 +++++----- Sources/FluentBenchmark/Tests/SetTests.swift | 8 +-- .../Tests/SoftDeleteTests.swift | 12 ++-- .../Tests/TimestampTests.swift | 8 +-- .../FluentBenchmark/Tests/UniqueTests.swift | 12 ++-- .../Concurrency/AsyncMigration.swift | 8 +-- .../Concurrency/AsyncModelMiddleware.swift | 27 ++++---- .../Concurrency/Children+Concurrency.swift | 8 +-- .../Concurrency/Database+Concurrency.swift | 4 +- .../Concurrency/Model+Concurrency.swift | 16 ++--- .../ModelResponder+Concurrency.swift | 22 +++---- .../OptionalChild+Concurrency.swift | 6 +- .../OptionalParent+Concurrency.swift | 4 +- .../Concurrency/Parent+Concurrency.swift | 4 +- .../QueryBuilder+Concurrency.swift | 6 +- .../Concurrency/Relation+Concurrency.swift | 2 +- .../FluentKit/Database/Database+Logging.swift | 10 +-- Sources/FluentKit/Database/Database.swift | 24 +++---- .../FluentKit/Database/DatabaseInput.swift | 6 +- .../FluentKit/Database/DatabaseOutput.swift | 18 +++--- Sources/FluentKit/Database/Databases.swift | 26 ++++---- Sources/FluentKit/Enum/EnumBuilder.swift | 4 +- Sources/FluentKit/Enum/EnumMetadata.swift | 6 +- Sources/FluentKit/Enum/EnumProperty.swift | 10 +-- .../FluentKit/Enum/OptionalEnumProperty.swift | 10 +-- Sources/FluentKit/FluentError.swift | 2 +- .../Middleware/ModelMiddleware.swift | 42 ++++++------ .../FluentKit/Middleware/ModelResponder.swift | 20 +++--- Sources/FluentKit/Migration/Migration.swift | 4 +- .../FluentKit/Migration/MigrationLog.swift | 6 +- Sources/FluentKit/Migration/Migrations.swift | 8 +-- Sources/FluentKit/Migration/Migrator.swift | 42 ++++++------ Sources/FluentKit/Model/AnyModel.swift | 4 +- Sources/FluentKit/Model/EagerLoad.swift | 6 +- Sources/FluentKit/Model/Fields+Codable.swift | 4 +- Sources/FluentKit/Model/Fields.swift | 22 +++---- Sources/FluentKit/Model/Model+CRUD.swift | 40 ++++++------ Sources/FluentKit/Model/Model.swift | 4 +- Sources/FluentKit/Model/ModelAlias.swift | 4 +- Sources/FluentKit/Properties/Boolean.swift | 10 +-- Sources/FluentKit/Properties/Children.swift | 20 +++--- .../Properties/CompositeChildren.swift | 16 ++--- .../FluentKit/Properties/CompositeID.swift | 10 +-- .../Properties/CompositeOptionalChild.swift | 16 ++--- .../Properties/CompositeOptionalParent.swift | 16 ++--- .../Properties/CompositeParent.swift | 16 ++--- Sources/FluentKit/Properties/Field.swift | 12 ++-- Sources/FluentKit/Properties/Group.swift | 10 +-- Sources/FluentKit/Properties/ID.swift | 20 +++--- .../Properties/OptionalBoolean.swift | 10 +-- .../FluentKit/Properties/OptionalChild.swift | 18 +++--- .../FluentKit/Properties/OptionalField.swift | 10 +-- .../FluentKit/Properties/OptionalParent.swift | 20 +++--- Sources/FluentKit/Properties/Parent.swift | 20 +++--- Sources/FluentKit/Properties/Property.swift | 10 +-- Sources/FluentKit/Properties/Relation.swift | 4 +- Sources/FluentKit/Properties/Siblings.swift | 34 +++++----- Sources/FluentKit/Properties/Timestamp.swift | 16 ++--- .../Builder/QueryBuilder+Aggregate.swift | 4 +- .../Query/Builder/QueryBuilder+Filter.swift | 6 +- .../Query/Builder/QueryBuilder+Paginate.swift | 2 +- .../Query/Builder/QueryBuilder.swift | 28 ++++---- .../Query/Database/DatabaseQuery+Value.swift | 4 +- Sources/FluentKit/Schema/SchemaBuilder.swift | 4 +- Sources/FluentSQL/DatabaseQuery+SQL.swift | 26 ++++---- Sources/FluentSQL/DatabaseSchema+SQL.swift | 22 +++---- Sources/FluentSQL/SQLDatabase+Model.swift | 4 +- Sources/FluentSQL/SQLList+Deprecated.swift | 4 +- Sources/FluentSQL/SQLQualifiedTable.swift | 6 +- Sources/FluentSQL/SQLQueryConverter.swift | 64 +++++++++---------- Sources/FluentSQL/SQLSchemaConverter.swift | 44 ++++++------- Sources/FluentSQL/Utilities.swift | 6 +- Sources/XCTFluent/DummyDatabase.swift | 46 ++++++------- Sources/XCTFluent/TestDatabase.swift | 42 ++++++------ Tests/FluentKitTests/CompositeIDTests.swift | 8 +-- .../DummyDatabaseForTestSQLSerializer.swift | 32 +++++----- Tests/FluentKitTests/FluentKitTests.swift | 2 +- 108 files changed, 757 insertions(+), 752 deletions(-) diff --git a/Sources/FluentBenchmark/FluentBenchmarker.swift b/Sources/FluentBenchmark/FluentBenchmarker.swift index 603995c7..50b0b275 100644 --- a/Sources/FluentBenchmark/FluentBenchmarker.swift +++ b/Sources/FluentBenchmark/FluentBenchmarker.swift @@ -54,7 +54,7 @@ public final class FluentBenchmarker { internal func runTest( _ name: String, - _ migrations: [Migration], + _ migrations: [any Migration], _ test: () throws -> () ) throws { try self.runTest(name, migrations, { _ in try test() }) @@ -62,7 +62,7 @@ public final class FluentBenchmarker { internal func runTest( _ name: String, - _ migrations: [Migration], + _ migrations: [any Migration], _ test: (any Database) throws -> () ) throws { // This re-initialization is required to make the middleware tests work thanks to ridiculous design flaws @@ -75,7 +75,7 @@ public final class FluentBenchmarker { internal func runTest( _ name: String, - _ migrations: [Migration], + _ migrations: [any Migration], on database: any Database, _ test: (any Database) throws -> () ) throws { diff --git a/Sources/FluentBenchmark/SolarSystem/GalacticJurisdiction.swift b/Sources/FluentBenchmark/SolarSystem/GalacticJurisdiction.swift index 3665a669..d172cf8b 100644 --- a/Sources/FluentBenchmark/SolarSystem/GalacticJurisdiction.swift +++ b/Sources/FluentBenchmark/SolarSystem/GalacticJurisdiction.swift @@ -51,7 +51,7 @@ public final class GalacticJurisdiction: Model { public struct GalacticJurisdictionMigration: Migration { public init() {} - public func prepare(on database: Database) -> EventLoopFuture { + public func prepare(on database: any Database) -> EventLoopFuture { database.schema(GalacticJurisdiction.schema) .field("galaxy_id", .uuid, .required, .references(Galaxy.schema, .id, onDelete: .cascade, onUpdate: .cascade)) .field("jurisdiction_id", .uuid, .required, .references(Jurisdiction.schema, .id, onDelete: .cascade, onUpdate: .cascade)) @@ -60,7 +60,7 @@ public struct GalacticJurisdictionMigration: Migration { .create() } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { database.schema(GalacticJurisdiction.schema) .delete() } @@ -69,7 +69,7 @@ public struct GalacticJurisdictionMigration: Migration { public struct GalacticJurisdictionSeed: Migration { public init() {} - public func prepare(on database: Database) -> EventLoopFuture { + public func prepare(on database: any Database) -> EventLoopFuture { database.eventLoop.flatSubmit { Galaxy.query(on: database).all().and( Jurisdiction.query(on: database).all()) @@ -94,7 +94,7 @@ public struct GalacticJurisdictionSeed: Migration { } } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { GalacticJurisdiction.query(on: database).delete() } } diff --git a/Sources/FluentBenchmark/SolarSystem/Galaxy.swift b/Sources/FluentBenchmark/SolarSystem/Galaxy.swift index f37e25b1..93411087 100644 --- a/Sources/FluentBenchmark/SolarSystem/Galaxy.swift +++ b/Sources/FluentBenchmark/SolarSystem/Galaxy.swift @@ -29,14 +29,14 @@ public final class Galaxy: Model { public struct GalaxyMigration: Migration { public init() {} - public func prepare(on database: Database) -> EventLoopFuture { + public func prepare(on database: any Database) -> EventLoopFuture { database.schema("galaxies") .field("id", .uuid, .identifier(auto: false)) .field("name", .string, .required) .create() } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { database.schema("galaxies").delete() } } @@ -44,7 +44,7 @@ public struct GalaxyMigration: Migration { public struct GalaxySeed: Migration { public init() { } - public func prepare(on database: Database) -> EventLoopFuture { + public func prepare(on database: any Database) -> EventLoopFuture { .andAllSucceed([ "Andromeda", "Milky Way", @@ -56,7 +56,7 @@ public struct GalaxySeed: Migration { }, on: database.eventLoop) } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { Galaxy.query(on: database).delete() } } diff --git a/Sources/FluentBenchmark/SolarSystem/Governor.swift b/Sources/FluentBenchmark/SolarSystem/Governor.swift index 8d314f35..a2b94c11 100644 --- a/Sources/FluentBenchmark/SolarSystem/Governor.swift +++ b/Sources/FluentBenchmark/SolarSystem/Governor.swift @@ -30,7 +30,7 @@ public final class Governor: Model { } public struct GovernorMigration: Migration { - public func prepare(on database: Database) -> EventLoopFuture { + public func prepare(on database: any Database) -> EventLoopFuture { database.schema(Governor.schema) .field(.id, .uuid, .identifier(auto: false), .required) .field("name", .string, .required) @@ -39,7 +39,7 @@ public struct GovernorMigration: Migration { .create() } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { database.schema(Governor.schema).delete() } } @@ -47,7 +47,7 @@ public struct GovernorMigration: Migration { public struct GovernorSeed: Migration { public init() { } - public func prepare(on database: Database) -> EventLoopFuture { + public func prepare(on database: any Database) -> EventLoopFuture { Planet.query(on: database).all().flatMap { planets in .andAllSucceed(planets.map { planet in let governor: Governor? @@ -64,7 +64,7 @@ public struct GovernorSeed: Migration { } } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { Governor.query(on: database).delete() } } diff --git a/Sources/FluentBenchmark/SolarSystem/Jurisdiction.swift b/Sources/FluentBenchmark/SolarSystem/Jurisdiction.swift index d51a881e..c3cb325f 100644 --- a/Sources/FluentBenchmark/SolarSystem/Jurisdiction.swift +++ b/Sources/FluentBenchmark/SolarSystem/Jurisdiction.swift @@ -26,7 +26,7 @@ public final class Jurisdiction: Model { public struct JurisdictionMigration: Migration { public init() {} - public func prepare(on database: Database) -> EventLoopFuture { + public func prepare(on database: any Database) -> EventLoopFuture { database.schema(Jurisdiction.schema) .field(.id, .uuid, .identifier(auto: false), .required) .field("title", .string, .required) @@ -34,7 +34,7 @@ public struct JurisdictionMigration: Migration { .create() } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { database.schema(Jurisdiction.schema) .delete() } @@ -43,7 +43,7 @@ public struct JurisdictionMigration: Migration { public struct JurisdictionSeed: Migration { public init() {} - public func prepare(on database: Database) -> EventLoopFuture { + public func prepare(on database: any Database) -> EventLoopFuture { [ "Old", "Corporate", @@ -55,7 +55,7 @@ public struct JurisdictionSeed: Migration { .create(on: database) } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { Jurisdiction.query(on: database) .delete() } diff --git a/Sources/FluentBenchmark/SolarSystem/Moon.swift b/Sources/FluentBenchmark/SolarSystem/Moon.swift index 20c53cf4..7a5e0a91 100644 --- a/Sources/FluentBenchmark/SolarSystem/Moon.swift +++ b/Sources/FluentBenchmark/SolarSystem/Moon.swift @@ -38,7 +38,7 @@ public final class Moon: Model { public struct MoonMigration: Migration { public init() { } - public func prepare(on database: Database) -> EventLoopFuture { + public func prepare(on database: any Database) -> EventLoopFuture { database.schema("moons") .field("id", .uuid, .identifier(auto: false)) .field("name", .string, .required) @@ -48,7 +48,7 @@ public struct MoonMigration: Migration { .create() } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { database.schema("moons").delete() } } @@ -56,7 +56,7 @@ public struct MoonMigration: Migration { public final class MoonSeed: Migration { public init() { } - public func prepare(on database: Database) -> EventLoopFuture { + public func prepare(on database: any Database) -> EventLoopFuture { Planet.query(on: database).all().flatMap { planets in .andAllSucceed(planets.map { planet in let moons: [Moon] @@ -92,7 +92,7 @@ public final class MoonSeed: Migration { } } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { Moon.query(on: database).delete() } } diff --git a/Sources/FluentBenchmark/SolarSystem/Planet.swift b/Sources/FluentBenchmark/SolarSystem/Planet.swift index a3755413..7e5da08d 100644 --- a/Sources/FluentBenchmark/SolarSystem/Planet.swift +++ b/Sources/FluentBenchmark/SolarSystem/Planet.swift @@ -45,7 +45,7 @@ public final class Planet: Model { } public struct PlanetMigration: Migration { - public func prepare(on database: Database) -> EventLoopFuture { + public func prepare(on database: any Database) -> EventLoopFuture { database.schema("planets") .field("id", .uuid, .identifier(auto: false)) .field("name", .string, .required) @@ -55,7 +55,7 @@ public struct PlanetMigration: Migration { .create() } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { database.schema("planets").delete() } } @@ -63,7 +63,7 @@ public struct PlanetMigration: Migration { public struct PlanetSeed: Migration { public init() { } - public func prepare(on database: Database) -> EventLoopFuture { + public func prepare(on database: any Database) -> EventLoopFuture { Star.query(on: database).all().flatMap { stars in .andAllSucceed(stars.map { star in let planets: [Planet] @@ -91,7 +91,7 @@ public struct PlanetSeed: Migration { } } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { Planet.query(on: database).delete(force: true) } } diff --git a/Sources/FluentBenchmark/SolarSystem/PlanetTag.swift b/Sources/FluentBenchmark/SolarSystem/PlanetTag.swift index 425fbe0f..8b38ec43 100644 --- a/Sources/FluentBenchmark/SolarSystem/PlanetTag.swift +++ b/Sources/FluentBenchmark/SolarSystem/PlanetTag.swift @@ -31,7 +31,7 @@ public final class PlanetTag: Model { public struct PlanetTagMigration: Migration { public init() { } - public func prepare(on database: Database) -> EventLoopFuture { + public func prepare(on database: any Database) -> EventLoopFuture { database.schema(PlanetTag.schema) .id() .field("planet_id", .uuid, .required) @@ -42,7 +42,7 @@ public struct PlanetTagMigration: Migration { .create() } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { database.schema(PlanetTag.schema).delete() } } @@ -50,7 +50,7 @@ public struct PlanetTagMigration: Migration { public struct PlanetTagSeed: Migration { public init() { } - public func prepare(on database: Database) -> EventLoopFuture { + public func prepare(on database: any Database) -> EventLoopFuture { let planets = Planet.query(on: database).all() let tags = Tag.query(on: database).all() return planets.and(tags).flatMap { (planets, tags) in @@ -75,7 +75,7 @@ public struct PlanetTagSeed: Migration { } } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { PlanetTag.query(on: database).delete() } } diff --git a/Sources/FluentBenchmark/SolarSystem/SolarSystem.swift b/Sources/FluentBenchmark/SolarSystem/SolarSystem.swift index 5b0a6468..5eabac30 100644 --- a/Sources/FluentBenchmark/SolarSystem/SolarSystem.swift +++ b/Sources/FluentBenchmark/SolarSystem/SolarSystem.swift @@ -2,7 +2,7 @@ import AsyncKit import FluentKit import NIOCore -private let migrations: [Migration] = [ +private let migrations: [any Migration] = [ GalaxyMigration(), StarMigration(), PlanetMigration(), @@ -12,7 +12,7 @@ private let migrations: [Migration] = [ PlanetTagMigration(), ] -private let seeds: [Migration] = [ +private let seeds: [any Migration] = [ GalaxySeed(), StarSeed(), PlanetSeed(), @@ -28,8 +28,8 @@ public struct SolarSystem: Migration { self.seed = seed } - public func prepare(on database: Database) -> EventLoopFuture { - let all: [Migration] + public func prepare(on database: any Database) -> EventLoopFuture { + let all: [any Migration] if self.seed { all = migrations + seeds } else { @@ -39,8 +39,8 @@ public struct SolarSystem: Migration { return all.sequencedFlatMapEach(on: database.eventLoop) { $0.prepare(on: database) } } - public func revert(on database: Database) -> EventLoopFuture { - let all: [Migration] + public func revert(on database: any Database) -> EventLoopFuture { + let all: [any Migration] if self.seed { all = migrations + seeds } else { diff --git a/Sources/FluentBenchmark/SolarSystem/Star.swift b/Sources/FluentBenchmark/SolarSystem/Star.swift index fbb8ebae..45ab4097 100644 --- a/Sources/FluentBenchmark/SolarSystem/Star.swift +++ b/Sources/FluentBenchmark/SolarSystem/Star.swift @@ -30,7 +30,7 @@ public final class Star: Model { } public struct StarMigration: Migration { - public func prepare(on database: Database) -> EventLoopFuture { + public func prepare(on database: any Database) -> EventLoopFuture { database.schema("stars") .field("id", .uuid, .identifier(auto: false)) .field("name", .string, .required) @@ -39,7 +39,7 @@ public struct StarMigration: Migration { .create() } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { database.schema("stars").delete() } } @@ -47,7 +47,7 @@ public struct StarMigration: Migration { public final class StarSeed: Migration { public init() { } - public func prepare(on database: Database) -> EventLoopFuture { + public func prepare(on database: any Database) -> EventLoopFuture { Galaxy.query(on: database).all().flatMap { galaxies in .andAllSucceed(galaxies.map { galaxy in let stars: [Star] @@ -64,7 +64,7 @@ public final class StarSeed: Migration { } } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { Star.query(on: database).delete(force: true) } } diff --git a/Sources/FluentBenchmark/SolarSystem/Tag.swift b/Sources/FluentBenchmark/SolarSystem/Tag.swift index 218f93f9..ff2feae7 100644 --- a/Sources/FluentBenchmark/SolarSystem/Tag.swift +++ b/Sources/FluentBenchmark/SolarSystem/Tag.swift @@ -26,14 +26,14 @@ public final class Tag: Model { public struct TagMigration: Migration { public init() { } - public func prepare(on database: Database) -> EventLoopFuture { + public func prepare(on database: any Database) -> EventLoopFuture { database.schema("tags") .field("id", .uuid, .identifier(auto: false)) .field("name", .string, .required) .create() } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { database.schema("tags").delete() } } @@ -41,7 +41,7 @@ public struct TagMigration: Migration { public final class TagSeed: Migration { public init() { } - public func prepare(on database: Database) -> EventLoopFuture { + public func prepare(on database: any Database) -> EventLoopFuture { .andAllSucceed([ "Small Rocky", "Gas Giant", "Inhabited" ].map { @@ -50,7 +50,7 @@ public final class TagSeed: Migration { }, on: database.eventLoop) } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { Tag.query(on: database).delete() } } diff --git a/Sources/FluentBenchmark/Tests/ArrayTests.swift b/Sources/FluentBenchmark/Tests/ArrayTests.swift index f4b5d68b..5de5b35a 100644 --- a/Sources/FluentBenchmark/Tests/ArrayTests.swift +++ b/Sources/FluentBenchmark/Tests/ArrayTests.swift @@ -94,7 +94,7 @@ private final class Foo: Model { } private struct FooMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("foos") .field("id", .uuid, .identifier(auto: false)) .field("bar", .array(of: .int), .required) @@ -103,7 +103,7 @@ private struct FooMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("foos").delete() } } @@ -132,14 +132,14 @@ private final class User: Model { } private struct UserMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("users") .field(.id, .uuid, .identifier(auto: false)) .field("roles", .array(of: .string), .required) .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("users").delete() } } @@ -162,14 +162,14 @@ private final class FooSet: Model { } private struct FooSetMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("foos") .field("id", .uuid, .identifier(auto: false)) .field("bar", .array(of: .string), .required) .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("foos").delete() } } diff --git a/Sources/FluentBenchmark/Tests/ChildTests.swift b/Sources/FluentBenchmark/Tests/ChildTests.swift index ee429ae2..f4a7d7b0 100644 --- a/Sources/FluentBenchmark/Tests/ChildTests.swift +++ b/Sources/FluentBenchmark/Tests/ChildTests.swift @@ -9,7 +9,7 @@ extension FluentBenchmarker { public func testChild() throws { try self.testChild_with() - guard let sql = self.database as? SQLDatabase else { + guard let sql = self.database as? any SQLDatabase else { return } try self.testChild_sqlIdInt(sql) @@ -78,7 +78,7 @@ extension FluentBenchmarker { } } - private func testChild_sqlIdInt(_ sql: SQLDatabase) throws { + private func testChild_sqlIdInt(_ sql: any SQLDatabase) throws { try self.runTest(#function, [ GameMigration(), PlayerMigration() @@ -131,14 +131,14 @@ private final class Foo: Model { } private struct FooMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema(Foo.schema) .field(.id, .uuid, .identifier(auto: false), .required) .field("name", .string, .required) .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema(Foo.schema).delete() } } @@ -165,7 +165,7 @@ private final class Bar: Model { } private struct BarMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema(Bar.schema) .field(.id, .uuid, .identifier(auto: false), .required) .field("bar", .int, .required) @@ -174,7 +174,7 @@ private struct BarMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema(Bar.schema).delete() } } @@ -201,7 +201,7 @@ private final class Baz: Model { } private struct BazMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema(Baz.schema) .field(.id, .uuid, .identifier(auto: false), .required) .field("baz", .double, .required) @@ -209,7 +209,7 @@ private struct BazMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema(Baz.schema).delete() } } @@ -239,14 +239,14 @@ private final class Game: Model { } private struct GameMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema(Game.schema) .field(.id, .int, .identifier(auto: true), .required) .field("title", .string, .required) .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema(Game.schema).delete() } } @@ -275,7 +275,7 @@ private final class Player: Model { } private struct PlayerMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema(Player.schema) .field(.id, .int, .identifier(auto: true), .required) .field("name", .string, .required) @@ -284,7 +284,7 @@ private struct PlayerMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema(Player.schema).delete() } } diff --git a/Sources/FluentBenchmark/Tests/ChildrenTests.swift b/Sources/FluentBenchmark/Tests/ChildrenTests.swift index b9e177a1..ce569ca4 100644 --- a/Sources/FluentBenchmark/Tests/ChildrenTests.swift +++ b/Sources/FluentBenchmark/Tests/ChildrenTests.swift @@ -59,14 +59,14 @@ private final class Foo: Model { } private struct FooMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("foos") .field("id", .uuid, .identifier(auto: false)) .field("name", .string, .required) .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("foos").delete() } } @@ -93,7 +93,7 @@ private final class Bar: Model { } private struct BarMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("bars") .field("id", .uuid, .identifier(auto: false)) .field("bar", .int, .required) @@ -101,7 +101,7 @@ private struct BarMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("bars").delete() } } @@ -128,7 +128,7 @@ private final class Baz: Model { } private struct BazMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("bazs") .field("id", .uuid, .identifier(auto: false)) .field("baz", .double, .required) @@ -136,7 +136,7 @@ private struct BazMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("bazs").delete() } } diff --git a/Sources/FluentBenchmark/Tests/ChunkTests.swift b/Sources/FluentBenchmark/Tests/ChunkTests.swift index ab4f2ec4..9877834b 100644 --- a/Sources/FluentBenchmark/Tests/ChunkTests.swift +++ b/Sources/FluentBenchmark/Tests/ChunkTests.swift @@ -10,8 +10,8 @@ extension FluentBenchmarker { try runTest(#function, [ GalaxyMigration(), ]) { - var fetched64: [Result] = [] - var fetched2047: [Result] = [] + var fetched64: [Result] = [] + var fetched2047: [Result] = [] let saves = (1...512).map { i -> EventLoopFuture in return Galaxy(name: "Milky Way \(i)") diff --git a/Sources/FluentBenchmark/Tests/CompositeIDTests.swift b/Sources/FluentBenchmark/Tests/CompositeIDTests.swift index 353e8d59..7f178081 100644 --- a/Sources/FluentBenchmark/Tests/CompositeIDTests.swift +++ b/Sources/FluentBenchmark/Tests/CompositeIDTests.swift @@ -15,7 +15,7 @@ extension FluentBenchmarker { try self.testCompositeID_count() // Embed this here instead of having to update all the Fluent drivers - if self.database is SQLDatabase { + if self.database is any SQLDatabase { try self.testCompositeRelations() } } @@ -223,7 +223,7 @@ public final class CompositeIDModel: Model { public struct CompositeIDModelMigration: Migration { public init() {} - public func prepare(on database: Database) -> EventLoopFuture { + public func prepare(on database: any Database) -> EventLoopFuture { database.schema(CompositeIDModel.schema) .field("name", .string, .required) .field("dimensions", .int, .required) @@ -232,7 +232,7 @@ public struct CompositeIDModelMigration: Migration { .create() } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { database.schema(CompositeIDModel.schema) .delete() } @@ -241,7 +241,7 @@ public struct CompositeIDModelMigration: Migration { public struct CompositeIDModelSeed: Migration { public init() {} - public func prepare(on database: Database) -> EventLoopFuture { + public func prepare(on database: any Database) -> EventLoopFuture { [ CompositeIDModel(name: "A", dimensions: 1, additionalInfo: nil), CompositeIDModel(name: "A", dimensions: 2, additionalInfo: nil), @@ -249,7 +249,7 @@ public struct CompositeIDModelSeed: Migration { ].map { $0.create(on: database) }.flatten(on: database.eventLoop) } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { CompositeIDModel.query(on: database).delete() } } diff --git a/Sources/FluentBenchmark/Tests/CompositeRelationTests.swift b/Sources/FluentBenchmark/Tests/CompositeRelationTests.swift index 5b811ead..22b809d6 100644 --- a/Sources/FluentBenchmark/Tests/CompositeRelationTests.swift +++ b/Sources/FluentBenchmark/Tests/CompositeRelationTests.swift @@ -199,7 +199,7 @@ final class CompositeIDParentModel: Model { } struct ModelMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema(CompositeIDParentModel.schema) .field("name", .string, .required) .field("dimensions", .int, .required) @@ -207,14 +207,14 @@ final class CompositeIDParentModel: Model { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema(CompositeIDParentModel.schema) .delete() } } struct ModelSeed: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { [ CompositeIDParentModel(name: "A", dimensions: 1), CompositeIDParentModel(name: "B", dimensions: 1), @@ -222,7 +222,7 @@ final class CompositeIDParentModel: Model { ].map { $0.create(on: database) }.flatten(on: database.eventLoop) } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { CompositeIDParentModel.query(on: database).delete() } } @@ -263,9 +263,9 @@ final class CompositeIDChildModel: Model { } struct ModelMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema(CompositeIDChildModel.schema) - .field(.id, .int, .required, .identifier(auto: (database as? SQLDatabase)?.dialect.name != "sqlite")) + .field(.id, .int, .required, .identifier(auto: (database as? any SQLDatabase)?.dialect.name != "sqlite")) .field("comp_parent_model_name", .string, .required) .field("comp_parent_model_dimensions", .int, .required) @@ -297,13 +297,13 @@ final class CompositeIDChildModel: Model { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema(CompositeIDChildModel.schema).delete() } } struct ModelSeed: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { [ CompositeIDChildModel(id: 1, parentId: .init(name: "A"), additionalParentId: nil, linkedId: .init(name: "A"), additionalLinkedId: nil), CompositeIDChildModel(id: 2, parentId: .init(name: "A"), additionalParentId: .init(name: "B"), linkedId: .init(name: "B"), additionalLinkedId: .init(name: "A")), @@ -311,7 +311,7 @@ final class CompositeIDChildModel: Model { ].create(on: database) } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { CompositeIDChildModel.query(on: database).delete() } } @@ -374,7 +374,7 @@ final class CompositeParentTheFirst: Model { } struct ModelMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema(CompositeParentTheFirst.schema) .field("parent_id", .uuid, .required) .foreignKey("parent_id", references: Galaxy.schema, .id, onDelete: .cascade, onUpdate: .cascade) @@ -382,7 +382,7 @@ final class CompositeParentTheFirst: Model { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema(CompositeParentTheFirst.schema) .delete() } @@ -421,7 +421,7 @@ final class CompositeParentTheSecond: Model { } struct ModelMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema(CompositeParentTheSecond.schema) .field("ref_parent_id", .uuid, .required) .foreignKey("ref_parent_id", references: CompositeParentTheFirst.schema, "parent_id", onDelete: .cascade, onUpdate: .cascade) @@ -429,7 +429,7 @@ final class CompositeParentTheSecond: Model { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema(CompositeParentTheSecond.schema) .delete() } diff --git a/Sources/FluentBenchmark/Tests/EagerLoadTests.swift b/Sources/FluentBenchmark/Tests/EagerLoadTests.swift index edc4cf6a..6ee0779f 100644 --- a/Sources/FluentBenchmark/Tests/EagerLoadTests.swift +++ b/Sources/FluentBenchmark/Tests/EagerLoadTests.swift @@ -312,7 +312,7 @@ private final class C: Model { } private struct ABCMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { .andAllSucceed([ database.schema("a").id().field("b_id", .uuid).create(), database.schema("b").id().field("c_id", .uuid, .required).create(), @@ -320,7 +320,7 @@ private struct ABCMigration: Migration { ], on: database.eventLoop) } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { .andAllSucceed([ database.schema("a").delete(), database.schema("b").delete(), diff --git a/Sources/FluentBenchmark/Tests/EnumTests.swift b/Sources/FluentBenchmark/Tests/EnumTests.swift index 29c58260..e294ec15 100644 --- a/Sources/FluentBenchmark/Tests/EnumTests.swift +++ b/Sources/FluentBenchmark/Tests/EnumTests.swift @@ -333,7 +333,7 @@ private final class Foo: Model { private struct FooMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.enum("bar") .case("baz") .case("qux") @@ -348,7 +348,7 @@ private struct FooMigration: Migration { } } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("foos").delete().flatMap { database.enum("bar").delete() } @@ -356,7 +356,7 @@ private struct FooMigration: Migration { } private struct BarAddQuzAndQuzzMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.enum("bar") .case("quz") .case("quzz") @@ -370,7 +370,7 @@ private struct BarAddQuzAndQuzzMigration: Migration { } } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.enum("bar") .deleteCase("quuz") .update() @@ -408,14 +408,14 @@ private final class Pet: Model { private struct PetMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("pets") .field("id", .uuid, .identifier(auto: false)) .field("type", .uint8, .required) .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("pets").delete() } } @@ -472,7 +472,7 @@ private final class RawFlags: Model { } private struct FlagsMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema(Flags.schema) .field(.id, .uuid, .identifier(auto: false), .required) .field("inquired", .bool, .required) @@ -484,7 +484,7 @@ private struct FlagsMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema(Flags.schema) .delete() } diff --git a/Sources/FluentBenchmark/Tests/FilterTests.swift b/Sources/FluentBenchmark/Tests/FilterTests.swift index 8492a20f..b375ed59 100644 --- a/Sources/FluentBenchmark/Tests/FilterTests.swift +++ b/Sources/FluentBenchmark/Tests/FilterTests.swift @@ -283,7 +283,7 @@ private final class FooAlias: ModelAlias { } private struct FooEnumMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.enum("foo_type") .case("foo") .case("bar") @@ -292,26 +292,26 @@ private struct FooEnumMigration: Migration { .transform(to: ()) } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.enum("foo_type").delete() } } private struct FooOwnerMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("foo_owners") .id() .field("name", .string, .required) .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("foo_owners").delete() } } private struct FooMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.enum("foo_type").read().flatMap { fooType in database.schema("foos") .id() @@ -322,7 +322,7 @@ private struct FooMigration: Migration { } } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("foos").delete() } } diff --git a/Sources/FluentBenchmark/Tests/GroupTests.swift b/Sources/FluentBenchmark/Tests/GroupTests.swift index 5707c015..219272ef 100644 --- a/Sources/FluentBenchmark/Tests/GroupTests.swift +++ b/Sources/FluentBenchmark/Tests/GroupTests.swift @@ -162,7 +162,7 @@ private final class FlatMoon: Model { private struct FlatMoonMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("moons") .field("id", .uuid, .identifier(auto: false)) .field("name", .string, .required) @@ -173,7 +173,7 @@ private struct FlatMoonMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("moons").delete() } } @@ -182,7 +182,7 @@ private struct FlatMoonMigration: Migration { private struct FlatMoonSeed: Migration { init() { } - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { let moon = FlatMoon( name: "Moon", planet: .init( @@ -210,7 +210,7 @@ private struct FlatMoonSeed: Migration { .map { _ in } } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.eventLoop.makeSucceededFuture(()) } } diff --git a/Sources/FluentBenchmark/Tests/IDTests.swift b/Sources/FluentBenchmark/Tests/IDTests.swift index 6a06e864..41c41c81 100644 --- a/Sources/FluentBenchmark/Tests/IDTests.swift +++ b/Sources/FluentBenchmark/Tests/IDTests.swift @@ -89,13 +89,13 @@ private final class Foo: Model { } } private struct FooMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("foos") .id() .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("foos").delete() } } @@ -114,13 +114,13 @@ private final class StringFoo: Model { } } private struct StringFooMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("foos") .field(.id, .string, .identifier(auto: false)) .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("foos").delete() } } @@ -139,13 +139,13 @@ private final class AutoincrementingFoo: Model { } } private struct AutoincrementingFooMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("foos") .field(.id, .int, .identifier(auto: true)) .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("foos").delete() } } @@ -165,13 +165,13 @@ private final class CustomAutoincrementingFoo: Model { } private struct CustomAutoincrementingFooMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("foos") .field("bar", .int, .identifier(auto: true)) .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("foos").delete() } } diff --git a/Sources/FluentBenchmark/Tests/JoinTests.swift b/Sources/FluentBenchmark/Tests/JoinTests.swift index b831b4ec..fb5a7997 100644 --- a/Sources/FluentBenchmark/Tests/JoinTests.swift +++ b/Sources/FluentBenchmark/Tests/JoinTests.swift @@ -217,7 +217,7 @@ extension FluentBenchmarker { try self.runTest(#function, [ SolarSystem() ]) { - guard self.database is SQLDatabase else { return } + guard self.database is any SQLDatabase else { return } let planets = try Planet.query(on: self.database) .join(Star.self, on: \Planet.$star.$id == \Star.$id && \Star.$name != \Planet.$name) @@ -258,14 +258,14 @@ private final class Team: Model { } private struct TeamMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("teams") .field("id", .uuid, .identifier(auto: false)) .field("name", .string, .required) .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("teams").delete() } } @@ -296,7 +296,7 @@ private final class Match: Model { } struct MatchMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { return database.schema("matches") .field("id", .uuid, .identifier(auto: false)) .field("name", .string, .required) @@ -305,13 +305,13 @@ struct MatchMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { return database.schema("matches").delete() } } private struct TeamMatchSeed: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { let a = Team(name: "a") let b = Team(name: "b") let c = Team(name: "c") @@ -328,7 +328,7 @@ private struct TeamMatchSeed: Migration { } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { Match.query(on: database).delete().flatMap { Team.query(on: database).delete() } @@ -363,7 +363,7 @@ private final class School: Model { } private struct SchoolMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("schools") .field("id", .uuid, .identifier(auto: false)) .field("name", .string, .required) @@ -372,13 +372,13 @@ private struct SchoolMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("schools").delete() } } private struct SchoolSeed: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { let amsterdam = self.add( [ (name: "schoolA1", pupils: 500), @@ -402,7 +402,7 @@ private struct SchoolSeed: Migration { return .andAllSucceed([amsterdam, newYork], on: database.eventLoop) } - private func add(_ schools: [(name: String, pupils: Int)], to city: String, on database: Database) -> EventLoopFuture { + private func add(_ schools: [(name: String, pupils: Int)], to city: String, on database: any Database) -> EventLoopFuture { return City.query(on: database) .filter(\.$name == city) .first() @@ -418,7 +418,7 @@ private struct SchoolSeed: Migration { } } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { return database.eventLoop.makeSucceededFuture(()) } } @@ -448,7 +448,7 @@ private final class City: Model { } private struct CityMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("cities") .field("id", .uuid, .identifier(auto: false)) .field("name", .string, .required) @@ -456,7 +456,7 @@ private struct CityMigration: Migration { .create() } - public func revert(on database: Database) -> EventLoopFuture { + public func revert(on database: any Database) -> EventLoopFuture { database.schema("cities").delete() } } @@ -464,7 +464,7 @@ private struct CityMigration: Migration { private struct CitySeed: Migration { init() { } - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { let saves = [ City(name: "Amsterdam", averagePupils: 300), City(name: "New York", averagePupils: 400) @@ -474,7 +474,7 @@ private struct CitySeed: Migration { return .andAllSucceed(saves, on: database.eventLoop) } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { return database.eventLoop.makeSucceededFuture(()) } } diff --git a/Sources/FluentBenchmark/Tests/MiddlewareTests.swift b/Sources/FluentBenchmark/Tests/MiddlewareTests.swift index 9ad2591c..b3b886bb 100644 --- a/Sources/FluentBenchmark/Tests/MiddlewareTests.swift +++ b/Sources/FluentBenchmark/Tests/MiddlewareTests.swift @@ -161,7 +161,7 @@ private final class User: Model { } private struct UserBatchMiddleware: ModelMiddleware { - func create(model: User, on db: Database, next: AnyModelResponder) -> EventLoopFuture { + func create(model: User, on db: any Database, next: any AnyModelResponder) -> EventLoopFuture { if model.name == "A" { model.name = "AA" return next.create(model, on: db) @@ -175,35 +175,35 @@ private struct UserBatchMiddleware: ModelMiddleware { } private struct AsyncUserMiddleware: AsyncModelMiddleware { - func create(model: User, on db: Database, next: AnyAsyncModelResponder) async throws { + func create(model: User, on db: any Database, next: any AnyAsyncModelResponder) async throws { model.name = "B" try await next.create(model, on: db) throw TestError(string: "didCreate") } - func update(model: User, on db: Database, next: AnyAsyncModelResponder) async throws { + func update(model: User, on db: any Database, next: any AnyAsyncModelResponder) async throws { model.name = "D" try await next.update(model, on: db) throw TestError(string: "didUpdate") } - func softDelete(model: User, on db: Database, next: AnyAsyncModelResponder) async throws { + func softDelete(model: User, on db: any Database, next: any AnyAsyncModelResponder) async throws { model.name = "E" try await next.softDelete(model, on: db) throw TestError(string: "didSoftDelete") } - func restore(model: User, on db: Database, next: AnyAsyncModelResponder) async throws { + func restore(model: User, on db: any Database, next: any AnyAsyncModelResponder) async throws { model.name = "F" try await next.restore(model , on: db) throw TestError(string: "didRestore") } - func delete(model: User, force: Bool, on db: Database, next: AnyAsyncModelResponder) async throws { + func delete(model: User, force: Bool, on db: any Database, next: any AnyAsyncModelResponder) async throws { model.name = "G" try await next.delete(model, force: force, on: db) @@ -212,7 +212,7 @@ private struct AsyncUserMiddleware: AsyncModelMiddleware { } private struct UserMiddleware: ModelMiddleware { - func create(model: User, on db: Database, next: AnyModelResponder) -> EventLoopFuture { + func create(model: User, on db: any Database, next: any AnyModelResponder) -> EventLoopFuture { model.name = "B" return next.create(model, on: db).flatMap { @@ -220,7 +220,7 @@ private struct UserMiddleware: ModelMiddleware { } } - func update(model: User, on db: Database, next: AnyModelResponder) -> EventLoopFuture { + func update(model: User, on db: any Database, next: any AnyModelResponder) -> EventLoopFuture { model.name = "D" return next.update(model, on: db).flatMap { @@ -228,7 +228,7 @@ private struct UserMiddleware: ModelMiddleware { } } - func softDelete(model: User, on db: Database, next: AnyModelResponder) -> EventLoopFuture { + func softDelete(model: User, on db: any Database, next: any AnyModelResponder) -> EventLoopFuture { model.name = "E" return next.softDelete(model, on: db).flatMap { @@ -236,7 +236,7 @@ private struct UserMiddleware: ModelMiddleware { } } - func restore(model: User, on db: Database, next: AnyModelResponder) -> EventLoopFuture { + func restore(model: User, on db: any Database, next: any AnyModelResponder) -> EventLoopFuture { model.name = "F" return next.restore(model , on: db).flatMap { @@ -244,7 +244,7 @@ private struct UserMiddleware: ModelMiddleware { } } - func delete(model: User, force: Bool, on db: Database, next: AnyModelResponder) -> EventLoopFuture { + func delete(model: User, force: Bool, on db: any Database, next: any AnyModelResponder) -> EventLoopFuture { model.name = "G" return next.delete(model, force: force, on: db).flatMap { @@ -254,7 +254,7 @@ private struct UserMiddleware: ModelMiddleware { } private struct UserMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("users") .field("id", .uuid, .identifier(auto: false)) .field("name", .string, .required) @@ -262,7 +262,7 @@ private struct UserMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("users").delete() } } diff --git a/Sources/FluentBenchmark/Tests/MigratorTests.swift b/Sources/FluentBenchmark/Tests/MigratorTests.swift index 1315fcd9..c4e74605 100644 --- a/Sources/FluentBenchmark/Tests/MigratorTests.swift +++ b/Sources/FluentBenchmark/Tests/MigratorTests.swift @@ -175,11 +175,11 @@ internal struct ErrorMigration: Migration { struct Error: Swift.Error { } - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { return database.eventLoop.makeFailedFuture(Error()) } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { return database.eventLoop.makeSucceededFuture(()) } } diff --git a/Sources/FluentBenchmark/Tests/ModelTests.swift b/Sources/FluentBenchmark/Tests/ModelTests.swift index 684a2d01..83d6a4d5 100644 --- a/Sources/FluentBenchmark/Tests/ModelTests.swift +++ b/Sources/FluentBenchmark/Tests/ModelTests.swift @@ -14,7 +14,7 @@ extension FluentBenchmarker { try self.testModel_jsonColumn() try self.testModel_hasChanges() try self.testModel_outputError() - if self.database is SQLDatabase { + if self.database is any SQLDatabase { // Broken in Mongo at this time try self.testModel_useOfFieldsWithoutGroup() } @@ -134,7 +134,7 @@ extension FluentBenchmarker { let fetched = try Bar.find(bar.id, on: self.database).wait() XCTAssertEqual(fetched?.baz.quux, "test") - if self.database is SQLDatabase { + if self.database is any SQLDatabase { let bars = try Bar.query(on: self.database) .filter(.sql(json: "baz", "quux"), .equal, .bind("test")) .all() @@ -196,14 +196,14 @@ extension FluentBenchmarker { init() {} struct Migration: FluentKit.Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema(Enclosure.schema) .field(.id, .int, .required, .identifier(auto: true)) .field("primary", .json, .required) .field("additional", .array(of: .json), .required) .create() } - func revert(on database: Database) -> EventLoopFuture { database.schema(Enclosure.schema).delete() } + func revert(on database: any Database) -> EventLoopFuture { database.schema(Enclosure.schema).delete() } } } @@ -222,11 +222,11 @@ extension FluentBenchmarker { } struct BadFooOutput: DatabaseOutput { - func schema(_ schema: String) -> DatabaseOutput { + func schema(_ schema: String) -> any DatabaseOutput { self } - func nested(_ key: FieldKey) throws -> DatabaseOutput { + func nested(_ key: FieldKey) throws -> any DatabaseOutput { self } @@ -271,14 +271,14 @@ private final class Foo: Model { } private struct FooMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { return database.schema("foos") .field("id", .uuid, .identifier(auto: false)) .field("bar", .string) .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { return database.schema("foos").delete() } } @@ -300,14 +300,14 @@ private final class User: Model { } private struct UserMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("users") .field("id", .uuid, .identifier(auto: false)) .field("name", .string, .required) .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("users").delete() } } @@ -329,14 +329,14 @@ private final class Todo: Model { } private struct TodoMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("todos") .field("id", .uuid, .identifier(auto: false)) .field("title", .string, .required) .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("todos").delete() } } @@ -363,14 +363,14 @@ private final class Bar: Model { } private struct BarMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { return database.schema("bars") .field("id", .uuid, .identifier(auto: false)) .field("baz", .json, .required) .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { return database.schema("bars").delete() } } diff --git a/Sources/FluentBenchmark/Tests/OptionalParentTests.swift b/Sources/FluentBenchmark/Tests/OptionalParentTests.swift index 1778f98c..041a6ad0 100644 --- a/Sources/FluentBenchmark/Tests/OptionalParentTests.swift +++ b/Sources/FluentBenchmark/Tests/OptionalParentTests.swift @@ -128,7 +128,7 @@ private final class User: Model { } private struct UserMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("users") .field("id", .uuid, .identifier(auto: false)) .field("name", .string, .required) @@ -138,7 +138,7 @@ private struct UserMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("users").delete() } } @@ -147,7 +147,7 @@ private struct UserMigration: Migration { private struct UserSeed: Migration { init() { } - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { let tanner = User(name: "Tanner", pet: .init(name: "Ziz", type: .cat)) let logan = User(name: "Logan", pet: .init(name: "Runa", type: .dog)) return logan.save(on: database) @@ -155,7 +155,7 @@ private struct UserSeed: Migration { .map { _ in } } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { return database.eventLoop.makeSucceededFuture(()) } } diff --git a/Sources/FluentBenchmark/Tests/ParentTests.swift b/Sources/FluentBenchmark/Tests/ParentTests.swift index 0836b8be..8f2d88e8 100644 --- a/Sources/FluentBenchmark/Tests/ParentTests.swift +++ b/Sources/FluentBenchmark/Tests/ParentTests.swift @@ -104,7 +104,7 @@ private struct GalaxyJSON: Codable { var id: UUID var name: String - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { let keyed = try decoder.container(keyedBy: GalaxyKey.self) self.id = try keyed.decode(UUID.self, forKey: "id") self.name = try keyed.decode(String.self, forKey: "name") diff --git a/Sources/FluentBenchmark/Tests/PerformanceTests+Siblings.swift b/Sources/FluentBenchmark/Tests/PerformanceTests+Siblings.swift index 0264cbc4..6bcb1abe 100644 --- a/Sources/FluentBenchmark/Tests/PerformanceTests+Siblings.swift +++ b/Sources/FluentBenchmark/Tests/PerformanceTests+Siblings.swift @@ -178,7 +178,7 @@ private final class Person: Model { } private struct PersonMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("people") .field("id", .uuid, .identifier(auto: false)) .field("first_name", .string, .required) @@ -186,7 +186,7 @@ private struct PersonMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("people").delete() } } @@ -231,7 +231,7 @@ private final class Expedition: Model { } private struct ExpeditionMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("expeditions") .field("id", .uuid, .identifier(auto: false)) .field("name", .string, .required) @@ -240,7 +240,7 @@ private struct ExpeditionMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("expeditions").delete() } } @@ -261,7 +261,7 @@ private final class ExpeditionOfficer: Model { } private struct ExpeditionOfficerMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("expedition+officer") .field("id", .uuid, .identifier(auto: false)) .field("expedition_id", .uuid, .required, .references("expeditions", "id")) @@ -269,7 +269,7 @@ private struct ExpeditionOfficerMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("expedition+officer").delete() } } @@ -290,7 +290,7 @@ private final class ExpeditionScientist: Model { } private struct ExpeditionScientistMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("expedition+scientist") .field("id", .uuid, .identifier(auto: false)) .field("expedition_id", .uuid, .required, .references("expeditions", "id")) @@ -298,7 +298,7 @@ private struct ExpeditionScientistMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("expedition+scientist").delete() } } @@ -325,7 +325,7 @@ private final class ExpeditionDoctor: Model { } private struct ExpeditionDoctorMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("expedition+doctor") .field("id", .uuid, .identifier(auto: false)) .field("expedition_id", .uuid, .required, .references("expeditions", "id")) @@ -333,7 +333,7 @@ private struct ExpeditionDoctorMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("expedition+doctor").delete() } } diff --git a/Sources/FluentBenchmark/Tests/PerformanceTests.swift b/Sources/FluentBenchmark/Tests/PerformanceTests.swift index cf5a5ded..5504868b 100644 --- a/Sources/FluentBenchmark/Tests/PerformanceTests.swift +++ b/Sources/FluentBenchmark/Tests/PerformanceTests.swift @@ -98,7 +98,7 @@ private final class Foo: Model { private struct FooMigration: Migration { let decimalType: DatabaseSchema.DataType - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("foos") .field("id", .uuid, .identifier(auto: false)) .field("bar", .int, .required) @@ -116,7 +116,7 @@ private struct FooMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("foos").delete() } } diff --git a/Sources/FluentBenchmark/Tests/SQLTests.swift b/Sources/FluentBenchmark/Tests/SQLTests.swift index 0bf07d93..7de7e34b 100644 --- a/Sources/FluentBenchmark/Tests/SQLTests.swift +++ b/Sources/FluentBenchmark/Tests/SQLTests.swift @@ -6,13 +6,13 @@ import SQLKit extension FluentBenchmarker { public func testSQL() throws { - guard let sql = self.database as? SQLDatabase else { + guard let sql = self.database as? any SQLDatabase else { return } try self.testSQL_rawDecode(sql) } - private func testSQL_rawDecode(_ sql: SQLDatabase) throws { + private func testSQL_rawDecode(_ sql: any SQLDatabase) throws { try self.runTest(#function, [ UserMigration() ]) { @@ -92,7 +92,7 @@ private final class User: Model { } private struct UserMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("users") .id() .field("first_name", .string, .required) @@ -101,7 +101,7 @@ private struct UserMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("users").delete() } } diff --git a/Sources/FluentBenchmark/Tests/SchemaTests.swift b/Sources/FluentBenchmark/Tests/SchemaTests.swift index f4db5152..f4bc10da 100644 --- a/Sources/FluentBenchmark/Tests/SchemaTests.swift +++ b/Sources/FluentBenchmark/Tests/SchemaTests.swift @@ -12,7 +12,7 @@ extension FluentBenchmarker { if foreignKeys { try self.testSchema_fieldReference() } - if self.database is SQLDatabase { + if self.database is any SQLDatabase { try self.testSchema_customSqlConstraints() try self.testSchema_customSqlFields() try self.testSchema_deleteConstraints() @@ -23,7 +23,7 @@ extension FluentBenchmarker { try self.runTest(#function, [ CreateCategories() ]) { - guard let sql = self.database as? SQLDatabase, sql.dialect.alterTableSyntax.allowsBatch else { + guard let sql = self.database as? any SQLDatabase, sql.dialect.alterTableSyntax.allowsBatch else { self.database.logger.warning("Skipping \(#function)") return } @@ -49,7 +49,7 @@ extension FluentBenchmarker { try self.runTest(#function, [ CreateCategories() ]) { - guard let sql = self.database as? SQLDatabase, sql.dialect.alterTableSyntax.allowsBatch else { + guard let sql = self.database as? any SQLDatabase, sql.dialect.alterTableSyntax.allowsBatch else { self.database.logger.warning("Skipping \(#function)") return } @@ -87,7 +87,7 @@ extension FluentBenchmarker { try self.runTest(#function, [ DeleteTableMigration(name: "custom_constraints") ]) { - let normalized1 = (self.database as! SQLDatabase).dialect.normalizeSQLConstraint(identifier: SQLIdentifier("id_unq_1")) + let normalized1 = (self.database as! any SQLDatabase).dialect.normalizeSQLConstraint(identifier: SQLIdentifier("id_unq_1")) try self.database.schema("custom_constraints") .id() @@ -101,7 +101,7 @@ extension FluentBenchmarker { .create().wait() - if (self.database as! SQLDatabase).dialect.alterTableSyntax.allowsBatch { + if (self.database as! any SQLDatabase).dialect.alterTableSyntax.allowsBatch { try self.database.schema("custom_constraints") // Test raw SQL for dropping constraints: .deleteConstraint(.sql(embed: "\(SQLDropTypedConstraint(name: SQLIdentifier("id_unq_1"), algorithm: .sql(raw: "")))")) @@ -118,7 +118,7 @@ extension FluentBenchmarker { .id() // Test query string SQL for field data types: - .field("morenotid", .sql(embed: "\(raw: "TEXT")")) + .field("morenotid", .sql(embed: "\(unsafeRaw: "TEXT")")) // Test raw SQL for field names: .field(.definition(name: .sql(embed: "\(ident: "stillnotid")"), dataType: .int, constraints: [.required])) @@ -132,7 +132,7 @@ extension FluentBenchmarker { .create().wait() - if (self.database as! SQLDatabase).dialect.alterTableSyntax.allowsBatch { + if (self.database as! any SQLDatabase).dialect.alterTableSyntax.allowsBatch { try self.database.schema("custom_fields") // Test raw SQL for field updates: @@ -159,7 +159,7 @@ extension FluentBenchmarker { .create().wait() - if (self.database as! SQLDatabase).dialect.alterTableSyntax.allowsBatch { + if (self.database as! any SQLDatabase).dialect.alterTableSyntax.allowsBatch { try self.database.schema("normal_constraints") // Test `DROP FOREIGN KEY` (MySQL) or `DROP CONSTRAINT` (Postgres) .deleteConstraint(.constraint(.foreignKey([.key("catid")], Category.schema, [.key(.id)], onDelete: .noAction, onUpdate: .noAction))) @@ -188,25 +188,25 @@ final class Category: Model { } struct CreateCategories: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("categories") .id() .field("name", .string, .required) .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("categories") .delete() } } struct AddUniqueConstraintToCategories: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("categories") .unique(on: "name") .update() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("categories") .deleteUnique(on: "name") .update() @@ -215,12 +215,12 @@ struct AddUniqueConstraintToCategories: Migration { struct AddNamedUniqueConstraintToCategories: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("categories") .unique(on: "name", name: "foo") .update() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("categories") .deleteConstraint(name: "foo") .update() @@ -231,11 +231,11 @@ struct AddNamedUniqueConstraintToCategories: Migration { struct DeleteTableMigration: Migration { let name: String - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.eventLoop.future() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema(self.name).delete() } } diff --git a/Sources/FluentBenchmark/Tests/SetTests.swift b/Sources/FluentBenchmark/Tests/SetTests.swift index f5095f83..79c24dfc 100644 --- a/Sources/FluentBenchmark/Tests/SetTests.swift +++ b/Sources/FluentBenchmark/Tests/SetTests.swift @@ -64,7 +64,7 @@ private final class Test: Model { } private struct TestMigration: FluentKit.Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("test") .field("id", .uuid, .identifier(auto: false)) .field("int_value", .int) @@ -72,7 +72,7 @@ private struct TestMigration: FluentKit.Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("test").delete() } } @@ -92,7 +92,7 @@ private final class Test2: Model { } private struct Test2Migration: FluentKit.Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.enum("foo").case("bar").case("baz").create().flatMap { foo in database.schema("test") .id() @@ -101,7 +101,7 @@ private struct Test2Migration: FluentKit.Migration { } } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("test").delete().flatMap { database.enum("foo").delete() } diff --git a/Sources/FluentBenchmark/Tests/SoftDeleteTests.swift b/Sources/FluentBenchmark/Tests/SoftDeleteTests.swift index 69ce93b6..3885684b 100644 --- a/Sources/FluentBenchmark/Tests/SoftDeleteTests.swift +++ b/Sources/FluentBenchmark/Tests/SoftDeleteTests.swift @@ -146,14 +146,14 @@ extension FluentBenchmarker { } struct FooMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("foos") .id() .field("bar", .uuid, .required) .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("foos").delete() } } @@ -171,14 +171,14 @@ extension FluentBenchmarker { } struct BarMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("bars") .id() .field("deleted_at", .datetime) .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("bars").delete() } } @@ -252,7 +252,7 @@ private final class Trash: Model { } private struct TrashMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("trash") .field("id", .uuid, .identifier(auto: false), .custom("UNIQUE")) .field("contents", .string, .required) @@ -260,7 +260,7 @@ private struct TrashMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("trash").delete() } } diff --git a/Sources/FluentBenchmark/Tests/TimestampTests.swift b/Sources/FluentBenchmark/Tests/TimestampTests.swift index 4e535474..4bfc8ed3 100644 --- a/Sources/FluentBenchmark/Tests/TimestampTests.swift +++ b/Sources/FluentBenchmark/Tests/TimestampTests.swift @@ -197,7 +197,7 @@ private final class User: Model { } private struct UserMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("users") .field("id", .uuid, .identifier(auto: false)) .field("name", .string, .required) @@ -207,7 +207,7 @@ private struct UserMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("users").delete() } } @@ -247,7 +247,7 @@ private final class Event: Model { } private struct EventMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("events") .field("id", .uuid, .identifier(auto: false)) .field("name", .string, .required) @@ -258,7 +258,7 @@ private struct EventMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("events").delete() } } diff --git a/Sources/FluentBenchmark/Tests/UniqueTests.swift b/Sources/FluentBenchmark/Tests/UniqueTests.swift index 069b8967..03fa23af 100644 --- a/Sources/FluentBenchmark/Tests/UniqueTests.swift +++ b/Sources/FluentBenchmark/Tests/UniqueTests.swift @@ -57,7 +57,7 @@ private final class Foo: Model { } private struct FooMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("foos") .field("id", .uuid, .identifier(auto: false)) .field("bar", .string, .required) @@ -66,33 +66,33 @@ private struct FooMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("foos").delete() } } private struct BarMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("bars") .field("name", .string) .unique(on: "name") .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("bars").delete() } } private struct BazMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("bazs") .field("name", .string) .unique(on: "name") .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("bazs").delete() } } diff --git a/Sources/FluentKit/Concurrency/AsyncMigration.swift b/Sources/FluentKit/Concurrency/AsyncMigration.swift index b7a152a4..37033853 100644 --- a/Sources/FluentKit/Concurrency/AsyncMigration.swift +++ b/Sources/FluentKit/Concurrency/AsyncMigration.swift @@ -1,12 +1,12 @@ import NIOCore public protocol AsyncMigration: Migration { - func prepare(on database: Database) async throws - func revert(on database: Database) async throws + func prepare(on database: any Database) async throws + func revert(on database: any Database) async throws } public extension AsyncMigration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { let promise = database.eventLoop.makePromise(of: Void.self) promise.completeWithTask { try await self.prepare(on: database) @@ -14,7 +14,7 @@ public extension AsyncMigration { return promise.futureResult } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { let promise = database.eventLoop.makePromise(of: Void.self) promise.completeWithTask { try await self.revert(on: database) diff --git a/Sources/FluentKit/Concurrency/AsyncModelMiddleware.swift b/Sources/FluentKit/Concurrency/AsyncModelMiddleware.swift index 3f38ded1..7c026153 100644 --- a/Sources/FluentKit/Concurrency/AsyncModelMiddleware.swift +++ b/Sources/FluentKit/Concurrency/AsyncModelMiddleware.swift @@ -3,15 +3,20 @@ import NIOCore public protocol AsyncModelMiddleware: AnyModelMiddleware { associatedtype Model: FluentKit.Model - func create(model: Model, on db: Database, next: AnyAsyncModelResponder) async throws - func update(model: Model, on db: Database, next: AnyAsyncModelResponder) async throws - func delete(model: Model, force: Bool, on db: Database, next: AnyAsyncModelResponder) async throws - func softDelete(model: Model, on db: Database, next: AnyAsyncModelResponder) async throws - func restore(model: Model, on db: Database, next: AnyAsyncModelResponder) async throws + func create(model: Model, on db: any Database, next: any AnyAsyncModelResponder) async throws + func update(model: Model, on db: any Database, next: any AnyAsyncModelResponder) async throws + func delete(model: Model, force: Bool, on db: any Database, next: any AnyAsyncModelResponder) async throws + func softDelete(model: Model, on db: any Database, next: any AnyAsyncModelResponder) async throws + func restore(model: Model, on db: any Database, next: any AnyAsyncModelResponder) async throws } extension AsyncModelMiddleware { - public func handle(_ event: ModelEvent, _ model: AnyModel, on db: Database, chainingTo next: AnyModelResponder) -> EventLoopFuture { + public func handle( + _ event: ModelEvent, + _ model: any AnyModel, + on db: any Database, + chainingTo next: any AnyModelResponder + ) -> EventLoopFuture { let promise = db.eventLoop.makePromise(of: Void.self) promise.completeWithTask { guard let modelType = model as? Model else { @@ -39,23 +44,23 @@ extension AsyncModelMiddleware { return promise.futureResult } - public func create(model: Model, on db: Database, next: AnyAsyncModelResponder) async throws { + public func create(model: Model, on db: any Database, next: any AnyAsyncModelResponder) async throws { try await next.create(model, on: db) } - public func update(model: Model, on db: Database, next: AnyAsyncModelResponder) async throws { + public func update(model: Model, on db: any Database, next: any AnyAsyncModelResponder) async throws { try await next.update(model, on: db) } - public func delete(model: Model, force: Bool, on db: Database, next: AnyAsyncModelResponder) async throws { + public func delete(model: Model, force: Bool, on db: any Database, next: any AnyAsyncModelResponder) async throws { try await next.delete(model, force: force, on: db) } - public func softDelete(model: Model, on db: Database, next: AnyAsyncModelResponder) async throws { + public func softDelete(model: Model, on db: any Database, next: any AnyAsyncModelResponder) async throws { try await next.softDelete(model, on: db) } - public func restore(model: Model, on db: Database, next: AnyAsyncModelResponder) async throws { + public func restore(model: Model, on db: any Database, next: any AnyAsyncModelResponder) async throws { try await next.restore(model, on: db) } } diff --git a/Sources/FluentKit/Concurrency/Children+Concurrency.swift b/Sources/FluentKit/Concurrency/Children+Concurrency.swift index 8137fd6d..47e97636 100644 --- a/Sources/FluentKit/Concurrency/Children+Concurrency.swift +++ b/Sources/FluentKit/Concurrency/Children+Concurrency.swift @@ -1,21 +1,21 @@ import NIOCore public extension ChildrenProperty { - func load(on database: Database) async throws { + func load(on database: any Database) async throws { try await self.load(on: database).get() } - func create(_ to: To, on database: Database) async throws { + func create(_ to: To, on database: any Database) async throws { try await self.create(to, on: database).get() } - func create(_ to: [To], on database: Database) async throws { + func create(_ to: [To], on database: any Database) async throws { try await self.create(to, on: database).get() } } public extension CompositeChildrenProperty { - func load(on database: Database) async throws { + func load(on database: any Database) async throws { try await self.load(on: database).get() } } diff --git a/Sources/FluentKit/Concurrency/Database+Concurrency.swift b/Sources/FluentKit/Concurrency/Database+Concurrency.swift index 15c3060f..7e422893 100644 --- a/Sources/FluentKit/Concurrency/Database+Concurrency.swift +++ b/Sources/FluentKit/Concurrency/Database+Concurrency.swift @@ -1,7 +1,7 @@ import NIOCore public extension Database { - func transaction(_ closure: @Sendable @escaping (Database) async throws -> T) async throws -> T { + func transaction(_ closure: @Sendable @escaping (any Database) async throws -> T) async throws -> T { try await self.transaction { db -> EventLoopFuture in let promise = self.eventLoop.makePromise(of: T.self) promise.completeWithTask{ try await closure(db) } @@ -9,7 +9,7 @@ public extension Database { }.get() } - func withConnection(_ closure: @Sendable @escaping (Database) async throws -> T) async throws -> T { + func withConnection(_ closure: @Sendable @escaping (any Database) async throws -> T) async throws -> T { try await self.withConnection { db -> EventLoopFuture in let promise = self.eventLoop.makePromise(of: T.self) promise.completeWithTask{ try await closure(db) } diff --git a/Sources/FluentKit/Concurrency/Model+Concurrency.swift b/Sources/FluentKit/Concurrency/Model+Concurrency.swift index 012c2bc2..dcf8d239 100644 --- a/Sources/FluentKit/Concurrency/Model+Concurrency.swift +++ b/Sources/FluentKit/Concurrency/Model+Concurrency.swift @@ -3,39 +3,39 @@ import NIOCore public extension Model { static func find( _ id: Self.IDValue?, - on database: Database + on database: any Database ) async throws -> Self? { try await self.find(id, on: database).get() } // MARK: - CRUD - func save(on database: Database) async throws { + func save(on database: any Database) async throws { try await self.save(on: database).get() } - func create(on database: Database) async throws { + func create(on database: any Database) async throws { try await self.create(on: database).get() } - func update(on database: Database) async throws { + func update(on database: any Database) async throws { try await self.update(on: database).get() } - func delete(force: Bool = false, on database: Database) async throws { + func delete(force: Bool = false, on database: any Database) async throws { try await self.delete(force: force, on: database).get() } - func restore(on database: Database) async throws { + func restore(on database: any Database) async throws { try await self.restore(on: database).get() } } public extension Collection where Element: FluentKit.Model { - func delete(force: Bool = false, on database: Database) async throws { + func delete(force: Bool = false, on database: any Database) async throws { try await self.delete(force: force, on: database).get() } - func create(on database: Database) async throws { + func create(on database: any Database) async throws { try await self.create(on: database).get() } } diff --git a/Sources/FluentKit/Concurrency/ModelResponder+Concurrency.swift b/Sources/FluentKit/Concurrency/ModelResponder+Concurrency.swift index 07a8b29d..adc78b4c 100644 --- a/Sources/FluentKit/Concurrency/ModelResponder+Concurrency.swift +++ b/Sources/FluentKit/Concurrency/ModelResponder+Concurrency.swift @@ -3,13 +3,13 @@ import NIOCore public protocol AnyAsyncModelResponder: AnyModelResponder { func handle( _ event: ModelEvent, - _ model: AnyModel, - on db: Database + _ model: any AnyModel, + on db: any Database ) async throws } extension AnyAsyncModelResponder { - func handle(_ event: ModelEvent, _ model: AnyModel, on db: Database) -> EventLoopFuture { + func handle(_ event: ModelEvent, _ model: any AnyModel, on db: any Database) -> EventLoopFuture { let promise = db.eventLoop.makePromise(of: Void.self) promise.completeWithTask { try await self.handle(event, model, on: db) @@ -19,35 +19,35 @@ extension AnyAsyncModelResponder { } extension AnyAsyncModelResponder { - public func create(_ model: AnyModel, on db: Database) async throws { + public func create(_ model: any AnyModel, on db: any Database) async throws { try await handle(.create, model, on: db) } - public func update(_ model: AnyModel, on db: Database) async throws { + public func update(_ model: any AnyModel, on db: any Database) async throws { try await handle(.update, model, on: db) } - public func restore(_ model: AnyModel, on db: Database) async throws { + public func restore(_ model: any AnyModel, on db: any Database) async throws { try await handle(.restore, model, on: db) } - public func softDelete(_ model: AnyModel, on db: Database) async throws { + public func softDelete(_ model: any AnyModel, on db: any Database) async throws { try await handle(.softDelete, model, on: db) } - public func delete(_ model: AnyModel, force: Bool, on db: Database) async throws { + public func delete(_ model: any AnyModel, force: Bool, on db: any Database) async throws { try await handle(.delete(force), model, on: db) } } internal struct AsyncBasicModelResponder: AnyAsyncModelResponder { - private let _handle: (ModelEvent, AnyModel, Database) async throws -> Void + private let _handle: (ModelEvent, any AnyModel, any Database) async throws -> Void - internal func handle(_ event: ModelEvent, _ model: AnyModel, on db: Database) async throws { + internal func handle(_ event: ModelEvent, _ model: any AnyModel, on db: any Database) async throws { return try await _handle(event, model, db) } - init(handle: @escaping (ModelEvent, AnyModel, Database) async throws -> Void) { + init(handle: @escaping (ModelEvent, any AnyModel, any Database) async throws -> Void) { self._handle = handle } } diff --git a/Sources/FluentKit/Concurrency/OptionalChild+Concurrency.swift b/Sources/FluentKit/Concurrency/OptionalChild+Concurrency.swift index c01088e4..6e35237d 100644 --- a/Sources/FluentKit/Concurrency/OptionalChild+Concurrency.swift +++ b/Sources/FluentKit/Concurrency/OptionalChild+Concurrency.swift @@ -1,17 +1,17 @@ import NIOCore public extension OptionalChildProperty { - func load(on database: Database) async throws { + func load(on database: any Database) async throws { try await self.load(on: database).get() } - func create(_ to: To, on database: Database) async throws { + func create(_ to: To, on database: any Database) async throws { try await self.create(to, on: database).get() } } public extension CompositeOptionalChildProperty { - func load(on database: Database) async throws { + func load(on database: any Database) async throws { try await self.load(on: database).get() } } diff --git a/Sources/FluentKit/Concurrency/OptionalParent+Concurrency.swift b/Sources/FluentKit/Concurrency/OptionalParent+Concurrency.swift index 1ee4296d..9388746d 100644 --- a/Sources/FluentKit/Concurrency/OptionalParent+Concurrency.swift +++ b/Sources/FluentKit/Concurrency/OptionalParent+Concurrency.swift @@ -1,13 +1,13 @@ import NIOCore public extension OptionalParentProperty { - func load(on database: Database) async throws { + func load(on database: any Database) async throws { try await self.load(on: database).get() } } public extension CompositeOptionalParentProperty { - func load(on database: Database) async throws { + func load(on database: any Database) async throws { try await self.load(on: database).get() } } diff --git a/Sources/FluentKit/Concurrency/Parent+Concurrency.swift b/Sources/FluentKit/Concurrency/Parent+Concurrency.swift index f6b3b8e4..e52cfec3 100644 --- a/Sources/FluentKit/Concurrency/Parent+Concurrency.swift +++ b/Sources/FluentKit/Concurrency/Parent+Concurrency.swift @@ -1,13 +1,13 @@ import NIOCore public extension ParentProperty { - func load(on database: Database) async throws { + func load(on database: any Database) async throws { try await self.load(on: database).get() } } public extension CompositeParentProperty { - func load(on database: Database) async throws { + func load(on database: any Database) async throws { try await self.load(on: database).get() } } diff --git a/Sources/FluentKit/Concurrency/QueryBuilder+Concurrency.swift b/Sources/FluentKit/Concurrency/QueryBuilder+Concurrency.swift index 1f9d4697..92c034e7 100644 --- a/Sources/FluentKit/Concurrency/QueryBuilder+Concurrency.swift +++ b/Sources/FluentKit/Concurrency/QueryBuilder+Concurrency.swift @@ -16,7 +16,7 @@ public extension QueryBuilder { // MARK: - Fetch - func chunk(max: Int, closure: @escaping ([Result]) -> ()) async throws { + func chunk(max: Int, closure: @escaping ([Result]) -> ()) async throws { try await self.chunk(max: max, closure: closure).get() } @@ -47,11 +47,11 @@ public extension QueryBuilder { try await self.run().get() } - func all(_ onOutput: @escaping (Result) -> ()) async throws { + func all(_ onOutput: @escaping (Result) -> ()) async throws { try await self.all(onOutput).get() } - func run(_ onOutput: @escaping (DatabaseOutput) -> ()) async throws { + func run(_ onOutput: @escaping (any DatabaseOutput) -> ()) async throws { try await self.run(onOutput).get() } diff --git a/Sources/FluentKit/Concurrency/Relation+Concurrency.swift b/Sources/FluentKit/Concurrency/Relation+Concurrency.swift index 0e1406f5..cbde9bd9 100644 --- a/Sources/FluentKit/Concurrency/Relation+Concurrency.swift +++ b/Sources/FluentKit/Concurrency/Relation+Concurrency.swift @@ -1,7 +1,7 @@ import NIOCore public extension Relation { - func get(reload: Bool = false, on database: Database) async throws -> RelatedValue { + func get(reload: Bool = false, on database: any Database) async throws -> RelatedValue { try await self.get(reload: reload, on: database).get() } } diff --git a/Sources/FluentKit/Database/Database+Logging.swift b/Sources/FluentKit/Database/Database+Logging.swift index 54e5fd07..252002d9 100644 --- a/Sources/FluentKit/Database/Database+Logging.swift +++ b/Sources/FluentKit/Database/Database+Logging.swift @@ -25,7 +25,7 @@ extension LoggingOverrideDatabase: Database { func execute( query: DatabaseQuery, - onOutput: @escaping (DatabaseOutput) -> () + onOutput: @escaping (any DatabaseOutput) -> () ) -> EventLoopFuture { self.database.execute(query: query, onOutput: onOutput) } @@ -47,19 +47,19 @@ extension LoggingOverrideDatabase: Database { self.database.inTransaction } - func transaction(_ closure: @escaping (Database) -> EventLoopFuture) -> EventLoopFuture { + func transaction(_ closure: @escaping (any Database) -> EventLoopFuture) -> EventLoopFuture { self.database.transaction(closure) } - func withConnection(_ closure: @escaping (Database) -> EventLoopFuture) -> EventLoopFuture { + func withConnection(_ closure: @escaping (any Database) -> EventLoopFuture) -> EventLoopFuture { self.database.withConnection(closure) } } extension LoggingOverrideDatabase: SQLDatabase where D: SQLDatabase { - func execute(sql query: SQLExpression, _ onRow: @escaping (SQLRow) -> ()) -> EventLoopFuture { + func execute(sql query: any SQLExpression, _ onRow: @escaping (any SQLRow) -> ()) -> EventLoopFuture { self.database.execute(sql: query, onRow) } - var dialect: SQLDialect { self.database.dialect } + var dialect: any SQLDialect { self.database.dialect } var version: (any SQLDatabaseReportedVersion)? { self.database.version } } diff --git a/Sources/FluentKit/Database/Database.swift b/Sources/FluentKit/Database/Database.swift index f9329bd1..65ca9357 100644 --- a/Sources/FluentKit/Database/Database.swift +++ b/Sources/FluentKit/Database/Database.swift @@ -6,7 +6,7 @@ public protocol Database { func execute( query: DatabaseQuery, - onOutput: @escaping (DatabaseOutput) -> () + onOutput: @escaping (any DatabaseOutput) -> () ) -> EventLoopFuture func execute( @@ -19,9 +19,9 @@ public protocol Database { var inTransaction: Bool { get } - func transaction(_ closure: @escaping (Database) -> EventLoopFuture) -> EventLoopFuture + func transaction(_ closure: @escaping (any Database) -> EventLoopFuture) -> EventLoopFuture - func withConnection(_ closure: @escaping (Database) -> EventLoopFuture) -> EventLoopFuture + func withConnection(_ closure: @escaping (any Database) -> EventLoopFuture) -> EventLoopFuture } extension Database { @@ -33,7 +33,7 @@ extension Database { } extension Database { - public var configuration: DatabaseConfiguration { + public var configuration: any DatabaseConfiguration { self.context.configuration } @@ -41,7 +41,7 @@ extension Database { self.context.logger } - public var eventLoop: EventLoop { + public var eventLoop: any EventLoop { self.context.eventLoop } @@ -55,26 +55,26 @@ extension Database { } public protocol DatabaseDriver { - func makeDatabase(with context: DatabaseContext) -> Database + func makeDatabase(with context: DatabaseContext) -> any Database func shutdown() } public protocol DatabaseConfiguration { - var middleware: [AnyModelMiddleware] { get set } - func makeDriver(for databases: Databases) -> DatabaseDriver + var middleware: [any AnyModelMiddleware] { get set } + func makeDriver(for databases: Databases) -> any DatabaseDriver } public struct DatabaseContext { - public let configuration: DatabaseConfiguration + public let configuration: any DatabaseConfiguration public let logger: Logger - public let eventLoop: EventLoop + public let eventLoop: any EventLoop public let history: QueryHistory? public let pageSizeLimit: Int? public init( - configuration: DatabaseConfiguration, + configuration: any DatabaseConfiguration, logger: Logger, - eventLoop: EventLoop, + eventLoop: any EventLoop, history: QueryHistory? = nil, pageSizeLimit: Int? = nil ) { diff --git a/Sources/FluentKit/Database/DatabaseInput.swift b/Sources/FluentKit/Database/DatabaseInput.swift index 6e36304f..e4c4542c 100644 --- a/Sources/FluentKit/Database/DatabaseInput.swift +++ b/Sources/FluentKit/Database/DatabaseInput.swift @@ -72,13 +72,13 @@ extension DatabaseInput { extension DatabaseInput { /// Return a ``DatabaseInput`` wrapping `self` so as to apply a given prefix to each field key /// before processing. - public func prefixed(by prefix: FieldKey) -> DatabaseInput { + public func prefixed(by prefix: FieldKey) -> any DatabaseInput { PrefixedDatabaseInput(prefix: prefix, strategy: .none, base: self) } /// Return a ``DatabaseInput`` wrapping `self` so as to apply a given prefix, according to a given /// ``KeyPrefixingStrategy``, to each field key before processing. - public func prefixed(by prefix: FieldKey, using stratgey: KeyPrefixingStrategy) -> DatabaseInput { + public func prefixed(by prefix: FieldKey, using stratgey: KeyPrefixingStrategy) -> any DatabaseInput { PrefixedDatabaseInput(prefix: prefix, strategy: stratgey, base: self) } } @@ -160,7 +160,7 @@ internal struct NullValueOverrideInput: DatabaseInput { extension DatabaseInput { /// Returns `self` wrapped with a ``NullValueOverrideInput``. This is here primarily so the actual /// implementation be defined generically rather than using existentials. - internal func nullValueOveridden() -> DatabaseInput { + internal func nullValueOveridden() -> any DatabaseInput { NullValueOverrideInput(base: self) } } diff --git a/Sources/FluentKit/Database/DatabaseOutput.swift b/Sources/FluentKit/Database/DatabaseOutput.swift index b441be55..c809cab3 100644 --- a/Sources/FluentKit/Database/DatabaseOutput.swift +++ b/Sources/FluentKit/Database/DatabaseOutput.swift @@ -1,5 +1,5 @@ public protocol DatabaseOutput: CustomStringConvertible { - func schema(_ schema: String) -> DatabaseOutput + func schema(_ schema: String) -> any DatabaseOutput func contains(_ key: FieldKey) -> Bool func decodeNil(_ key: FieldKey) throws -> Bool func decode(_ key: FieldKey, as type: T.Type) throws -> T @@ -13,29 +13,29 @@ extension DatabaseOutput { try self.decode(key, as: T.self) } - public func qualifiedSchema(space: String?, _ schema: String) -> DatabaseOutput { + public func qualifiedSchema(space: String?, _ schema: String) -> any DatabaseOutput { self.schema([space, schema].compactMap({ $0 }).joined(separator: "_")) } } extension DatabaseOutput { - public func prefixed(by prefix: FieldKey) -> DatabaseOutput { + public func prefixed(by prefix: FieldKey) -> any DatabaseOutput { PrefixedDatabaseOutput(prefix: prefix, strategy: .none, base: self) } - public func prefixed(by prefix: FieldKey, using stratgey: KeyPrefixingStrategy) -> DatabaseOutput { + public func prefixed(by prefix: FieldKey, using stratgey: KeyPrefixingStrategy) -> any DatabaseOutput { PrefixedDatabaseOutput(prefix: prefix, strategy: stratgey, base: self) } - public func cascading(to output: DatabaseOutput) -> DatabaseOutput { + public func cascading(to output: any DatabaseOutput) -> any DatabaseOutput { return CombinedOutput(first: self, second: output) } } private struct CombinedOutput: DatabaseOutput { - let first: DatabaseOutput, second: DatabaseOutput + let first: any DatabaseOutput, second: any DatabaseOutput - func schema(_ schema: String) -> DatabaseOutput { + func schema(_ schema: String) -> any DatabaseOutput { CombinedOutput(first: self.first.schema(schema), second: self.second.schema(schema)) } @@ -58,9 +58,9 @@ private struct CombinedOutput: DatabaseOutput { private struct PrefixedDatabaseOutput: DatabaseOutput { let prefix: FieldKey, strategy: KeyPrefixingStrategy - let base: DatabaseOutput + let base: any DatabaseOutput - func schema(_ schema: String) -> DatabaseOutput { + func schema(_ schema: String) -> any DatabaseOutput { PrefixedDatabaseOutput(prefix: self.prefix, strategy: self.strategy, base: self.base.schema(schema)) } diff --git a/Sources/FluentKit/Database/Databases.swift b/Sources/FluentKit/Database/Databases.swift index 3ca8d808..bdaf3967 100644 --- a/Sources/FluentKit/Database/Databases.swift +++ b/Sources/FluentKit/Database/Databases.swift @@ -5,23 +5,23 @@ import NIOPosix import Logging public struct DatabaseConfigurationFactory { - public let make: () -> DatabaseConfiguration + public let make: () -> any DatabaseConfiguration - public init(make: @escaping () -> DatabaseConfiguration) { + public init(make: @escaping () -> any DatabaseConfiguration) { self.make = make } } public final class Databases { - public let eventLoopGroup: EventLoopGroup + public let eventLoopGroup: any EventLoopGroup public let threadPool: NIOThreadPool - private var configurations: [DatabaseID: DatabaseConfiguration] + private var configurations: [DatabaseID: any DatabaseConfiguration] private var defaultID: DatabaseID? // Currently running database drivers. // Access to this variable must be synchronized. - private var drivers: [DatabaseID: DatabaseDriver] + private var drivers: [DatabaseID: any DatabaseDriver] // Synchronize access across threads. private var lock: NIOLock @@ -30,7 +30,7 @@ public final class Databases { let databases: Databases public func use( - _ middleware: AnyModelMiddleware, + _ middleware: any AnyModelMiddleware, on id: DatabaseID? = nil ) { self.databases.lock.withLockVoid { @@ -55,7 +55,7 @@ public final class Databases { .init(databases: self) } - public init(threadPool: NIOThreadPool, on eventLoopGroup: EventLoopGroup) { + public init(threadPool: NIOThreadPool, on eventLoopGroup: any EventLoopGroup) { self.eventLoopGroup = eventLoopGroup self.threadPool = threadPool self.configurations = [:] @@ -72,7 +72,7 @@ public final class Databases { } public func use( - _ driver: DatabaseConfiguration, + _ driver: any DatabaseConfiguration, as id: DatabaseID, isDefault: Bool? = nil ) { @@ -90,7 +90,7 @@ public final class Databases { } } - public func configuration(for id: DatabaseID? = nil) -> DatabaseConfiguration? { + public func configuration(for id: DatabaseID? = nil) -> (any DatabaseConfiguration)? { self.lock.withLock { self.configurations[id ?? self._requireDefaultID()] } @@ -99,10 +99,10 @@ public final class Databases { public func database( _ id: DatabaseID? = nil, logger: Logger, - on eventLoop: EventLoop, + on eventLoop: any EventLoop, history: QueryHistory? = nil, pageSizeLimit: Int? = nil - ) -> Database? { + ) -> (any Database)? { self.lock.withLock { let id = id ?? self._requireDefaultID() var logger = logger @@ -115,7 +115,7 @@ public final class Databases { history: history, pageSizeLimit: pageSizeLimit ) - let driver: DatabaseDriver + let driver: any DatabaseDriver if let existing = self.drivers[id] { driver = existing } else { @@ -150,7 +150,7 @@ public final class Databases { } } - private func _requireConfiguration(for id: DatabaseID) -> DatabaseConfiguration { + private func _requireConfiguration(for id: DatabaseID) -> any DatabaseConfiguration { guard let configuration = self.configurations[id] else { fatalError("No datatabase configuration registered for \(id).") } diff --git a/Sources/FluentKit/Enum/EnumBuilder.swift b/Sources/FluentKit/Enum/EnumBuilder.swift index 292cdb90..c563a601 100644 --- a/Sources/FluentKit/Enum/EnumBuilder.swift +++ b/Sources/FluentKit/Enum/EnumBuilder.swift @@ -8,10 +8,10 @@ extension Database { } public final class EnumBuilder { - let database: Database + let database: any Database public var `enum`: DatabaseEnum - init(database: Database, name: String) { + init(database: any Database, name: String) { self.database = database self.enum = .init(name: name) } diff --git a/Sources/FluentKit/Enum/EnumMetadata.swift b/Sources/FluentKit/Enum/EnumMetadata.swift index f95a3471..190e4016 100644 --- a/Sources/FluentKit/Enum/EnumMetadata.swift +++ b/Sources/FluentKit/Enum/EnumMetadata.swift @@ -4,7 +4,7 @@ import Foundation final class EnumMetadata: Model { static let schema = "_fluent_enums" - static var migration: Migration { + static var migration: any Migration { return EnumMetadataMigration() } @@ -27,7 +27,7 @@ final class EnumMetadata: Model { } private struct EnumMetadataMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("_fluent_enums") .field(.id, .uuid, .identifier(auto: false)) .field("name", .string, .required) @@ -37,7 +37,7 @@ private struct EnumMetadataMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("_fluent_enums").delete() } } diff --git a/Sources/FluentKit/Enum/EnumProperty.swift b/Sources/FluentKit/Enum/EnumProperty.swift index f84b5a83..3e99e5e4 100644 --- a/Sources/FluentKit/Enum/EnumProperty.swift +++ b/Sources/FluentKit/Enum/EnumProperty.swift @@ -71,7 +71,7 @@ extension EnumProperty: QueryableProperty { // MARK: Query-addressable extension EnumProperty: AnyQueryAddressableProperty { - public var anyQueryableProperty: AnyQueryableProperty { self } + public var anyQueryableProperty: any AnyQueryableProperty { self } public var queryablePath: [FieldKey] { self.path } } @@ -86,7 +86,7 @@ extension EnumProperty: AnyDatabaseProperty { self.field.keys } - public func input(to input: DatabaseInput) { + public func input(to input: any DatabaseInput) { let value: DatabaseQuery.Value if !input.wantsUnmodifiedKeys { guard let ivalue = self.field.inputValue else { return } @@ -107,7 +107,7 @@ extension EnumProperty: AnyDatabaseProperty { } } - public func output(from output: DatabaseOutput) throws { + public func output(from output: any DatabaseOutput) throws { try self.field.output(from: output) } } @@ -115,12 +115,12 @@ extension EnumProperty: AnyDatabaseProperty { // MARK: Codable extension EnumProperty: AnyCodableProperty { - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(self.wrappedValue) } - public func decode(from decoder: Decoder) throws { + public func decode(from decoder: any Decoder) throws { let container = try decoder.singleValueContainer() self.value = try container.decode(Value.self) } diff --git a/Sources/FluentKit/Enum/OptionalEnumProperty.swift b/Sources/FluentKit/Enum/OptionalEnumProperty.swift index 4c212a14..9e27141e 100644 --- a/Sources/FluentKit/Enum/OptionalEnumProperty.swift +++ b/Sources/FluentKit/Enum/OptionalEnumProperty.swift @@ -77,7 +77,7 @@ extension OptionalEnumProperty: QueryableProperty { // MARK: Query-addressable extension OptionalEnumProperty: AnyQueryAddressableProperty { - public var anyQueryableProperty: AnyQueryableProperty { self } + public var anyQueryableProperty: any AnyQueryableProperty { self } public var queryablePath: [FieldKey] { self.path } } @@ -92,7 +92,7 @@ extension OptionalEnumProperty: AnyDatabaseProperty { self.field.keys } - public func input(to input: DatabaseInput) { + public func input(to input: any DatabaseInput) { let value: DatabaseQuery.Value if !input.wantsUnmodifiedKeys { guard let ivalue = self.field.inputValue else { return } @@ -116,7 +116,7 @@ extension OptionalEnumProperty: AnyDatabaseProperty { } } - public func output(from output: DatabaseOutput) throws { + public func output(from output: any DatabaseOutput) throws { try self.field.output(from: output) } } @@ -124,12 +124,12 @@ extension OptionalEnumProperty: AnyDatabaseProperty { // MARK: Codable extension OptionalEnumProperty: AnyCodableProperty { - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(self.wrappedValue) } - public func decode(from decoder: Decoder) throws { + public func decode(from decoder: any Decoder) throws { let container = try decoder.singleValueContainer() if container.decodeNil() { self.value = nil diff --git a/Sources/FluentKit/FluentError.swift b/Sources/FluentKit/FluentError.swift index fad72cba..dd3224d1 100644 --- a/Sources/FluentKit/FluentError.swift +++ b/Sources/FluentKit/FluentError.swift @@ -2,7 +2,7 @@ import Foundation public enum FluentError: Error, LocalizedError, CustomStringConvertible, CustomDebugStringConvertible { case idRequired - case invalidField(name: String, valueType: Any.Type, error: Error) + case invalidField(name: String, valueType: Any.Type, error: any Error) case missingField(name: String) case relationNotLoaded(name: String) case missingParent(from: String, to: String, key: String, id: String) diff --git a/Sources/FluentKit/Middleware/ModelMiddleware.swift b/Sources/FluentKit/Middleware/ModelMiddleware.swift index 2e2b72e2..5b4dae27 100644 --- a/Sources/FluentKit/Middleware/ModelMiddleware.swift +++ b/Sources/FluentKit/Middleware/ModelMiddleware.swift @@ -3,24 +3,24 @@ import NIOCore public protocol AnyModelMiddleware { func handle( _ event: ModelEvent, - _ model: AnyModel, - on db: Database, - chainingTo next: AnyModelResponder + _ model: any AnyModel, + on db: any Database, + chainingTo next: any AnyModelResponder ) -> EventLoopFuture } public protocol ModelMiddleware: AnyModelMiddleware { associatedtype Model: FluentKit.Model - func create(model: Model, on db: Database, next: AnyModelResponder) -> EventLoopFuture - func update(model: Model, on db: Database, next: AnyModelResponder) -> EventLoopFuture - func delete(model: Model, force: Bool, on db: Database, next: AnyModelResponder) -> EventLoopFuture - func softDelete(model: Model, on db: Database, next: AnyModelResponder) -> EventLoopFuture - func restore(model: Model, on db: Database, next: AnyModelResponder) -> EventLoopFuture + func create(model: Model, on db: any Database, next: any AnyModelResponder) -> EventLoopFuture + func update(model: Model, on db: any Database, next: any AnyModelResponder) -> EventLoopFuture + func delete(model: Model, force: Bool, on db: any Database, next: any AnyModelResponder) -> EventLoopFuture + func softDelete(model: Model, on db: any Database, next: any AnyModelResponder) -> EventLoopFuture + func restore(model: Model, on db: any Database, next: any AnyModelResponder) -> EventLoopFuture } extension ModelMiddleware { - public func handle(_ event: ModelEvent, _ model: AnyModel, on db: Database, chainingTo next: AnyModelResponder) -> EventLoopFuture { + public func handle(_ event: ModelEvent, _ model: any AnyModel, on db: any Database, chainingTo next: any AnyModelResponder) -> EventLoopFuture { guard let modelType = model as? Model else { return next.handle(event, model, on: db) } @@ -39,36 +39,36 @@ extension ModelMiddleware { } } - public func create(model: Model, on db: Database, next: AnyModelResponder) -> EventLoopFuture { + public func create(model: Model, on db: any Database, next: any AnyModelResponder) -> EventLoopFuture { return next.create(model, on: db) } - public func update(model: Model, on db: Database, next: AnyModelResponder) -> EventLoopFuture { + public func update(model: Model, on db: any Database, next: any AnyModelResponder) -> EventLoopFuture { return next.update(model, on: db) } - public func delete(model: Model, force: Bool, on db: Database, next: AnyModelResponder) -> EventLoopFuture { + public func delete(model: Model, force: Bool, on db: any Database, next: any AnyModelResponder) -> EventLoopFuture { return next.delete(model, force: force, on: db) } - public func softDelete(model: Model, on db: Database, next: AnyModelResponder) -> EventLoopFuture { + public func softDelete(model: Model, on db: any Database, next: any AnyModelResponder) -> EventLoopFuture { return next.softDelete(model, on: db) } - public func restore(model: Model, on db: Database, next: AnyModelResponder) -> EventLoopFuture { + public func restore(model: Model, on db: any Database, next: any AnyModelResponder) -> EventLoopFuture { return next.restore(model, on: db) } } extension AnyModelMiddleware { - func makeResponder(chainingTo responder: AnyModelResponder) -> AnyModelResponder { + func makeResponder(chainingTo responder: any AnyModelResponder) -> any AnyModelResponder { return ModelMiddlewareResponder(middleware: self, responder: responder) } } -extension Array where Element == AnyModelMiddleware { - internal func chainingTo(_ type: Model.Type, closure: @escaping (ModelEvent, Model, Database) throws -> EventLoopFuture) -> AnyModelResponder where Model: FluentKit.Model { - var responder: AnyModelResponder = BasicModelResponder(handle: closure) +extension Array where Element == any AnyModelMiddleware { + internal func chainingTo(_ type: Model.Type, closure: @escaping (ModelEvent, Model, any Database) throws -> EventLoopFuture) -> any AnyModelResponder where Model: FluentKit.Model { + var responder: any AnyModelResponder = BasicModelResponder(handle: closure) for middleware in reversed() { responder = middleware.makeResponder(chainingTo: responder) } @@ -77,10 +77,10 @@ extension Array where Element == AnyModelMiddleware { } private struct ModelMiddlewareResponder: AnyModelResponder { - var middleware: AnyModelMiddleware - var responder: AnyModelResponder + var middleware: any AnyModelMiddleware + var responder: any AnyModelResponder - func handle(_ event: ModelEvent, _ model: AnyModel, on db: Database) -> EventLoopFuture { + func handle(_ event: ModelEvent, _ model: any AnyModel, on db: any Database) -> EventLoopFuture { return self.middleware.handle(event, model, on: db, chainingTo: responder) } } diff --git a/Sources/FluentKit/Middleware/ModelResponder.swift b/Sources/FluentKit/Middleware/ModelResponder.swift index a1368cfb..33fb7352 100644 --- a/Sources/FluentKit/Middleware/ModelResponder.swift +++ b/Sources/FluentKit/Middleware/ModelResponder.swift @@ -3,37 +3,37 @@ import NIOCore public protocol AnyModelResponder { func handle( _ event: ModelEvent, - _ model: AnyModel, - on db: Database + _ model: any AnyModel, + on db: any Database ) -> EventLoopFuture } extension AnyModelResponder { - public func create(_ model: AnyModel, on db: Database) -> EventLoopFuture { + public func create(_ model: any AnyModel, on db: any Database) -> EventLoopFuture { return handle(.create, model, on: db) } - public func update(_ model: AnyModel, on db: Database) -> EventLoopFuture { + public func update(_ model: any AnyModel, on db: any Database) -> EventLoopFuture { return handle(.update, model, on: db) } - public func restore(_ model: AnyModel, on db: Database) -> EventLoopFuture { + public func restore(_ model: any AnyModel, on db: any Database) -> EventLoopFuture { return handle(.restore, model, on: db) } - public func softDelete(_ model: AnyModel, on db: Database) -> EventLoopFuture { + public func softDelete(_ model: any AnyModel, on db: any Database) -> EventLoopFuture { return handle(.softDelete, model, on: db) } - public func delete(_ model: AnyModel, force: Bool, on db: Database) -> EventLoopFuture { + public func delete(_ model: any AnyModel, force: Bool, on db: any Database) -> EventLoopFuture { return handle(.delete(force), model, on: db) } } internal struct BasicModelResponder: AnyModelResponder where Model: FluentKit.Model { - private let _handle: (ModelEvent, Model, Database) throws -> EventLoopFuture + private let _handle: (ModelEvent, Model, any Database) throws -> EventLoopFuture - internal func handle(_ event: ModelEvent, _ model: AnyModel, on db: Database) -> EventLoopFuture { + internal func handle(_ event: ModelEvent, _ model: any AnyModel, on db: any Database) -> EventLoopFuture { guard let modelType = model as? Model else { fatalError("Could not convert type AnyModel to \(Model.self)") } @@ -45,7 +45,7 @@ internal struct BasicModelResponder: AnyModelResponder where Model: Fluen } } - init(handle: @escaping (ModelEvent, Model, Database) throws -> EventLoopFuture) { + init(handle: @escaping (ModelEvent, Model, any Database) throws -> EventLoopFuture) { self._handle = handle } } diff --git a/Sources/FluentKit/Migration/Migration.swift b/Sources/FluentKit/Migration/Migration.swift index 73a4dc78..49fc90f9 100644 --- a/Sources/FluentKit/Migration/Migration.swift +++ b/Sources/FluentKit/Migration/Migration.swift @@ -13,13 +13,13 @@ public protocol Migration { /// - database: `Database` to run the migration on, /// - returns: An asynchronous `Void`. - func prepare(on database: Database) -> EventLoopFuture + func prepare(on database: any Database) -> EventLoopFuture /// Called when the changes from a migration are reverted. /// - Parameters: /// - database: `Database` to revert the migration on. /// - returns: An asynchronous `Void`. - func revert(on database: Database) -> EventLoopFuture + func revert(on database: any Database) -> EventLoopFuture } extension Migration { diff --git a/Sources/FluentKit/Migration/MigrationLog.swift b/Sources/FluentKit/Migration/MigrationLog.swift index 84dcda78..b4a884c2 100644 --- a/Sources/FluentKit/Migration/MigrationLog.swift +++ b/Sources/FluentKit/Migration/MigrationLog.swift @@ -5,7 +5,7 @@ import Foundation public final class MigrationLog: Model { public static let schema = "_fluent_migrations" - public static var migration: Migration { + public static var migration: any Migration { return MigrationLogMigration() } @@ -36,7 +36,7 @@ public final class MigrationLog: Model { } private struct MigrationLogMigration: Migration { - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema("_fluent_migrations") .field(.id, .uuid, .identifier(auto: false)) .field("name", .string, .required) @@ -48,7 +48,7 @@ private struct MigrationLogMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema("_fluent_migrations").delete() } } diff --git a/Sources/FluentKit/Migration/Migrations.swift b/Sources/FluentKit/Migration/Migrations.swift index 2f5a452c..cabd8b72 100644 --- a/Sources/FluentKit/Migration/Migrations.swift +++ b/Sources/FluentKit/Migration/Migrations.swift @@ -1,20 +1,20 @@ public final class Migrations { - var storage: [DatabaseID?: [Migration]] + var storage: [DatabaseID?: [any Migration]] public init() { self.storage = [:] } - public func add(_ migration: Migration, to id: DatabaseID? = nil) { + public func add(_ migration: any Migration, to id: DatabaseID? = nil) { self.storage[id, default: []].append(migration) } @inlinable - public func add(_ migrations: Migration..., to id: DatabaseID? = nil) { + public func add(_ migrations: any Migration..., to id: DatabaseID? = nil) { self.add(migrations, to: id) } - public func add(_ migrations: [Migration], to id: DatabaseID? = nil) { + public func add(_ migrations: [any Migration], to id: DatabaseID? = nil) { self.storage[id, default: []].append(contentsOf: migrations) } } diff --git a/Sources/FluentKit/Migration/Migrator.swift b/Sources/FluentKit/Migration/Migrator.swift index c47c586c..87be2968 100644 --- a/Sources/FluentKit/Migration/Migrator.swift +++ b/Sources/FluentKit/Migration/Migrator.swift @@ -4,16 +4,16 @@ import Logging import NIOCore public struct Migrator { - public let databaseFactory: (DatabaseID?) -> (Database) + public let databaseFactory: (DatabaseID?) -> (any Database) public let migrations: Migrations - public let eventLoop: EventLoop + public let eventLoop: any EventLoop public let migrationLogLevel: Logger.Level public init( databases: Databases, migrations: Migrations, logger: Logger, - on eventLoop: EventLoop, + on eventLoop: any EventLoop, migrationLogLevel: Logger.Level = .info ) { self.init( @@ -27,9 +27,9 @@ public struct Migrator { } public init( - databaseFactory: @escaping (DatabaseID?) -> (Database), + databaseFactory: @escaping (DatabaseID?) -> (any Database), migrations: Migrations, - on eventLoop: EventLoop, + on eventLoop: any EventLoop, migrationLogLevel: Logger.Level = .info ) { self.databaseFactory = databaseFactory @@ -66,7 +66,7 @@ public struct Migrator { // MARK: Preview - public func previewPrepareBatch() -> EventLoopFuture<[(Migration, DatabaseID?)]> { + public func previewPrepareBatch() -> EventLoopFuture<[(any Migration, DatabaseID?)]> { return self.migrators() { migrator in return migrator.previewPrepareBatch().and(value: migrator.id) }.map { items in @@ -77,7 +77,7 @@ public struct Migrator { } } - public func previewRevertLastBatch() -> EventLoopFuture<[(Migration, DatabaseID?)]> { + public func previewRevertLastBatch() -> EventLoopFuture<[(any Migration, DatabaseID?)]> { return self.migrators() { migrator in return migrator.previewRevertLastBatch().and(value: migrator.id) }.map { items in @@ -88,7 +88,7 @@ public struct Migrator { } } - public func previewRevertBatch() -> EventLoopFuture<[(Migration, DatabaseID?)]> { + public func previewRevertBatch() -> EventLoopFuture<[(any Migration, DatabaseID?)]> { return self.migrators() { migrator in return migrator.previewPrepareBatch().and(value: migrator.id) }.map { items in @@ -99,7 +99,7 @@ public struct Migrator { } } - public func previewRevertAllBatches() -> EventLoopFuture<[(Migration, DatabaseID?)]> { + public func previewRevertAllBatches() -> EventLoopFuture<[(any Migration, DatabaseID?)]> { return self.migrators() { migrator in return migrator.previewRevertAllBatches().and(value: migrator.id) }.map { items in @@ -121,12 +121,12 @@ public struct Migrator { } private final class DatabaseMigrator { - let migrations: [Migration] - let database: Database + let migrations: [any Migration] + let database: any Database let id: DatabaseID? let migrationLogLevel: Logger.Level - init(id: DatabaseID?, database: Database, migrations: [Migration], migrationLogLeveL: Logger.Level) { + init(id: DatabaseID?, database: any Database, migrations: [any Migration], migrationLogLeveL: Logger.Level) { self.migrations = migrations self.database = database self.id = id @@ -181,27 +181,27 @@ private final class DatabaseMigrator { // MARK: Preview - func previewPrepareBatch() -> EventLoopFuture<[Migration]> { + func previewPrepareBatch() -> EventLoopFuture<[any Migration]> { return self.unpreparedMigrations() } - func previewRevertLastBatch() -> EventLoopFuture<[Migration]> { + func previewRevertLastBatch() -> EventLoopFuture<[any Migration]> { return self.lastBatchNumber().flatMap { batch in return self.preparedMigrations(batch: batch) } } - func previewRevertBatch(number: Int) -> EventLoopFuture<[Migration]> { + func previewRevertBatch(number: Int) -> EventLoopFuture<[any Migration]> { return self.preparedMigrations(batch: number) } - func previewRevertAllBatches() -> EventLoopFuture<[Migration]> { + func previewRevertAllBatches() -> EventLoopFuture<[any Migration]> { return self.preparedMigrations() } // MARK: Private - private func prepare(_ migration: Migration, batch: Int) -> EventLoopFuture { + private func prepare(_ migration: any Migration, batch: Int) -> EventLoopFuture { self.database.logger.log(level: self.migrationLogLevel, "[Migrator] Starting prepare", metadata: ["migration": .string(migration.name)]) return migration.prepare(on: self.database).flatMap { self.database.logger.log(level: self.migrationLogLevel, "[Migrator] Finished prepare", metadata: ["migration": .string(migration.name)]) @@ -212,7 +212,7 @@ private final class DatabaseMigrator { } } - private func revert(_ migration: Migration) -> EventLoopFuture { + private func revert(_ migration: any Migration) -> EventLoopFuture { self.database.logger.log(level: self.migrationLogLevel, "[Migrator] Starting revert", metadata: ["migration": .string(migration.name)]) return migration.revert(on: self.database).flatMap { self.database.logger.log(level: self.migrationLogLevel, "[Migrator] Finished revert", metadata: ["migration": .string(migration.name)]) @@ -233,7 +233,7 @@ private final class DatabaseMigrator { } } - private func preparedMigrations() -> EventLoopFuture<[Migration]> { + private func preparedMigrations() -> EventLoopFuture<[any Migration]> { return MigrationLog.query(on: self.database).all().map { logs in return self.migrations.filter { migration in return logs.contains(where: { $0.name == migration.name }) @@ -241,7 +241,7 @@ private final class DatabaseMigrator { } } - private func preparedMigrations(batch: Int) -> EventLoopFuture<[Migration]> { + private func preparedMigrations(batch: Int) -> EventLoopFuture<[any Migration]> { return MigrationLog.query(on: self.database).filter(\.$batch == batch).all().map { logs in return self.migrations.filter { migration in return logs.contains(where: { $0.name == migration.name }) @@ -249,7 +249,7 @@ private final class DatabaseMigrator { } } - private func unpreparedMigrations() -> EventLoopFuture<[Migration]> { + private func unpreparedMigrations() -> EventLoopFuture<[any Migration]> { return MigrationLog.query(on: self.database).all().map { logs in return self.migrations.compactMap { migration in if logs.contains(where: { $0.name == migration.name }) { return nil } diff --git a/Sources/FluentKit/Model/AnyModel.swift b/Sources/FluentKit/Model/AnyModel.swift index 454635ab..8369a2c4 100644 --- a/Sources/FluentKit/Model/AnyModel.swift +++ b/Sources/FluentKit/Model/AnyModel.swift @@ -28,14 +28,14 @@ extension AnyModel { return joined } - var anyID: AnyID { + var anyID: any AnyID { for (nameC, child) in _FastChildSequence(subject: self) { /// Match a property named `_id` which conforms to `AnyID`. `as?` is expensive, so check that last. if nameC?[0] == 0x5f/* '_' */, nameC?[1] == 0x69/* 'i' */, nameC?[2] == 0x64/* 'd' */, nameC?[3] == 0x00/* '\0' */, - let idChild = child as? AnyID + let idChild = child as? any AnyID { return idChild } diff --git a/Sources/FluentKit/Model/EagerLoad.swift b/Sources/FluentKit/Model/EagerLoad.swift index 4c0ff36a..1ac3f76c 100644 --- a/Sources/FluentKit/Model/EagerLoad.swift +++ b/Sources/FluentKit/Model/EagerLoad.swift @@ -2,17 +2,17 @@ import NIOCore public protocol EagerLoader: AnyEagerLoader { associatedtype Model: FluentKit.Model - func run(models: [Model], on database: Database) -> EventLoopFuture + func run(models: [Model], on database: any Database) -> EventLoopFuture } extension EagerLoader { - func anyRun(models: [AnyModel], on database: Database) -> EventLoopFuture { + func anyRun(models: [any AnyModel], on database: any Database) -> EventLoopFuture { self.run(models: models.map { $0 as! Model }, on: database) } } public protocol AnyEagerLoader { - func anyRun(models: [AnyModel], on database: Database) -> EventLoopFuture + func anyRun(models: [any AnyModel], on database: any Database) -> EventLoopFuture } public protocol EagerLoadable { diff --git a/Sources/FluentKit/Model/Fields+Codable.swift b/Sources/FluentKit/Model/Fields+Codable.swift index fe1e8686..2695ec6a 100644 --- a/Sources/FluentKit/Model/Fields+Codable.swift +++ b/Sources/FluentKit/Model/Fields+Codable.swift @@ -1,5 +1,5 @@ extension Fields { - public init(from decoder: Decoder) throws { + public init(from decoder: any Decoder) throws { self.init() let container = try decoder.container(keyedBy: SomeCodingKey.self) @@ -22,7 +22,7 @@ extension Fields { } } - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { var container = encoder.container(keyedBy: SomeCodingKey.self) for (key, property) in self.codableProperties where !property.skipPropertyEncoding { diff --git a/Sources/FluentKit/Model/Fields.swift b/Sources/FluentKit/Model/Fields.swift index d36867d2..d8047dc9 100644 --- a/Sources/FluentKit/Model/Fields.swift +++ b/Sources/FluentKit/Model/Fields.swift @@ -22,12 +22,12 @@ public protocol Fields: AnyObject, Codable { /// most severe performance bottleneck in FluentKit by a huge margin. Every access of this property /// carries the same cost; it is not possible to meaningfully cache the results. See /// `MirrorBypass.swift` for a considerable amount of very low-level detail. - var properties: [AnyProperty] { get } + var properties: [any AnyProperty] { get } init() - func input(to input: DatabaseInput) - func output(from output: DatabaseOutput) throws + func input(to input: any DatabaseInput) + func output(from output: any DatabaseOutput) throws } // MARK: Path @@ -67,7 +67,7 @@ extension Fields { /// - Note: It is trivial to construct ``DatabaseInput`` objects which do not in fact actually transfer /// their contents to a database. FluentKit itself does this to implement a save/restore operation for /// model state under certain conditions (see ``Model``). - public func input(to input: DatabaseInput) { + public func input(to input: any DatabaseInput) { for field in self.databaseProperties { field.input(to: input) } @@ -79,7 +79,7 @@ extension Fields { /// /// - Note: It is trivial to construct ``DatabaseOutput`` objects which do not in fact actually represent /// data from a database. FluentKit itself does this to help keep models up to date (see ``Model``). - public func output(from output: DatabaseOutput) throws { + public func output(from output: any DatabaseOutput) throws { for field in self.databaseProperties { try field.output(from: output) } @@ -90,14 +90,14 @@ extension Fields { extension Fields { /// Default implementation of ``Fields/properties-dup4``. - public var properties: [AnyProperty] { - return _FastChildSequence(subject: self).compactMap { $1 as? AnyProperty } + public var properties: [any AnyProperty] { + return _FastChildSequence(subject: self).compactMap { $1 as? any AnyProperty } } /// A wrapper around ``properties`` which returns only the properties which have database keys and can be /// input to and output from a database (corresponding to the ``AnyDatabaseProperty`` protocol). - internal var databaseProperties: [AnyDatabaseProperty] { - self.properties.compactMap { $0 as? AnyDatabaseProperty } + internal var databaseProperties: [any AnyDatabaseProperty] { + self.properties.compactMap { $0 as? any AnyDatabaseProperty } } /// Returns all properties which can be serialized and deserialized independently of a database via the @@ -114,9 +114,9 @@ extension Fields { /// /// - Warning: Like ``properties``, this method uses reflection, and incurs all of the accompanying /// performance penalties. - internal var codableProperties: [SomeCodingKey: AnyCodableProperty] { + internal var codableProperties: [SomeCodingKey: any AnyCodableProperty] { return .init(uniqueKeysWithValues: _FastChildSequence(subject: self).compactMap { - guard let value = $1 as? AnyCodableProperty, + guard let value = $1 as? any AnyCodableProperty, let nameC = $0, nameC[0] != 0, nameC[1] != 0, let name = String(utf8String: nameC + 1) else { diff --git a/Sources/FluentKit/Model/Model+CRUD.swift b/Sources/FluentKit/Model/Model+CRUD.swift index 9f205eba..e4042209 100644 --- a/Sources/FluentKit/Model/Model+CRUD.swift +++ b/Sources/FluentKit/Model/Model+CRUD.swift @@ -2,7 +2,7 @@ import NIOCore import protocol SQLKit.SQLDatabase extension Model { - public func save(on database: Database) -> EventLoopFuture { + public func save(on database: any Database) -> EventLoopFuture { if self._$idExists { return self.update(on: database) } else { @@ -10,20 +10,20 @@ extension Model { } } - public func create(on database: Database) -> EventLoopFuture { + public func create(on database: any Database) -> EventLoopFuture { return database.configuration.middleware.chainingTo(Self.self) { event, model, db in try model.handle(event, on: db) }.handle(.create, self, on: database) } - private func _create(on database: Database) -> EventLoopFuture { + private func _create(on database: any Database) -> EventLoopFuture { precondition(!self._$idExists) self.touchTimestamps(.create, .update) - if self.anyID is AnyQueryableProperty { + if self.anyID is any AnyQueryableProperty { self.anyID.generate() - let promise = database.eventLoop.makePromise(of: DatabaseOutput.self) + let promise = database.eventLoop.makePromise(of: (any DatabaseOutput).self) Self.query(on: database) - .set(self.collectInput(withDefaultedValues: database is SQLDatabase)) + .set(self.collectInput(withDefaultedValues: database is any SQLDatabase)) .action(.create) .run { promise.succeed($0) } .cascadeFailure(to: promise) @@ -37,7 +37,7 @@ extension Model { } } else { return Self.query(on: database) - .set(self.collectInput(withDefaultedValues: database is SQLDatabase)) + .set(self.collectInput(withDefaultedValues: database is any SQLDatabase)) .action(.create) .run() .flatMapThrowing { @@ -46,13 +46,13 @@ extension Model { } } - public func update(on database: Database) -> EventLoopFuture { + public func update(on database: any Database) -> EventLoopFuture { return database.configuration.middleware.chainingTo(Self.self) { event, model, db in try model.handle(event, on: db) }.handle(.update, self, on: database) } - private func _update(on database: Database) throws -> EventLoopFuture { + private func _update(on database: any Database) throws -> EventLoopFuture { precondition(self._$idExists) guard self.hasChanges else { return database.eventLoop.makeSucceededFuture(()) @@ -70,7 +70,7 @@ extension Model { } } - public func delete(force: Bool = false, on database: Database) -> EventLoopFuture { + public func delete(force: Bool = false, on database: any Database) -> EventLoopFuture { if !force, let timestamp = self.deletedTimestamp { timestamp.touch() return database.configuration.middleware.chainingTo(Self.self) { event, model, db in @@ -83,7 +83,7 @@ extension Model { } } - private func _delete(force: Bool = false, on database: Database) throws -> EventLoopFuture { + private func _delete(force: Bool = false, on database: any Database) throws -> EventLoopFuture { guard let id = self.id else { throw FluentError.idRequired } return Self.query(on: database) .filter(id: id) @@ -96,13 +96,13 @@ extension Model { } } - public func restore(on database: Database) -> EventLoopFuture { + public func restore(on database: any Database) -> EventLoopFuture { return database.configuration.middleware.chainingTo(Self.self) { event, model, db in try model.handle(event, on: db) }.handle(.restore, self, on: database) } - private func _restore(on database: Database) throws -> EventLoopFuture { + private func _restore(on database: any Database) throws -> EventLoopFuture { guard let timestamp = self.timestamps.filter({ $0.trigger == .delete }).first else { fatalError("no delete timestamp on this model") } @@ -122,7 +122,7 @@ extension Model { } } - private func handle(_ event: ModelEvent, on db: Database) throws -> EventLoopFuture { + private func handle(_ event: ModelEvent, on db: any Database) throws -> EventLoopFuture { switch event { case .create: return _create(on: db) @@ -139,7 +139,7 @@ extension Model { } extension Collection where Element: FluentKit.Model { - public func delete(force: Bool = false, on database: Database) -> EventLoopFuture { + public func delete(force: Bool = false, on database: any Database) -> EventLoopFuture { guard !self.isEmpty else { return database.eventLoop.makeSucceededFuture(()) } @@ -163,7 +163,7 @@ extension Collection where Element: FluentKit.Model { } } - public func create(on database: Database) -> EventLoopFuture { + public func create(on database: any Database) -> EventLoopFuture { guard !self.isEmpty else { return database.eventLoop.makeSucceededFuture(()) } @@ -172,7 +172,7 @@ extension Collection where Element: FluentKit.Model { return EventLoopFuture.andAllSucceed(self.enumerated().map { idx, model in database.configuration.middleware.chainingTo(Element.self) { event, model, db in - if model.anyID is AnyQueryableProperty { + if model.anyID is any AnyQueryableProperty { model._$id.generate() } model.touchTimestamps(.create, .update) @@ -180,7 +180,7 @@ extension Collection where Element: FluentKit.Model { }.create(model, on: database) }, on: database.eventLoop).flatMap { Element.query(on: database) - .set(self.map { $0.collectInput(withDefaultedValues: database is SQLDatabase) }) + .set(self.map { $0.collectInput(withDefaultedValues: database is any SQLDatabase) }) .create() }.map { for model in self { @@ -206,7 +206,7 @@ private struct SavedInput: DatabaseOutput { self.input = input } - func schema(_ schema: String) -> DatabaseOutput { + func schema(_ schema: String) -> any DatabaseOutput { return self } @@ -214,7 +214,7 @@ private struct SavedInput: DatabaseOutput { self.input[key] != nil } - func nested(_ key: FieldKey) throws -> DatabaseOutput { + func nested(_ key: FieldKey) throws -> any DatabaseOutput { guard let data = self.input[key] else { throw FluentError.missingField(name: key.description) } diff --git a/Sources/FluentKit/Model/Model.swift b/Sources/FluentKit/Model/Model.swift index 754b18df..bcfeae2f 100644 --- a/Sources/FluentKit/Model/Model.swift +++ b/Sources/FluentKit/Model/Model.swift @@ -6,13 +6,13 @@ public protocol Model: AnyModel { } extension Model { - public static func query(on database: Database) -> QueryBuilder { + public static func query(on database: any Database) -> QueryBuilder { .init(database: database) } public static func find( _ id: Self.IDValue?, - on database: Database + on database: any Database ) -> EventLoopFuture { guard let id = id else { return database.eventLoop.makeSucceededFuture(nil) diff --git a/Sources/FluentKit/Model/ModelAlias.swift b/Sources/FluentKit/Model/ModelAlias.swift index d1866fde..8efcedc0 100644 --- a/Sources/FluentKit/Model/ModelAlias.swift +++ b/Sources/FluentKit/Model/ModelAlias.swift @@ -133,7 +133,7 @@ extension ModelAlias { /// values (i.e. instances of ``AliasedField``) to correctly behave as the properties they provide /// automatic access to. Without this override, the "parent" implementation would always return an empty /// array, as the alias type does not itself make direct use of any of the property wrapper types. - public var properties: [AnyProperty] { self.model.properties } + public var properties: [any AnyProperty] { self.model.properties } } /// Provides support for `@dynamicMemberLookup` to continue descending through arbitrary @@ -185,7 +185,7 @@ extension AliasedField: QueryableProperty where Field: QueryableProperty { /// Conditionally forwarded ``AnyQueryAddressableProperty`` conformance for ``AliasedField``. extension AliasedField: AnyQueryAddressableProperty where Field: AnyQueryAddressableProperty { public var queryablePath: [FieldKey] { self.field.queryablePath } - public var anyQueryableProperty: AnyQueryableProperty { self.field.anyQueryableProperty } + public var anyQueryableProperty: any AnyQueryableProperty { self.field.anyQueryableProperty } } /// Conditionally forwarded ``QueryAddressableProperty`` conformance for ``AliasedField``. diff --git a/Sources/FluentKit/Properties/Boolean.swift b/Sources/FluentKit/Properties/Boolean.swift index d6df05dc..2f99e097 100644 --- a/Sources/FluentKit/Properties/Boolean.swift +++ b/Sources/FluentKit/Properties/Boolean.swift @@ -102,7 +102,7 @@ extension BooleanProperty: QueryableProperty { } extension BooleanProperty: AnyQueryAddressableProperty { - public var anyQueryableProperty: AnyQueryableProperty { self } + public var anyQueryableProperty: any AnyQueryableProperty { self } public var queryablePath: [FieldKey] { self.path } } @@ -112,17 +112,17 @@ extension BooleanProperty: QueryAddressableProperty { extension BooleanProperty: AnyDatabaseProperty { public var keys: [FieldKey] { self.$field.keys } - public func input(to input: DatabaseInput) { self.$field.input(to: input) } - public func output(from output: DatabaseOutput) throws { try self.$field.output(from: output) } + public func input(to input: any DatabaseInput) { self.$field.input(to: input) } + public func output(from output: any DatabaseOutput) throws { try self.$field.output(from: output) } } extension BooleanProperty: AnyCodableProperty { - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(self.wrappedValue) } - public func decode(from decoder: Decoder) throws { + public func decode(from decoder: any Decoder) throws { let container = try decoder.singleValueContainer() self.value = try container.decode(Value.self) } diff --git a/Sources/FluentKit/Properties/Children.swift b/Sources/FluentKit/Properties/Children.swift index 58fb0df1..e7ebac9e 100644 --- a/Sources/FluentKit/Properties/Children.swift +++ b/Sources/FluentKit/Properties/Children.swift @@ -51,7 +51,7 @@ public final class ChildrenProperty set { self.idValue = newValue } } - public func query(on database: Database) -> QueryBuilder { + public func query(on database: any Database) -> QueryBuilder { guard let id = self.idValue else { fatalError("Cannot query children relation \(self.name) from unsaved model.") } @@ -65,7 +65,7 @@ public final class ChildrenProperty return builder } - public func create(_ to: [To], on database: Database) -> EventLoopFuture { + public func create(_ to: [To], on database: any Database) -> EventLoopFuture { guard let id = self.idValue else { fatalError("Cannot save child in relation \(self.name) to unsaved model.") } @@ -80,7 +80,7 @@ public final class ChildrenProperty return to.create(on: database) } - public func create(_ to: To, on database: Database) -> EventLoopFuture { + public func create(_ to: To, on database: any Database) -> EventLoopFuture { guard let id = self.idValue else { fatalError("Cannot save child in relation \(self.name) to unsaved model.") } @@ -116,11 +116,11 @@ extension ChildrenProperty: AnyDatabaseProperty { [] } - public func input(to input: DatabaseInput) { + public func input(to input: any DatabaseInput) { // children never has input } - public func output(from output: DatabaseOutput) throws { + public func output(from output: any DatabaseOutput) throws { let key = From()._$id.field.key if output.contains(key) { self.idValue = try output.decode(key, as: From.IDValue.self) @@ -131,14 +131,14 @@ extension ChildrenProperty: AnyDatabaseProperty { // MARK: Codable extension ChildrenProperty: AnyCodableProperty { - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { if let rows = self.value { var container = encoder.singleValueContainer() try container.encode(rows) } } - public func decode(from decoder: Decoder) throws { + public func decode(from decoder: any Decoder) throws { // don't decode } @@ -154,7 +154,7 @@ extension ChildrenProperty: Relation { "Children<\(From.self), \(To.self)>(for: \(self.parentKey))" } - public func load(on database: Database) -> EventLoopFuture { + public func load(on database: any Database) -> EventLoopFuture { self.query(on: database).all().map { self.value = $0 } @@ -206,7 +206,7 @@ private struct ChildrenEagerLoader: EagerLoader let relationKey: KeyPath> let withDeleted: Bool - func run(models: [From], on database: Database) -> EventLoopFuture { + func run(models: [From], on database: any Database) -> EventLoopFuture { let ids = models.map { $0.id! } let builder = To.query(on: database) @@ -242,7 +242,7 @@ private struct ThroughChildrenEagerLoader: EagerLoader let relationKey: KeyPath> let loader: Loader - func run(models: [From], on database: Database) -> EventLoopFuture { + func run(models: [From], on database: any Database) -> EventLoopFuture { let throughs = models.flatMap { $0[keyPath: self.relationKey].value! } diff --git a/Sources/FluentKit/Properties/CompositeChildren.swift b/Sources/FluentKit/Properties/CompositeChildren.swift index 7a606ad7..94925c7e 100644 --- a/Sources/FluentKit/Properties/CompositeChildren.swift +++ b/Sources/FluentKit/Properties/CompositeChildren.swift @@ -110,7 +110,7 @@ public final class CompositeChildrenProperty set { self.idValue = newValue } } - public func query(on database: Database) -> QueryBuilder { + public func query(on database: any Database) -> QueryBuilder { guard let id = self.idValue else { fatalError("Cannot query children relation \(self.name) from unsaved model.") } @@ -137,8 +137,8 @@ extension CompositeChildrenProperty: Property { extension CompositeChildrenProperty: AnyDatabaseProperty { public var keys: [FieldKey] { [] } - public func input(to input: DatabaseInput) {} - public func output(from output: DatabaseOutput) throws { + public func input(to input: any DatabaseInput) {} + public func output(from output: any DatabaseOutput) throws { if From.IDValue.keys.reduce(true, { $0 && output.contains($1) }) { // don't output unless all keys are present self.idValue = From.IDValue() try self.idValue!.output(from: output) @@ -147,19 +147,19 @@ extension CompositeChildrenProperty: AnyDatabaseProperty { } extension CompositeChildrenProperty: AnyCodableProperty { - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { if let value = self.value { var container = encoder.singleValueContainer() try container.encode(value) } } - public func decode(from decoder: Decoder) throws {} + public func decode(from decoder: any Decoder) throws {} public var skipPropertyEncoding: Bool { self.value == nil } } extension CompositeChildrenProperty: Relation { public var name: String { "CompositeChildren<\(From.self), \(To.self)>(for: \(self.parentKey))" } - public func load(on database: Database) -> EventLoopFuture { self.query(on: database).all().map { self.value = $0 } } + public func load(on database: any Database) -> EventLoopFuture { self.query(on: database).all().map { self.value = $0 } } } extension CompositeChildrenProperty: EagerLoadable { @@ -191,7 +191,7 @@ private struct CompositeChildrenEagerLoader: EagerLoader let relationKey: KeyPath> let withDeleted: Bool - func run(models: [From], on database: Database) -> EventLoopFuture { + func run(models: [From], on database: any Database) -> EventLoopFuture { let ids = Set(models.map(\.id!)) let parentKey = From()[keyPath: self.relationKey].parentKey let builder = To.query(on: database) @@ -216,7 +216,7 @@ private struct ThroughCompositeChildrenEagerLoader: Eager let relationKey: KeyPath> let loader: Loader - func run(models: [From], on database: Database) -> EventLoopFuture { + func run(models: [From], on database: any Database) -> EventLoopFuture { return self.loader.run(models: models.flatMap { $0[keyPath: self.relationKey].value! }, on: database) } } diff --git a/Sources/FluentKit/Properties/CompositeID.swift b/Sources/FluentKit/Properties/CompositeID.swift index ff99e5f1..cbd42bb6 100644 --- a/Sources/FluentKit/Properties/CompositeID.swift +++ b/Sources/FluentKit/Properties/CompositeID.swift @@ -11,7 +11,7 @@ public final class CompositeIDProperty { public var value: Value? public var exists: Bool - var cachedOutput: DatabaseOutput? + var cachedOutput: (any DatabaseOutput)? public var projectedValue: CompositeIDProperty { self } @@ -52,11 +52,11 @@ extension CompositeIDProperty: AnyDatabaseProperty { Value.keys } - public func input(to input: DatabaseInput) { + public func input(to input: any DatabaseInput) { self.value!.input(to: input) } - public func output(from output: DatabaseOutput) throws { + public func output(from output: any DatabaseOutput) throws { self.exists = true self.cachedOutput = output try self.value!.output(from: output) @@ -66,12 +66,12 @@ extension CompositeIDProperty: AnyDatabaseProperty { // MARK: Codable extension CompositeIDProperty: AnyCodableProperty { - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(self.value) } - public func decode(from decoder: Decoder) throws { + public func decode(from decoder: any Decoder) throws { let container = try decoder.singleValueContainer() self.value = try container.decode(Value?.self) } diff --git a/Sources/FluentKit/Properties/CompositeOptionalChild.swift b/Sources/FluentKit/Properties/CompositeOptionalChild.swift index 34c37ab8..bbd320e1 100644 --- a/Sources/FluentKit/Properties/CompositeOptionalChild.swift +++ b/Sources/FluentKit/Properties/CompositeOptionalChild.swift @@ -95,7 +95,7 @@ public final class CompositeOptionalChildProperty set { self.idValue = newValue } } - public func query(on database: Database) -> QueryBuilder { + public func query(on database:any Database) -> QueryBuilder { guard let id = self.idValue else { fatalError("Cannot query child relation \(self.name) from unsaved model.") } @@ -122,8 +122,8 @@ extension CompositeOptionalChildProperty: Property { extension CompositeOptionalChildProperty: AnyDatabaseProperty { public var keys: [FieldKey] { [] } - public func input(to input: DatabaseInput) {} - public func output(from output: DatabaseOutput) throws { + public func input(to input: any DatabaseInput) {} + public func output(from output: any DatabaseOutput) throws { if From.IDValue.keys.reduce(true, { $0 && output.contains($1) }) { // don't output unless all keys are present self.idValue = From.IDValue() try self.idValue!.output(from: output) @@ -132,19 +132,19 @@ extension CompositeOptionalChildProperty: AnyDatabaseProperty { } extension CompositeOptionalChildProperty: AnyCodableProperty { - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { if let value = self.value { var container = encoder.singleValueContainer() try container.encode(value) } } - public func decode(from decoder: Decoder) throws {} + public func decode(from decoder: any Decoder) throws {} public var skipPropertyEncoding: Bool { self.value == nil } } extension CompositeOptionalChildProperty: Relation { public var name: String { "CompositeOptionalChild<\(From.self), \(To.self)>(for: \(self.parentKey))" } - public func load(on database: Database) -> EventLoopFuture { self.query(on: database).first().map { self.value = $0 } } + public func load(on database: any Database) -> EventLoopFuture { self.query(on: database).first().map { self.value = $0 } } } extension CompositeOptionalChildProperty: EagerLoadable { @@ -176,7 +176,7 @@ private struct CompositeOptionalChildEagerLoader: EagerLoader let relationKey: KeyPath> let withDeleted: Bool - func run(models: [From], on database: Database) -> EventLoopFuture { + func run(models: [From], on database: any Database) -> EventLoopFuture { let ids = Set(models.map(\.id!)) let parentKey = From()[keyPath: self.relationKey].parentKey let builder = To.query(on: database) @@ -203,7 +203,7 @@ private struct ThroughCompositeOptionalChildEagerLoader: let relationKey: KeyPath> let loader: Loader - func run(models: [From], on database: Database) -> EventLoopFuture { + func run(models: [From], on database: any Database) -> EventLoopFuture { return self.loader.run(models: models.compactMap { $0[keyPath: self.relationKey].value! }, on: database) } } diff --git a/Sources/FluentKit/Properties/CompositeOptionalParent.swift b/Sources/FluentKit/Properties/CompositeOptionalParent.swift index 1c3845e8..e0b0f145 100644 --- a/Sources/FluentKit/Properties/CompositeOptionalParent.swift +++ b/Sources/FluentKit/Properties/CompositeOptionalParent.swift @@ -101,7 +101,7 @@ public final class CompositeOptionalParentProperty self.prefixingStrategy = strategy } - public func query(on database: Database) -> QueryBuilder { + public func query(on database: any Database) -> QueryBuilder { return To.query(on: database).group(.and) { self.id?.input(to: QueryFilterInput(builder: $0)) ?? To.IDValue().input(to: QueryFilterInput(builder: $0).nullValueOveridden()) } @@ -125,7 +125,7 @@ extension CompositeOptionalParentProperty: Relation { "CompositeOptionalParent<\(From.self), \(To.self)>(prefix: \(self.prefix), strategy: \(self.prefixingStrategy))" } - public func load(on database: Database) -> EventLoopFuture { + public func load(on database: any Database) -> EventLoopFuture { self.query(on: database) .first() .map { @@ -148,7 +148,7 @@ extension CompositeOptionalParentProperty: AnyDatabaseProperty { } } - public func input(to input: DatabaseInput) { + public func input(to input: any DatabaseInput) { let prefixedInput = input.prefixed(by: self.prefix, using: self.prefixingStrategy) let id: To.IDValue? @@ -159,7 +159,7 @@ extension CompositeOptionalParentProperty: AnyDatabaseProperty { id?.input(to: prefixedInput) ?? To.IDValue().input(to: prefixedInput.nullValueOveridden()) } - public func output(from output: DatabaseOutput) throws { + public func output(from output: any DatabaseOutput) throws { if self.keys.reduce(true, { $0 && output.contains($1) }) { self.inputId = nil if try self.keys.reduce(true, { try $0 && output.decodeNil($1) }) { @@ -174,7 +174,7 @@ extension CompositeOptionalParentProperty: AnyDatabaseProperty { } extension CompositeOptionalParentProperty: AnyCodableProperty { - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() if case .some(.some(let value)) = self.value { @@ -184,7 +184,7 @@ extension CompositeOptionalParentProperty: AnyCodableProperty { } } - public func decode(from decoder: Decoder) throws { + public func decode(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: SomeCodingKey.self) self.id = try container.decode(To.IDValue?.self, forKey: .init(stringValue: "id")) } @@ -216,7 +216,7 @@ private struct CompositeOptionalParentEagerLoader: EagerLoader let relationKey: KeyPath> let withDeleted: Bool - func run(models: [From], on database: Database) -> EventLoopFuture { + func run(models: [From], on database: any Database) -> EventLoopFuture { var sets = Dictionary(grouping: models, by: { $0[keyPath: self.relationKey].id }) let nilParentModels = sets.removeValue(forKey: nil) ?? [] @@ -249,7 +249,7 @@ private struct ThroughCompositeOptionalParentEagerLoader: let relationKey: KeyPath> let loader: Loader - func run(models: [From], on database: Database) -> EventLoopFuture { + func run(models: [From], on database: any Database) -> EventLoopFuture { self.loader.run(models: models.compactMap { $0[keyPath: self.relationKey].value! }, on: database) } } diff --git a/Sources/FluentKit/Properties/CompositeParent.swift b/Sources/FluentKit/Properties/CompositeParent.swift index f0ebd7f9..646a7231 100644 --- a/Sources/FluentKit/Properties/CompositeParent.swift +++ b/Sources/FluentKit/Properties/CompositeParent.swift @@ -96,7 +96,7 @@ public final class CompositeParentProperty self.prefixingStrategy = strategy } - public func query(on database: Database) -> QueryBuilder { + public func query(on database: any Database) -> QueryBuilder { return To.query(on: database).group(.and) { self.id.input(to: QueryFilterInput(builder: $0)) } } @@ -118,7 +118,7 @@ extension CompositeParentProperty: Relation { "CompositeParent<\(From.self), \(To.self)>(prefix: \(self.prefix), strategy: \(self.prefixingStrategy))" } - public func load(on database: Database) -> EventLoopFuture { + public func load(on database: any Database) -> EventLoopFuture { self.query(on: database) .first() .map { @@ -141,17 +141,17 @@ extension CompositeParentProperty: AnyDatabaseProperty { } } - public func input(to input: DatabaseInput) { + public func input(to input: any DatabaseInput) { self.id.input(to: input.prefixed(by: self.prefix, using: self.prefixingStrategy)) } - public func output(from output: DatabaseOutput) throws { + public func output(from output: any DatabaseOutput) throws { try self.id.output(from: output.prefixed(by: self.prefix, using: self.prefixingStrategy)) } } extension CompositeParentProperty: AnyCodableProperty { - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() if let value = self.value { @@ -161,7 +161,7 @@ extension CompositeParentProperty: AnyCodableProperty { } } - public func decode(from decoder: Decoder) throws { + public func decode(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: SomeCodingKey.self) self.id = try container.decode(To.IDValue.self, forKey: .init(stringValue: "id")) } @@ -193,7 +193,7 @@ private struct CompositeParentEagerLoader: EagerLoader let relationKey: KeyPath> let withDeleted: Bool - func run(models: [From], on database: Database) -> EventLoopFuture { + func run(models: [From], on database: any Database) -> EventLoopFuture { let sets = Dictionary(grouping: models, by: { $0[keyPath: self.relationKey].id }) let builder = To.query(on: database) @@ -229,7 +229,7 @@ private struct ThroughCompositeParentEagerLoader: EagerLo let relationKey: KeyPath> let loader: Loader - func run(models: [From], on database: Database) -> EventLoopFuture { + func run(models: [From], on database: any Database) -> EventLoopFuture { self.loader.run(models: models.map { $0[keyPath: self.relationKey].value! }, on: database) diff --git a/Sources/FluentKit/Properties/Field.swift b/Sources/FluentKit/Properties/Field.swift index ffff2981..a81cc6cd 100644 --- a/Sources/FluentKit/Properties/Field.swift +++ b/Sources/FluentKit/Properties/Field.swift @@ -83,7 +83,7 @@ extension FieldProperty: QueryableProperty { } // MARK: Query-addressable extension FieldProperty: AnyQueryAddressableProperty { - public var anyQueryableProperty: AnyQueryableProperty { self } + public var anyQueryableProperty: any AnyQueryableProperty { self } public var queryablePath: [FieldKey] { self.path } } @@ -98,7 +98,7 @@ extension FieldProperty: AnyDatabaseProperty { [self.key] } - public func input(to input: DatabaseInput) { + public func input(to input: any DatabaseInput) { if input.wantsUnmodifiedKeys { input.set(self.inputValue ?? self.outputValue.map { .bind($0) } ?? .default, at: self.key) } else if let inputValue = self.inputValue { @@ -106,7 +106,7 @@ extension FieldProperty: AnyDatabaseProperty { } } - public func output(from output: DatabaseOutput) throws { + public func output(from output: any DatabaseOutput) throws { if output.contains(self.key) { self.inputValue = nil do { @@ -125,15 +125,15 @@ extension FieldProperty: AnyDatabaseProperty { // MARK: Codable extension FieldProperty: AnyCodableProperty { - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(self.wrappedValue) } - public func decode(from decoder: Decoder) throws { + public func decode(from decoder: any Decoder) throws { let container = try decoder.singleValueContainer() - if let valueType = Value.self as? AnyOptionalType.Type { + if let valueType = Value.self as? any AnyOptionalType.Type { // Hacks for supporting optionals in @Field. // Using @OptionalField is preferred moving forward. if container.decodeNil() { diff --git a/Sources/FluentKit/Properties/Group.swift b/Sources/FluentKit/Properties/Group.swift index 79325034..8183c726 100644 --- a/Sources/FluentKit/Properties/Group.swift +++ b/Sources/FluentKit/Properties/Group.swift @@ -67,11 +67,11 @@ extension GroupProperty: AnyDatabaseProperty { .prefix(self.key, .string("_")) } - public func input(to input: DatabaseInput) { + public func input(to input: any DatabaseInput) { self.value?.input(to: input.prefixed(by: self.prefix)) } - public func output(from output: DatabaseOutput) throws { + public func output(from output: any DatabaseOutput) throws { if self.value == nil { self.value = .init() } try self.value!.output(from: output.prefixed(by: self.prefix)) } @@ -80,11 +80,11 @@ extension GroupProperty: AnyDatabaseProperty { // MARK: + Codable extension GroupProperty: AnyCodableProperty { - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { try self.value?.encode(to: encoder) } - public func decode(from decoder: Decoder) throws { + public func decode(from decoder: any Decoder) throws { let container = try decoder.singleValueContainer() guard !container.decodeNil() else { return } @@ -175,7 +175,7 @@ extension GroupPropertyPath: QueryableProperty extension GroupPropertyPath: AnyQueryAddressableProperty where Property: AnyQueryAddressableProperty { - public var anyQueryableProperty: AnyQueryableProperty { + public var anyQueryableProperty: any AnyQueryableProperty { self.property.anyQueryableProperty } diff --git a/Sources/FluentKit/Properties/ID.swift b/Sources/FluentKit/Properties/ID.swift index 2f02bbaa..6f972956 100644 --- a/Sources/FluentKit/Properties/ID.swift +++ b/Sources/FluentKit/Properties/ID.swift @@ -17,7 +17,7 @@ public final class IDProperty case database static func `default`(for type: T.Type) -> Generator { - if T.self is RandomGeneratable.Type { + if T.self is any RandomGeneratable.Type { return .random } else if T.self == Int.self { return .database @@ -30,7 +30,7 @@ public final class IDProperty public let field: Model.OptionalField public var exists: Bool let generator: Generator - var cachedOutput: DatabaseOutput? + var cachedOutput: (any DatabaseOutput)? public var key: FieldKey { return self.field.key @@ -98,7 +98,7 @@ public final class IDProperty switch self.inputValue { case .none, .null: break - case .bind(let value) where (value as? AnyOptionalType).map({ $0.wrappedValue == nil }) ?? false: + case .bind(let value) where (value as? any AnyOptionalType).map({ $0.wrappedValue == nil }) ?? false: break default: return @@ -109,7 +109,7 @@ public final class IDProperty case .database: self.inputValue = .default case .random: - let generatable = Value.self as! (RandomGeneratable & Encodable).Type + let generatable = Value.self as! any (RandomGeneratable & Encodable).Type self.inputValue = .bind(generatable.generateRandom()) case .user: // do nothing @@ -152,7 +152,7 @@ extension IDProperty: QueryableProperty { } // MARK: Query-addressable extension IDProperty: AnyQueryAddressableProperty { - public var anyQueryableProperty: AnyQueryableProperty { self } + public var anyQueryableProperty: any AnyQueryableProperty { self } public var queryablePath: [FieldKey] { self.path } } @@ -167,11 +167,11 @@ extension IDProperty: AnyDatabaseProperty { self.field.keys } - public func input(to input: DatabaseInput) { + public func input(to input: any DatabaseInput) { self.field.input(to: input) } - public func output(from output: DatabaseOutput) throws { + public func output(from output: any DatabaseOutput) throws { self.exists = true self.cachedOutput = output try self.field.output(from: output) @@ -181,11 +181,11 @@ extension IDProperty: AnyDatabaseProperty { // MARK: Codable extension IDProperty: AnyCodableProperty { - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { try self.field.encode(to: encoder) } - public func decode(from decoder: Decoder) throws { + public func decode(from decoder: any Decoder) throws { try self.field.decode(from: decoder) } } @@ -197,5 +197,5 @@ extension IDProperty: AnyID { } protocol AnyID: AnyObject { func generate() var exists: Bool { get set } - var cachedOutput: DatabaseOutput? { get set } + var cachedOutput: (any DatabaseOutput)? { get set } } diff --git a/Sources/FluentKit/Properties/OptionalBoolean.swift b/Sources/FluentKit/Properties/OptionalBoolean.swift index d779b6fb..512f8ffa 100644 --- a/Sources/FluentKit/Properties/OptionalBoolean.swift +++ b/Sources/FluentKit/Properties/OptionalBoolean.swift @@ -114,7 +114,7 @@ extension OptionalBooleanProperty: QueryableProperty { } extension OptionalBooleanProperty: AnyQueryAddressableProperty { - public var anyQueryableProperty: AnyQueryableProperty { self } + public var anyQueryableProperty: any AnyQueryableProperty { self } public var queryablePath: [FieldKey] { self.path } } @@ -124,17 +124,17 @@ extension OptionalBooleanProperty: QueryAddressableProperty { extension OptionalBooleanProperty: AnyDatabaseProperty { public var keys: [FieldKey] { self.$field.keys } - public func input(to input: DatabaseInput) { self.$field.input(to: input) } - public func output(from output: DatabaseOutput) throws { try self.$field.output(from: output) } + public func input(to input: any DatabaseInput) { self.$field.input(to: input) } + public func output(from output: any DatabaseOutput) throws { try self.$field.output(from: output) } } extension OptionalBooleanProperty: AnyCodableProperty { - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(self.wrappedValue) } - public func decode(from decoder: Decoder) throws { + public func decode(from decoder: any Decoder) throws { let container = try decoder.singleValueContainer() if container.decodeNil() { self.value = nil diff --git a/Sources/FluentKit/Properties/OptionalChild.swift b/Sources/FluentKit/Properties/OptionalChild.swift index c9c2ee5a..817eb6fc 100644 --- a/Sources/FluentKit/Properties/OptionalChild.swift +++ b/Sources/FluentKit/Properties/OptionalChild.swift @@ -51,7 +51,7 @@ public final class OptionalChildProperty set { self.idValue = newValue } } - public func query(on database: Database) -> QueryBuilder { + public func query(on database: any Database) -> QueryBuilder { guard let id = self.idValue else { fatalError("Cannot query child relation \(self.name) from unsaved model.") } @@ -65,7 +65,7 @@ public final class OptionalChildProperty return builder } - public func create(_ to: To, on database: Database) -> EventLoopFuture { + public func create(_ to: To, on database: any Database) -> EventLoopFuture { guard let id = self.idValue else { fatalError("Cannot save child in \(self.name) to unsaved model in.") } @@ -101,11 +101,11 @@ extension OptionalChildProperty: AnyDatabaseProperty { [] } - public func input(to input: DatabaseInput) { + public func input(to input: any DatabaseInput) { // child never has input } - public func output(from output: DatabaseOutput) throws { + public func output(from output: any DatabaseOutput) throws { let key = From()._$id.field.key if output.contains(key) { self.idValue = try output.decode(key, as: From.IDValue.self) @@ -116,14 +116,14 @@ extension OptionalChildProperty: AnyDatabaseProperty { // MARK: Codable extension OptionalChildProperty: AnyCodableProperty { - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { if let child = self.value { var container = encoder.singleValueContainer() try container.encode(child) } } - public func decode(from decoder: Decoder) throws { + public func decode(from decoder: any Decoder) throws { // don't decode } @@ -139,7 +139,7 @@ extension OptionalChildProperty: Relation { "Child<\(From.self), \(To.self)>(for: \(self.parentKey))" } - public func load(on database: Database) -> EventLoopFuture { + public func load(on database: any Database) -> EventLoopFuture { self.query(on: database).first().map { self.value = $0 } @@ -191,7 +191,7 @@ private struct OptionalChildEagerLoader: EagerLoader let relationKey: KeyPath> let withDeleted: Bool - func run(models: [From], on database: Database) -> EventLoopFuture { + func run(models: [From], on database: any Database) -> EventLoopFuture { let ids = models.compactMap { $0.id! } let builder = To.query(on: database) @@ -228,7 +228,7 @@ private struct ThroughChildEagerLoader: EagerLoader let relationKey: KeyPath> let loader: Loader - func run(models: [From], on database: Database) -> EventLoopFuture { + func run(models: [From], on database: any Database) -> EventLoopFuture { let throughs = models.compactMap { $0[keyPath: self.relationKey].value! } diff --git a/Sources/FluentKit/Properties/OptionalField.swift b/Sources/FluentKit/Properties/OptionalField.swift index 044e84b1..46d9c6ab 100644 --- a/Sources/FluentKit/Properties/OptionalField.swift +++ b/Sources/FluentKit/Properties/OptionalField.swift @@ -82,7 +82,7 @@ extension OptionalFieldProperty: QueryableProperty { } // MARK: Query-addressable extension OptionalFieldProperty: AnyQueryAddressableProperty { - public var anyQueryableProperty: AnyQueryableProperty { self } + public var anyQueryableProperty: any AnyQueryableProperty { self } public var queryablePath: [FieldKey] { self.path } } @@ -97,7 +97,7 @@ extension OptionalFieldProperty: AnyDatabaseProperty { [self.key] } - public func input(to input: DatabaseInput) { + public func input(to input: any DatabaseInput) { if input.wantsUnmodifiedKeys { input.set(self.inputValue ?? self.outputValue.map { $0.map { .bind($0) } ?? .null } ?? .default, at: self.key) } else if let inputValue = self.inputValue { @@ -105,7 +105,7 @@ extension OptionalFieldProperty: AnyDatabaseProperty { } } - public func output(from output: DatabaseOutput) throws { + public func output(from output: any DatabaseOutput) throws { if output.contains(self.key) { self.inputValue = nil do { @@ -128,12 +128,12 @@ extension OptionalFieldProperty: AnyDatabaseProperty { // MARK: Codable extension OptionalFieldProperty: AnyCodableProperty { - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(self.wrappedValue) } - public func decode(from decoder: Decoder) throws { + public func decode(from decoder: any Decoder) throws { let container = try decoder.singleValueContainer() if container.decodeNil() { self.value = nil diff --git a/Sources/FluentKit/Properties/OptionalParent.swift b/Sources/FluentKit/Properties/OptionalParent.swift index aa28d3c8..554a3e1f 100644 --- a/Sources/FluentKit/Properties/OptionalParent.swift +++ b/Sources/FluentKit/Properties/OptionalParent.swift @@ -30,14 +30,14 @@ public final class OptionalParentProperty public var value: To?? public init(key: FieldKey) { - guard !(To.IDValue.self is Fields.Type) else { + guard !(To.IDValue.self is any Fields.Type) else { fatalError("Can not use @OptionalParent to target a model with composite ID; use @CompositeOptionalParent instead.") } self._id = .init(key: key) } - public func query(on database: Database) -> QueryBuilder { + public func query(on database: any Database) -> QueryBuilder { let builder = To.query(on: database) if let id = self.id { builder.filter(\._$id == id) @@ -61,7 +61,7 @@ extension OptionalParentProperty: Relation { "OptionalParent<\(From.self), \(To.self)>(key: \(self.$id.key))" } - public func load(on database: Database) -> EventLoopFuture { + public func load(on database: any Database) -> EventLoopFuture { self.query(on: database).first().map { self.value = $0 } @@ -80,7 +80,7 @@ extension OptionalParentProperty: Property { // MARK: Query-addressable extension OptionalParentProperty: AnyQueryAddressableProperty { - public var anyQueryableProperty: AnyQueryableProperty { self.$id.anyQueryableProperty } + public var anyQueryableProperty: any AnyQueryableProperty { self.$id.anyQueryableProperty } public var queryablePath: [FieldKey] { self.$id.queryablePath } } @@ -95,11 +95,11 @@ extension OptionalParentProperty: AnyDatabaseProperty { self.$id.keys } - public func input(to input: DatabaseInput) { + public func input(to input: any DatabaseInput) { self.$id.input(to: input) } - public func output(from output: DatabaseOutput) throws { + public func output(from output: any DatabaseOutput) throws { try self.$id.output(from: output) } } @@ -107,7 +107,7 @@ extension OptionalParentProperty: AnyDatabaseProperty { // MARK: Codable extension OptionalParentProperty: AnyCodableProperty { - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() if case .some(.some(let parent)) = self.value { // require truly non-nil so we don't mis-encode when value has been manually cleared try container.encode(parent) @@ -118,7 +118,7 @@ extension OptionalParentProperty: AnyCodableProperty { } } - public func decode(from decoder: Decoder) throws { + public func decode(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: SomeCodingKey.self) try self.$id.decode(from: container.superDecoder(forKey: .init(stringValue: "id"))) } @@ -169,7 +169,7 @@ private struct OptionalParentEagerLoader: EagerLoader let relationKey: KeyPath> let withDeleted: Bool - func run(models: [From], on database: Database) -> EventLoopFuture { + func run(models: [From], on database: any Database) -> EventLoopFuture { var sets = Dictionary(grouping: models, by: { $0[keyPath: self.relationKey].id }) let nilParentModels = sets.removeValue(forKey: nil) ?? [] @@ -207,7 +207,7 @@ private struct ThroughOptionalParentEagerLoader: EagerLoa let relationKey: KeyPath> let loader: Loader - func run(models: [From], on database: Database) -> EventLoopFuture { + func run(models: [From], on database: any Database) -> EventLoopFuture { let throughs = models.compactMap { $0[keyPath: self.relationKey].value! } diff --git a/Sources/FluentKit/Properties/Parent.swift b/Sources/FluentKit/Properties/Parent.swift index 9c9922fe..b2d5b3ec 100644 --- a/Sources/FluentKit/Properties/Parent.swift +++ b/Sources/FluentKit/Properties/Parent.swift @@ -31,14 +31,14 @@ public final class ParentProperty public var value: To? public init(key: FieldKey) { - guard !(To.IDValue.self is Fields.Type) else { + guard !(To.IDValue.self is any Fields.Type) else { fatalError("Can not use @Parent to target a model with composite ID; use @CompositeParent instead.") } self._id = .init(key: key) } - public func query(on database: Database) -> QueryBuilder { + public func query(on database: any Database) -> QueryBuilder { return To.query(on: database) .filter(\._$id == self.id) } @@ -57,7 +57,7 @@ extension ParentProperty: Relation { "Parent<\(From.self), \(To.self)>(key: \(self.$id.key))" } - public func load(on database: Database) -> EventLoopFuture { + public func load(on database: any Database) -> EventLoopFuture { self.query(on: database).first().map { self.value = $0 } @@ -76,7 +76,7 @@ extension ParentProperty: Property { // MARK: Query-addressable extension ParentProperty: AnyQueryAddressableProperty { - public var anyQueryableProperty: AnyQueryableProperty { self.$id.anyQueryableProperty } + public var anyQueryableProperty: any AnyQueryableProperty { self.$id.anyQueryableProperty } public var queryablePath: [FieldKey] { self.$id.queryablePath } } @@ -91,17 +91,17 @@ extension ParentProperty: AnyDatabaseProperty { self.$id.keys } - public func input(to input: DatabaseInput) { + public func input(to input: any DatabaseInput) { self.$id.input(to: input) } - public func output(from output: DatabaseOutput) throws { + public func output(from output: any DatabaseOutput) throws { try self.$id.output(from: output) } } extension ParentProperty: AnyCodableProperty { - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() if let parent = self.value { try container.encode(parent) @@ -112,7 +112,7 @@ extension ParentProperty: AnyCodableProperty { } } - public func decode(from decoder: Decoder) throws { + public func decode(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: SomeCodingKey.self) try self.$id.decode(from: container.superDecoder(forKey: .init(stringValue: "id"))) } @@ -163,7 +163,7 @@ private struct ParentEagerLoader: EagerLoader let relationKey: KeyPath> let withDeleted: Bool - func run(models: [From], on database: Database) -> EventLoopFuture { + func run(models: [From], on database: any Database) -> EventLoopFuture { let sets = Dictionary(grouping: models, by: { $0[keyPath: self.relationKey].id }) let builder = To.query(on: database).filter(\._$id ~~ Set(sets.keys)) if (self.withDeleted) { @@ -192,7 +192,7 @@ private struct ThroughParentEagerLoader: EagerLoader let relationKey: KeyPath> let loader: Loader - func run(models: [From], on database: Database) -> EventLoopFuture { + func run(models: [From], on database: any Database) -> EventLoopFuture { let throughs = models.map { $0[keyPath: self.relationKey].value! } diff --git a/Sources/FluentKit/Properties/Property.swift b/Sources/FluentKit/Properties/Property.swift index 31bbb81e..a87f00ef 100644 --- a/Sources/FluentKit/Properties/Property.swift +++ b/Sources/FluentKit/Properties/Property.swift @@ -48,8 +48,8 @@ extension AnyProperty where Self: Property { /// effectively complete. They should not be considered actual "database" properties. public protocol AnyDatabaseProperty: AnyProperty { var keys: [FieldKey] { get } - func input(to input: DatabaseInput) - func output(from output: DatabaseOutput) throws + func input(to input: any DatabaseInput) + func output(from output: any DatabaseOutput) throws } /// Marks a property as participating in the ``Fields`` protocol's (defaulted) @@ -67,10 +67,10 @@ public protocol AnyDatabaseProperty: AnyProperty { /// into a way to at least error out rather than crashing. public protocol AnyCodableProperty: AnyProperty { /// Encode the property's data to an external representation. - func encode(to encoder: Encoder) throws + func encode(to encoder: any Encoder) throws /// Decode an external representation and replace the property's current data with the result. - func decode(from decoder: Decoder) throws + func decode(from decoder: any Decoder) throws /// Return `true` to skip encoding of this property. Defaults to `false` unless explicitly /// implemented. @@ -151,7 +151,7 @@ extension QueryableProperty { /// property types whose `Value` is a derivative of or expansion upon an underlying queryable /// property. See the discussion of ``QueryAddressableProperty`` itself for additional details. public protocol AnyQueryAddressableProperty: AnyProperty { - var anyQueryableProperty: AnyQueryableProperty { get } + var anyQueryableProperty: any AnyQueryableProperty { get } var queryablePath: [FieldKey] { get } } diff --git a/Sources/FluentKit/Properties/Relation.swift b/Sources/FluentKit/Properties/Relation.swift index d95e489f..9a6e6e4e 100644 --- a/Sources/FluentKit/Properties/Relation.swift +++ b/Sources/FluentKit/Properties/Relation.swift @@ -9,7 +9,7 @@ public protocol Relation { associatedtype RelatedValue var name: String { get } var value: RelatedValue? { get set } - func load(on database: Database) -> EventLoopFuture + func load(on database: any Database) -> EventLoopFuture } extension Relation { @@ -25,7 +25,7 @@ extension Relation { /// loaded value. /// - database: The database to use if the value needs to be loaded. /// - Returns: The loaded value. - public func get(reload: Bool = false, on database: Database) -> EventLoopFuture { + public func get(reload: Bool = false, on database: any Database) -> EventLoopFuture { if let value = self.value, !reload { return database.eventLoop.makeSucceededFuture(value) } else { diff --git a/Sources/FluentKit/Properties/Siblings.swift b/Sources/FluentKit/Properties/Siblings.swift index d00c09f3..7bf8d8a6 100644 --- a/Sources/FluentKit/Properties/Siblings.swift +++ b/Sources/FluentKit/Properties/Siblings.swift @@ -41,7 +41,7 @@ public final class SiblingsProperty from: KeyPath>, to: KeyPath> ) { - guard !(From.IDValue.self is Fields.Type), !(To.IDValue.self is Fields.Type) else { + guard !(From.IDValue.self is any Fields.Type), !(To.IDValue.self is any Fields.Type) else { fatalError("Can not use @Siblings with models which have composite IDs.") } @@ -78,7 +78,7 @@ public final class SiblingsProperty /// - Parameters: /// - to: The model to check whether it is attached through a pivot. /// - database: The database to perform check on. - public func isAttached(to: To, on database: Database) -> EventLoopFuture { + public func isAttached(to: To, on database: any Database) -> EventLoopFuture { guard let toID = to.id else { return database.eventLoop.makeFailedFuture(SiblingsPropertyError.operandModelIdRequired(property: self.name)) } @@ -91,7 +91,7 @@ public final class SiblingsProperty /// - Parameters: /// - toID: The ID of the model to check whether it is attached through a pivot. /// - database: The database to perform the check on. - public func isAttached(toID: To.IDValue, on database: Database) -> EventLoopFuture { + public func isAttached(toID: To.IDValue, on database: any Database) -> EventLoopFuture { guard let fromID = self.idValue else { return database.eventLoop.makeFailedFuture(SiblingsPropertyError.owningModelIdRequired(property: self.name)) } @@ -113,7 +113,7 @@ public final class SiblingsProperty /// - edit: An optional closure to edit the pivot model before saving it. public func attach( _ tos: [To], - on database: Database, + on database: any Database, _ edit: (Through) -> () = { _ in } ) -> EventLoopFuture { guard let fromID = self.idValue else { @@ -147,7 +147,7 @@ public final class SiblingsProperty public func attach( _ to: To, method: AttachMethod, - on database: Database, + on database: any Database, _ edit: @escaping (Through) -> () = { _ in } ) -> EventLoopFuture { switch method { @@ -172,7 +172,7 @@ public final class SiblingsProperty /// - edit: An optional closure to edit the pivot model before saving it. public func attach( _ to: To, - on database: Database, + on database: any Database, _ edit: (Through) -> () = { _ in } ) -> EventLoopFuture { guard let fromID = self.idValue else { @@ -195,7 +195,7 @@ public final class SiblingsProperty /// - Parameters: /// - tos: An array of models to detach from this model. /// - database: The database to perform the attachment on. - public func detach(_ tos: [To], on database: Database) -> EventLoopFuture { + public func detach(_ tos: [To], on database: any Database) -> EventLoopFuture { guard let fromID = self.idValue else { return database.eventLoop.makeFailedFuture(SiblingsPropertyError.owningModelIdRequired(property: self.name)) } @@ -221,7 +221,7 @@ public final class SiblingsProperty /// - Parameters: /// - to: The model to detach from this model. /// - database: The database to perform the attachment on. - public func detach(_ to: To, on database: Database) -> EventLoopFuture { + public func detach(_ to: To, on database: any Database) -> EventLoopFuture { guard let fromID = self.idValue else { return database.eventLoop.makeFailedFuture(SiblingsPropertyError.owningModelIdRequired(property: self.name)) } @@ -236,7 +236,7 @@ public final class SiblingsProperty } /// Detach all models by deleting all pivots from this model. - public func detachAll(on database: Database) -> EventLoopFuture { + public func detachAll(on database: any Database) -> EventLoopFuture { guard let fromID = self.idValue else { return database.eventLoop.makeFailedFuture(SiblingsPropertyError.owningModelIdRequired(property: self.name)) } @@ -249,7 +249,7 @@ public final class SiblingsProperty // MARK: Query /// Returns a `QueryBuilder` that can be used to query the siblings. - public func query(on database: Database) -> QueryBuilder { + public func query(on database: any Database) -> QueryBuilder { guard let fromID = self.idValue else { // TODO: Get rid of this fatalError() like we got rid of all the others. fatalError("Cannot query siblings relation \(self.name) from unsaved model.") @@ -283,11 +283,11 @@ extension SiblingsProperty: AnyDatabaseProperty { [] } - public func input(to input: DatabaseInput) { + public func input(to input: any DatabaseInput) { // siblings never has input } - public func output(from output: DatabaseOutput) throws { + public func output(from output: any DatabaseOutput) throws { let key = From()._$id.key if output.contains(key) { self.idValue = try output.decode(key, as: From.IDValue.self) @@ -299,14 +299,14 @@ extension SiblingsProperty: AnyDatabaseProperty { // MARK: Codable extension SiblingsProperty: AnyCodableProperty { - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { if let rows = self.value { var container = encoder.singleValueContainer() try container.encode(rows) } } - public func decode(from decoder: Decoder) throws { + public func decode(from decoder: any Decoder) throws { // don't decode } @@ -324,7 +324,7 @@ extension SiblingsProperty: Relation { return "Siblings<\(From.self), \(To.self), \(Through.self)>(from: \(fromKey), to: \(toKey))" } - public func load(on database: Database) -> EventLoopFuture { + public func load(on database: any Database) -> EventLoopFuture { self.query(on: database).all().map { self.value = $0 } @@ -377,7 +377,7 @@ private struct SiblingsEagerLoader: EagerLoader let relationKey: KeyPath> let withDeleted: Bool - func run(models: [From], on database: Database) -> EventLoopFuture { + func run(models: [From], on database: any Database) -> EventLoopFuture { let ids = models.map { $0.id! } let from = From()[keyPath: self.relationKey].from @@ -410,7 +410,7 @@ private struct ThroughSiblingsEagerLoader: EagerLoade let relationKey: KeyPath> let loader: Loader - func run(models: [From], on database: Database) -> EventLoopFuture { + func run(models: [From], on database: any Database) -> EventLoopFuture { let throughs = models.flatMap { $0[keyPath: self.relationKey].value! } diff --git a/Sources/FluentKit/Properties/Timestamp.swift b/Sources/FluentKit/Properties/Timestamp.swift index ec7a0db6..040b01d0 100644 --- a/Sources/FluentKit/Properties/Timestamp.swift +++ b/Sources/FluentKit/Properties/Timestamp.swift @@ -115,7 +115,7 @@ extension TimestampProperty: QueryableProperty { } // MARK: Query-addressable extension TimestampProperty: AnyQueryAddressableProperty { - public var anyQueryableProperty: AnyQueryableProperty { self } + public var anyQueryableProperty: any AnyQueryableProperty { self } public var queryablePath: [FieldKey] { self.path } } @@ -130,11 +130,11 @@ extension TimestampProperty: AnyDatabaseProperty { self.$timestamp.keys } - public func input(to input: DatabaseInput) { + public func input(to input: any DatabaseInput) { self.$timestamp.input(to: input) } - public func output(from output: DatabaseOutput) throws { + public func output(from output: any DatabaseOutput) throws { try self.$timestamp.output(from: output) } } @@ -142,12 +142,12 @@ extension TimestampProperty: AnyDatabaseProperty { // MARK: Codable extension TimestampProperty: AnyCodableProperty { - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(self.wrappedValue) } - public func decode(from decoder: Decoder) throws { + public func decode(from decoder: any Decoder) throws { let container = try decoder.singleValueContainer() if container.decodeNil() { self.value = nil @@ -183,9 +183,9 @@ extension AnyTimestamp { } extension Fields { - var timestamps: [AnyTimestamp] { + var timestamps: [any AnyTimestamp] { self.properties.compactMap { - $0 as? AnyTimestamp + $0 as? any AnyTimestamp } } @@ -202,7 +202,7 @@ extension Fields { } } - var deletedTimestamp: AnyTimestamp? { + var deletedTimestamp: (any AnyTimestamp)? { self.timestamps.filter { $0.trigger == .delete }.first } } diff --git a/Sources/FluentKit/Query/Builder/QueryBuilder+Aggregate.swift b/Sources/FluentKit/Query/Builder/QueryBuilder+Aggregate.swift index 0eb1ed59..a1137ecd 100644 --- a/Sources/FluentKit/Query/Builder/QueryBuilder+Aggregate.swift +++ b/Sources/FluentKit/Query/Builder/QueryBuilder+Aggregate.swift @@ -4,9 +4,9 @@ extension QueryBuilder { // MARK: Aggregate public func count() -> EventLoopFuture { - if Model().anyID is AnyQueryableProperty { + if Model().anyID is any AnyQueryableProperty { return self.count(\._$id) - } else if let fieldsIDType = Model.IDValue.self as? Fields.Type { + } else if let fieldsIDType = Model.IDValue.self as? any Fields.Type { return self.aggregate(.count, fieldsIDType.keys.first!) } else { fatalError("Model '\(Model.self)' has neither @ID nor @CompositeID, this is not valid.") diff --git a/Sources/FluentKit/Query/Builder/QueryBuilder+Filter.swift b/Sources/FluentKit/Query/Builder/QueryBuilder+Filter.swift index 4618dcc0..5e77893b 100644 --- a/Sources/FluentKit/Query/Builder/QueryBuilder+Filter.swift +++ b/Sources/FluentKit/Query/Builder/QueryBuilder+Filter.swift @@ -3,7 +3,7 @@ extension QueryBuilder { @discardableResult internal func filter(id: Model.IDValue) -> Self { - if let fields = id as? Fields { + if let fields = id as? any Fields { return self.group(.and) { fields.input(to: QueryFilterInput(builder: $0)) } } else { return self.filter(\Model._$id == id) @@ -13,8 +13,8 @@ extension QueryBuilder { @discardableResult internal func filter(ids: [Model.IDValue]) -> Self { guard let firstId = ids.first else { return self.limit(0) } - if firstId is Fields { - return self.group(.or) { q in ids.forEach { id in q.group(.and) { (id as! Fields).input(to: QueryFilterInput(builder: $0)) } } } + if firstId is any Fields { + return self.group(.or) { q in ids.forEach { id in q.group(.and) { (id as! any Fields).input(to: QueryFilterInput(builder: $0)) } } } } else { return self.filter(\Model._$id ~~ ids) } diff --git a/Sources/FluentKit/Query/Builder/QueryBuilder+Paginate.swift b/Sources/FluentKit/Query/Builder/QueryBuilder+Paginate.swift index dcc97c48..3a1a2324 100644 --- a/Sources/FluentKit/Query/Builder/QueryBuilder+Paginate.swift +++ b/Sources/FluentKit/Query/Builder/QueryBuilder+Paginate.swift @@ -119,7 +119,7 @@ public struct PageRequest: Decodable { } /// `Decodable` conformance. - public init(from decoder: Decoder) throws { + public init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.page = try container.decodeIfPresent(Int.self, forKey: .page) ?? 1 self.per = try container.decodeIfPresent(Int.self, forKey: .per) ?? 10 diff --git a/Sources/FluentKit/Query/Builder/QueryBuilder.swift b/Sources/FluentKit/Query/Builder/QueryBuilder.swift index 1debee6a..4d3ec652 100644 --- a/Sources/FluentKit/Query/Builder/QueryBuilder.swift +++ b/Sources/FluentKit/Query/Builder/QueryBuilder.swift @@ -6,13 +6,13 @@ public final class QueryBuilder { public var query: DatabaseQuery - public let database: Database + public let database: any Database internal var includeDeleted: Bool internal var shouldForceDelete: Bool - internal var models: [Schema.Type] - public var eagerLoaders: [AnyEagerLoader] + internal var models: [any Schema.Type] + public var eagerLoaders: [any AnyEagerLoader] - public convenience init(database: Database) { + public convenience init(database: any Database) { self.init( query: .init(schema: Model.schema, space: Model.space), database: database, @@ -22,9 +22,9 @@ public final class QueryBuilder private init( query: DatabaseQuery, - database: Database, - models: [Schema.Type] = [], - eagerLoaders: [AnyEagerLoader] = [], + database: any Database, + models: [any Schema.Type] = [], + eagerLoaders: [any AnyEagerLoader] = [], includeDeleted: Bool = false, shouldForceDelete: Bool = false ) { @@ -35,7 +35,7 @@ public final class QueryBuilder self.includeDeleted = includeDeleted self.shouldForceDelete = shouldForceDelete // Pass through custom ID key for database if used. - if Model().anyID is AnyQueryableProperty { + if Model().anyID is any AnyQueryableProperty { switch Model()._$id.key { case .id: break case let other: self.query.customIDKey = other @@ -66,7 +66,7 @@ public final class QueryBuilder return self } - internal func addFields(for model: (Schema & Fields).Type, to query: inout DatabaseQuery) { + internal func addFields(for model: any (Schema & Fields).Type, to query: inout DatabaseQuery) { query.fields += model.keys.map { path in .extendedPath([path], schema: model.schemaOrAlias, space: model.spaceIfNotAliased) } @@ -146,8 +146,8 @@ public final class QueryBuilder // MARK: Fetch - public func chunk(max: Int, closure: @escaping ([Result]) -> ()) -> EventLoopFuture { - var partial: [Result] = [] + public func chunk(max: Int, closure: @escaping ([Result]) -> ()) -> EventLoopFuture { + var partial: [Result] = [] partial.reserveCapacity(max) return self.all { row in partial.append(row) @@ -203,7 +203,7 @@ public final class QueryBuilder } public func all() -> EventLoopFuture<[Model]> { - var models: [Result] = [] + var models: [Result] = [] return self.all { model in models.append(model) }.flatMapThrowing { @@ -216,7 +216,7 @@ public final class QueryBuilder return self.run { _ in } } - public func all(_ onOutput: @escaping (Result) -> ()) -> EventLoopFuture { + public func all(_ onOutput: @escaping (Result) -> ()) -> EventLoopFuture { var all: [Model] = [] let done = self.run { output in @@ -251,7 +251,7 @@ public final class QueryBuilder return self } - public func run(_ onOutput: @escaping (DatabaseOutput) -> ()) -> EventLoopFuture { + public func run(_ onOutput: @escaping (any DatabaseOutput) -> ()) -> EventLoopFuture { // make a copy of this query before mutating it // so that run can be called multiple times var query = self.query diff --git a/Sources/FluentKit/Query/Database/DatabaseQuery+Value.swift b/Sources/FluentKit/Query/Database/DatabaseQuery+Value.swift index bd022f0e..f3d0101a 100644 --- a/Sources/FluentKit/Query/Database/DatabaseQuery+Value.swift +++ b/Sources/FluentKit/Query/Database/DatabaseQuery+Value.swift @@ -1,6 +1,6 @@ extension DatabaseQuery { public enum Value { - case bind(Encodable) + case bind(any Encodable) case dictionary([FieldKey: Value]) case array([Value]) case null @@ -14,7 +14,7 @@ extension DatabaseQuery.Value: CustomStringConvertible { public var description: String { switch self { case .bind(let encodable): - if let convertible = encodable as? CustomDebugStringConvertible { + if let convertible = encodable as? any CustomDebugStringConvertible { return convertible.debugDescription } else { return "\(encodable)" diff --git a/Sources/FluentKit/Schema/SchemaBuilder.swift b/Sources/FluentKit/Schema/SchemaBuilder.swift index 06f9fe35..3ed6eb0a 100644 --- a/Sources/FluentKit/Schema/SchemaBuilder.swift +++ b/Sources/FluentKit/Schema/SchemaBuilder.swift @@ -7,10 +7,10 @@ extension Database { import NIOCore public final class SchemaBuilder { - let database: Database + let database: any Database public var schema: DatabaseSchema - init(database: Database, schema: String, space: String? = nil) { + init(database: any Database, schema: String, space: String? = nil) { self.database = database self.schema = .init(schema: schema, space: space) } diff --git a/Sources/FluentSQL/DatabaseQuery+SQL.swift b/Sources/FluentSQL/DatabaseQuery+SQL.swift index da68ffe0..68641592 100644 --- a/Sources/FluentSQL/DatabaseQuery+SQL.swift +++ b/Sources/FluentSQL/DatabaseQuery+SQL.swift @@ -10,7 +10,7 @@ extension DatabaseQuery.Value { .sql(embed) } - public static func sql(_ expression: SQLExpression) -> Self { + public static func sql(_ expression: any SQLExpression) -> Self { .custom(expression) } } @@ -28,7 +28,7 @@ extension DatabaseQuery.Field { .sql(embed) } - public static func sql(_ expression: SQLExpression) -> Self { + public static func sql(_ expression: any SQLExpression) -> Self { .custom(expression) } } @@ -41,7 +41,7 @@ extension DatabaseQuery.Filter { public static func sql( _ left: SQLIdentifier, _ op: SQLBinaryOperator, - _ right: Encodable + _ right: any Encodable ) -> Self { .sql(SQLBinaryExpression(left: left, op: op, right: SQLBind(right))) } @@ -55,9 +55,9 @@ extension DatabaseQuery.Filter { } public static func sql( - _ left: SQLExpression, - _ op: SQLExpression, - _ right: SQLExpression + _ left: any SQLExpression, + _ op: any SQLExpression, + _ right: any SQLExpression ) -> Self { .sql(SQLBinaryExpression(left: left, op: op, right: right)) } @@ -66,7 +66,7 @@ extension DatabaseQuery.Filter { .sql(embed) } - public static func sql(_ expression: SQLExpression) -> Self { + public static func sql(_ expression: any SQLExpression) -> Self { .custom(expression) } } @@ -80,7 +80,7 @@ extension DatabaseQuery.Join { .sql(embed) } - public static func sql(_ expression: SQLExpression) -> Self { + public static func sql(_ expression: any SQLExpression) -> Self { .custom(expression) } } @@ -93,7 +93,7 @@ extension DatabaseQuery.Sort { public static func sql( _ left: SQLIdentifier, _ op: SQLBinaryOperator, - _ right: Encodable + _ right: any Encodable ) -> Self { .sql(SQLBinaryExpression(left: left, op: op, right: SQLBind(right))) } @@ -107,9 +107,9 @@ extension DatabaseQuery.Sort { } public static func sql( - _ left: SQLExpression, - _ op: SQLExpression, - _ right: SQLExpression + _ left: any SQLExpression, + _ op: any SQLExpression, + _ right: any SQLExpression ) -> Self { .sql(SQLBinaryExpression(left: left, op: op, right: right)) } @@ -118,7 +118,7 @@ extension DatabaseQuery.Sort { .sql(embed) } - public static func sql(_ expression: SQLExpression) -> Self { + public static func sql(_ expression: any SQLExpression) -> Self { .custom(expression) } } diff --git a/Sources/FluentSQL/DatabaseSchema+SQL.swift b/Sources/FluentSQL/DatabaseSchema+SQL.swift index 5469981e..22a522c3 100644 --- a/Sources/FluentSQL/DatabaseSchema+SQL.swift +++ b/Sources/FluentSQL/DatabaseSchema+SQL.swift @@ -7,14 +7,14 @@ extension DatabaseSchema.DataType { } public static func sql(_ dataType: SQLDataType) -> Self { - .sql(dataType as SQLExpression) + .sql(dataType as any SQLExpression) } public static func sql(embed: SQLQueryString) -> Self { .sql(embed) } - public static func sql(_ expression: SQLExpression) -> Self { + public static func sql(_ expression: any SQLExpression) -> Self { .custom(expression) } } @@ -25,14 +25,14 @@ extension DatabaseSchema.Constraint { } public static func sql(_ constraint: SQLTableConstraintAlgorithm) -> Self { - .sql(constraint as SQLExpression) + .sql(constraint as any SQLExpression) } public static func sql(embed: SQLQueryString) -> Self { .sql(embed) } - public static func sql(_ expression: SQLExpression) -> Self { + public static func sql(_ expression: any SQLExpression) -> Self { .custom(expression) } } @@ -46,7 +46,7 @@ extension DatabaseSchema.ConstraintAlgorithm { .sql(embed) } - public static func sql(_ expression: SQLExpression) -> Self { + public static func sql(_ expression: any SQLExpression) -> Self { .custom(expression) } } @@ -57,14 +57,14 @@ extension DatabaseSchema.FieldConstraint { } public static func sql(_ constraint: SQLColumnConstraintAlgorithm) -> Self { - .sql(constraint as SQLExpression) + .sql(constraint as any SQLExpression) } public static func sql(embed: SQLQueryString) -> Self { .sql(embed) } - public static func sql(_ expression: SQLExpression) -> Self { + public static func sql(_ expression: any SQLExpression) -> Self { .custom(expression) } } @@ -78,7 +78,7 @@ extension DatabaseSchema.FieldDefinition { .sql(embed) } - public static func sql(_ expression: SQLExpression) -> Self { + public static func sql(_ expression: any SQLExpression) -> Self { .custom(expression) } } @@ -92,7 +92,7 @@ extension DatabaseSchema.FieldUpdate { .sql(embed) } - public static func sql(_ expression: SQLExpression) -> Self { + public static func sql(_ expression: any SQLExpression) -> Self { .custom(expression) } } @@ -106,7 +106,7 @@ extension DatabaseSchema.FieldName { .sql(embed) } - public static func sql(_ expression: SQLExpression) -> Self { + public static func sql(_ expression: any SQLExpression) -> Self { .custom(expression) } } @@ -120,7 +120,7 @@ extension DatabaseSchema.ConstraintDelete { .sql(embed) } - public static func sql(_ expression: SQLExpression) -> Self { + public static func sql(_ expression: any SQLExpression) -> Self { .custom(expression) } } diff --git a/Sources/FluentSQL/SQLDatabase+Model.swift b/Sources/FluentSQL/SQLDatabase+Model.swift index 1f3f47cd..822da38b 100644 --- a/Sources/FluentSQL/SQLDatabase+Model.swift +++ b/Sources/FluentSQL/SQLDatabase+Model.swift @@ -32,13 +32,13 @@ extension SQLRow { } internal struct SQLDatabaseOutput: DatabaseOutput { - let sql: SQLRow + let sql: any SQLRow var description: String { "\(self.sql)" } - func schema(_ schema: String) -> DatabaseOutput { + func schema(_ schema: String) -> any DatabaseOutput { self } diff --git a/Sources/FluentSQL/SQLList+Deprecated.swift b/Sources/FluentSQL/SQLList+Deprecated.swift index b5bd3a6a..7eb5868a 100644 --- a/Sources/FluentSQL/SQLList+Deprecated.swift +++ b/Sources/FluentSQL/SQLList+Deprecated.swift @@ -28,13 +28,13 @@ import SQLKit /// public. Convert code using these extensions to invoke the original ``SQLKit/SQLList`` directly. extension SQLKit.SQLList { @available(*, deprecated, message: "Use `expressions` instead.") - public var items: [SQLExpression] { + public var items: [any SQLExpression] { get { self.expressions } set { self.expressions = newValue } } @available(*, deprecated, message: "Use `init(_:separator:)` and include whitespace in the separator as needed instead.") - public init(items: [SQLExpression], separator: SQLExpression) { + public init(items: [any SQLExpression], separator: any SQLExpression) { self.init(items, separator: " \(separator) " as SQLQueryString) } } diff --git a/Sources/FluentSQL/SQLQualifiedTable.swift b/Sources/FluentSQL/SQLQualifiedTable.swift index 1d1993aa..79d55368 100644 --- a/Sources/FluentSQL/SQLQualifiedTable.swift +++ b/Sources/FluentSQL/SQLQualifiedTable.swift @@ -1,14 +1,14 @@ import SQLKit public struct SQLQualifiedTable: SQLExpression { - public var table: SQLExpression - public var space: SQLExpression? + public var table: any SQLExpression + public var space: (any SQLExpression)? public init(_ table: String, space: String? = nil) { self.init(SQLIdentifier(table), space: space.flatMap(SQLIdentifier.init(_:))) } - public init(_ table: SQLExpression, space: SQLExpression? = nil) { + public init(_ table: any SQLExpression, space: (any SQLExpression)? = nil) { self.table = table self.space = space } diff --git a/Sources/FluentSQL/SQLQueryConverter.swift b/Sources/FluentSQL/SQLQueryConverter.swift index 0c2249bc..01eda1f4 100644 --- a/Sources/FluentSQL/SQLQueryConverter.swift +++ b/Sources/FluentSQL/SQLQueryConverter.swift @@ -2,13 +2,13 @@ import FluentKit import SQLKit public struct SQLQueryConverter { - let delegate: SQLConverterDelegate - public init(delegate: SQLConverterDelegate) { + let delegate: any SQLConverterDelegate + public init(delegate: any SQLConverterDelegate) { self.delegate = delegate } - public func convert(_ fluent: DatabaseQuery) -> SQLExpression { - let sql: SQLExpression + public func convert(_ fluent: DatabaseQuery) -> any SQLExpression { + let sql: any SQLExpression switch fluent.action { case .read, .aggregate: sql = self.select(fluent) case .create: sql = self.insert(fluent) @@ -22,18 +22,18 @@ public struct SQLQueryConverter { // MARK: Private - private func delete(_ query: DatabaseQuery) -> SQLExpression { + private func delete(_ query: DatabaseQuery) -> any SQLExpression { var delete = SQLDelete(table: SQLQualifiedTable(query.schema, space: query.space)) delete.predicate = self.filters(query.filters) return delete } - private func update(_ query: DatabaseQuery) -> SQLExpression { + private func update(_ query: DatabaseQuery) -> any SQLExpression { var update = SQLUpdate(table: SQLQualifiedTable(query.schema, space: query.space)) guard case .dictionary(let values) = query.input.first else { fatalError("Missing query input generating update query") } - update.values = query.fields.compactMap { field -> SQLExpression? in + update.values = query.fields.compactMap { field -> (any SQLExpression)? in let key: FieldKey switch field { case let .path(path, schema) where schema == query.schema: key = path[0] @@ -47,7 +47,7 @@ public struct SQLQueryConverter { return update } - private func select(_ query: DatabaseQuery) -> SQLExpression { + private func select(_ query: DatabaseQuery) -> any SQLExpression { var select = SQLSelect() select.tables.append(SQLQualifiedTable(query.schema, space: query.space)) switch query.action { @@ -80,7 +80,7 @@ public struct SQLQueryConverter { return select } - private func insert(_ query: DatabaseQuery) -> SQLExpression { + private func insert(_ query: DatabaseQuery) -> any SQLExpression { var insert = SQLInsert(table: SQLQualifiedTable(query.schema, space: query.space)) // 1. Load the first set of inputs to the query, used as a basis to validate uniformity of all inputs. @@ -102,7 +102,7 @@ public struct SQLQueryConverter { // 4. Validate each set of inputs, making sure it provides exactly the keys as the first, and convert the sets // to their underlying SQL representations. - let dictionaries = query.input.map { input -> [FieldKey: SQLExpression] in + let dictionaries = query.input.map { input -> [FieldKey: any SQLExpression] in guard case let .dictionary(value) = input else { fatalError("Unexpected query input: \(input)") } guard Set(value.keys).symmetricDifference(usedKeys).isEmpty else { fatalError("Non-uniform query input: \(query.input)") } return value.mapValues(self.value(_:)) @@ -116,7 +116,7 @@ public struct SQLQueryConverter { return insert } - private func filters(_ filters: [DatabaseQuery.Filter]) -> SQLExpression? { + private func filters(_ filters: [DatabaseQuery.Filter]) -> (any SQLExpression)? { guard !filters.isEmpty else { return nil } @@ -127,7 +127,7 @@ public struct SQLQueryConverter { ) } - private func sort(_ sort: DatabaseQuery.Sort) -> SQLExpression { + private func sort(_ sort: DatabaseQuery.Sort) -> any SQLExpression { switch sort { case .sort(let field, let direction): return SQLOrderBy(expression: self.field(field), direction: self.direction(direction)) @@ -136,7 +136,7 @@ public struct SQLQueryConverter { } } - private func direction(_ direction: DatabaseQuery.Sort.Direction) -> SQLExpression { + private func direction(_ direction: DatabaseQuery.Sort.Direction) -> any SQLExpression { switch direction { case .ascending: return SQLDirection.ascending case .descending: return SQLDirection.descending @@ -144,7 +144,7 @@ public struct SQLQueryConverter { } } - private func join(_ join: DatabaseQuery.Join) -> SQLExpression { + private func join(_ join: DatabaseQuery.Join) -> any SQLExpression { switch join { case .custom(let any): return custom(any) @@ -165,14 +165,14 @@ public struct SQLQueryConverter { alias: String?, method: DatabaseQuery.Join.Method, filters: [DatabaseQuery.Filter] - ) -> SQLExpression { - let table: SQLExpression = alias.map { SQLAlias(SQLQualifiedTable(schema, space: space), as: SQLIdentifier($0)) } ?? + ) -> any SQLExpression { + let table: any SQLExpression = alias.map { SQLAlias(SQLQualifiedTable(schema, space: space), as: SQLIdentifier($0)) } ?? SQLQualifiedTable(schema, space: space) return SQLJoin(method: self.joinMethod(method), table: table, expression: self.filters(filters) ?? SQLLiteral.boolean(true)) } - private func joinMethod(_ method: DatabaseQuery.Join.Method) -> SQLExpression { + private func joinMethod(_ method: DatabaseQuery.Join.Method) -> any SQLExpression { switch method { case .inner: return SQLJoinMethod.inner case .left: return SQLJoinMethod.left @@ -181,7 +181,7 @@ public struct SQLQueryConverter { } } - private func field(_ field: DatabaseQuery.Field, aliased: Bool = false) -> SQLExpression { + private func field(_ field: DatabaseQuery.Field, aliased: Bool = false) -> any SQLExpression { switch field { case .custom(let any): return custom(any) @@ -192,8 +192,8 @@ public struct SQLQueryConverter { } } - private func fieldPath(_ path: [FieldKey], space: String? = nil, schema: String, aliased: Bool) -> SQLExpression { - let field: SQLExpression + private func fieldPath(_ path: [FieldKey], space: String? = nil, schema: String, aliased: Bool) -> any SQLExpression { + let field: any SQLExpression switch path.count { case 1: @@ -211,10 +211,10 @@ public struct SQLQueryConverter { } } - private func aggregate(_ aggregate: DatabaseQuery.Aggregate, isUnique: Bool) -> SQLExpression { + private func aggregate(_ aggregate: DatabaseQuery.Aggregate, isUnique: Bool) -> any SQLExpression { switch aggregate { case .custom(let any): - return any as! SQLExpression + return any as! any SQLExpression case .field(let field, let method): let name: String switch method { @@ -237,7 +237,7 @@ public struct SQLQueryConverter { } } - private func filter(_ filter: DatabaseQuery.Filter) -> SQLExpression { + private func filter(_ filter: DatabaseQuery.Filter) -> any SQLExpression { switch filter { case .value(let field, let method, let value): switch (method, value) { @@ -253,7 +253,7 @@ public struct SQLQueryConverter { let maybeString: String? if let string = bind as? String { maybeString = string - } else if let convertible = bind as? CustomStringConvertible { + } else if let convertible = bind as? any CustomStringConvertible { maybeString = convertible.description } else { maybeString = nil @@ -261,7 +261,7 @@ public struct SQLQueryConverter { guard let string = maybeString else { fatalError("Only string binds are supported with contains") } - let right: SQLExpression + let right: any SQLExpression switch method { case .anywhere: right = SQLBind("%" + string.description + "%") @@ -307,7 +307,7 @@ public struct SQLQueryConverter { } } - private func relation(_ relation: DatabaseQuery.Filter.Relation) -> SQLExpression { + private func relation(_ relation: DatabaseQuery.Filter.Relation) -> any SQLExpression { switch relation { case .and: return SQLBinaryOperator.and @@ -319,10 +319,10 @@ public struct SQLQueryConverter { } - private func value(_ value: DatabaseQuery.Value) -> SQLExpression { + private func value(_ value: DatabaseQuery.Value) -> any SQLExpression { switch value { case .bind(let encodable): - if let optional = encodable as? AnyOptionalType, optional.wrappedValue == nil { + if let optional = encodable as? any AnyOptionalType, optional.wrappedValue == nil { return SQLLiteral.null } else { return SQLBind(encodable) @@ -342,7 +342,7 @@ public struct SQLQueryConverter { } } - private func method(_ method: DatabaseQuery.Filter.Method) -> SQLExpression { + private func method(_ method: DatabaseQuery.Filter.Method) -> any SQLExpression { switch method { case .equality(let inverse): if inverse { @@ -381,7 +381,7 @@ public struct SQLQueryConverter { private struct EncodableDatabaseInput: Encodable { let input: [FieldKey: DatabaseQuery.Value] - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.container(keyedBy: FluentKit.SomeCodingKey.self) for (key, value) in self.input { try container.encode(EncodableDatabaseValue(value: value), forKey: FluentKit.SomeCodingKey(stringValue: key.description)) @@ -391,7 +391,7 @@ private struct EncodableDatabaseInput: Encodable { private struct EncodableDatabaseValue: Encodable { let value: DatabaseQuery.Value - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { switch self.value { case .bind(let encodable): try encodable.encode(to: encoder) @@ -412,7 +412,7 @@ extension DatabaseQuery.Value { case .null: return true case .bind(let bind): - guard let optional = bind as? AnyOptionalType, case .none = optional.wrappedValue else { return false } + guard let optional = bind as? any AnyOptionalType, case .none = optional.wrappedValue else { return false } return true default: return false diff --git a/Sources/FluentSQL/SQLSchemaConverter.swift b/Sources/FluentSQL/SQLSchemaConverter.swift index 8535c5f3..c143d6cd 100644 --- a/Sources/FluentSQL/SQLSchemaConverter.swift +++ b/Sources/FluentSQL/SQLSchemaConverter.swift @@ -2,13 +2,13 @@ import SQLKit @_spi(FluentSQLSPI) import FluentKit public protocol SQLConverterDelegate { - func customDataType(_ dataType: DatabaseSchema.DataType) -> SQLExpression? - func nestedFieldExpression(_ column: String, _ path: [String]) -> SQLExpression + func customDataType(_ dataType: DatabaseSchema.DataType) -> (any SQLExpression)? + func nestedFieldExpression(_ column: String, _ path: [String]) -> any SQLExpression func beforeConvert(_ schema: DatabaseSchema) -> DatabaseSchema } extension SQLConverterDelegate { - public func nestedFieldExpression(_ column: String, _ path: [String]) -> SQLExpression { + public func nestedFieldExpression(_ column: String, _ path: [String]) -> any SQLExpression { SQLNestedSubpathExpression(column: column, path: path) } @@ -18,12 +18,12 @@ extension SQLConverterDelegate { } public struct SQLSchemaConverter { - let delegate: SQLConverterDelegate - public init(delegate: SQLConverterDelegate) { + let delegate: any SQLConverterDelegate + public init(delegate: any SQLConverterDelegate) { self.delegate = delegate } - public func convert(_ schema: DatabaseSchema) -> SQLExpression { + public func convert(_ schema: DatabaseSchema) -> any SQLExpression { let schema = self.delegate.beforeConvert(schema) switch schema.action { case .create: @@ -37,7 +37,7 @@ public struct SQLSchemaConverter { // MARK: Private - private func update(_ schema: DatabaseSchema) -> SQLExpression { + private func update(_ schema: DatabaseSchema) -> any SQLExpression { var update = SQLAlterTable(name: self.name(schema.schema, space: schema.space)) update.addColumns = schema.createFields.map(self.fieldDefinition) update.dropColumns = schema.deleteFields.map(self.fieldName) @@ -51,12 +51,12 @@ public struct SQLSchemaConverter { return update } - private func delete(_ schema: DatabaseSchema) -> SQLExpression { + private func delete(_ schema: DatabaseSchema) -> any SQLExpression { let delete = SQLDropTable(table: self.name(schema.schema, space: schema.space)) return delete } - private func create(_ schema: DatabaseSchema) -> SQLExpression { + private func create(_ schema: DatabaseSchema) -> any SQLExpression { var create = SQLCreateTable(name: self.name(schema.schema, space: schema.space)) create.columns = schema.createFields.map(self.fieldDefinition) create.tableConstraints = schema.createConstraints.map { @@ -68,11 +68,11 @@ public struct SQLSchemaConverter { return create } - private func name(_ string: String, space: String? = nil) -> SQLExpression { + private func name(_ string: String, space: String? = nil) -> any SQLExpression { return SQLQualifiedTable(string, space: space) } - private func constraint(_ constraint: DatabaseSchema.Constraint, table: String) -> SQLExpression { + private func constraint(_ constraint: DatabaseSchema.Constraint, table: String) -> any SQLExpression { switch constraint { case .constraint(let algorithm, let customName): let name = customName ?? self.constraintIdentifier(algorithm, table: table) @@ -99,14 +99,14 @@ public struct SQLSchemaConverter { case .compositeIdentifier(let fields): return SQLConstraint(algorithm: SQLTableConstraintAlgorithm.primaryKey(columns: fields.map(self.fieldName)), name: nil) case .custom(let any): - return SQLConstraint(algorithm: any as! SQLExpression, name: customName.map(SQLIdentifier.init(_:))) + return SQLConstraint(algorithm: any as! any SQLExpression, name: customName.map(SQLIdentifier.init(_:))) } case .custom(let any): return custom(any) } } - private func deleteConstraint(_ constraint: DatabaseSchema.ConstraintDelete, table: String) -> SQLExpression { + private func deleteConstraint(_ constraint: DatabaseSchema.ConstraintDelete, table: String) -> any SQLExpression { switch constraint { case .constraint(let algorithm): let name = self.constraintIdentifier(algorithm, table: table) @@ -163,7 +163,7 @@ public struct SQLSchemaConverter { } } - private func fieldDefinition(_ fieldDefinition: DatabaseSchema.FieldDefinition) -> SQLExpression { + private func fieldDefinition(_ fieldDefinition: DatabaseSchema.FieldDefinition) -> any SQLExpression { switch fieldDefinition { case .custom(let any): return custom(any) @@ -176,7 +176,7 @@ public struct SQLSchemaConverter { } } - private func fieldUpdate(_ fieldDefinition: DatabaseSchema.FieldUpdate) -> SQLExpression { + private func fieldUpdate(_ fieldDefinition: DatabaseSchema.FieldUpdate) -> any SQLExpression { switch fieldDefinition { case .custom(let any): return custom(any) @@ -188,7 +188,7 @@ public struct SQLSchemaConverter { } } - private func fieldName(_ fieldName: DatabaseSchema.FieldName) -> SQLExpression { + private func fieldName(_ fieldName: DatabaseSchema.FieldName) -> any SQLExpression { switch fieldName { case .key(let key): return SQLIdentifier(self.key(key)) @@ -197,7 +197,7 @@ public struct SQLSchemaConverter { } } - private func dataType(_ dataType: DatabaseSchema.DataType) -> SQLExpression { + private func dataType(_ dataType: DatabaseSchema.DataType) -> any SQLExpression { if let custom = self.delegate.customDataType(dataType) { return custom } @@ -246,7 +246,7 @@ public struct SQLSchemaConverter { } } - private func fieldConstraint(_ fieldConstraint: DatabaseSchema.FieldConstraint) -> SQLExpression { + private func fieldConstraint(_ fieldConstraint: DatabaseSchema.FieldConstraint) -> any SQLExpression { switch fieldConstraint { case .required: return SQLColumnConstraintAlgorithm.notNull @@ -282,10 +282,10 @@ public struct SQLSchemaConverter { /// /// - Warning: This is only public for the benefit of `FluentBenchmarks`. DO NOT USE THIS TYPE! public struct SQLDropTypedConstraint: SQLExpression { - public let name: SQLExpression + public let name: any SQLExpression public let algorithm: DatabaseSchema.ConstraintAlgorithm - public init(name: SQLExpression, algorithm: DatabaseSchema.ConstraintAlgorithm) { + public init(name: any SQLExpression, algorithm: DatabaseSchema.ConstraintAlgorithm) { self.name = name self.algorithm = algorithm } @@ -320,9 +320,9 @@ public struct SQLDropTypedConstraint: SQLExpression { /// `CONSTRAINT/KEY ` @available(*, deprecated, message: "Use SQLDropTypedConstraint instead") public struct SQLDropConstraint: SQLExpression { - public var name: SQLExpression + public var name: any SQLExpression - public init(name: SQLExpression) { + public init(name: any SQLExpression) { self.name = name } diff --git a/Sources/FluentSQL/Utilities.swift b/Sources/FluentSQL/Utilities.swift index 93e52cc3..a7075064 100644 --- a/Sources/FluentSQL/Utilities.swift +++ b/Sources/FluentSQL/Utilities.swift @@ -1,13 +1,13 @@ import SQLKit -func custom(_ any: Any) -> SQLExpression { - if let sql = any as? SQLExpression { +func custom(_ any: Any) -> any SQLExpression { + if let sql = any as? any SQLExpression { return sql } if let string = any as? String { return SQLRaw(string) } - if let stringConvertible = any as? CustomStringConvertible { + if let stringConvertible = any as? any CustomStringConvertible { return SQLRaw(stringConvertible.description) } fatalError("Could not convert \(any) to a SQL-compatible type.") diff --git a/Sources/XCTFluent/DummyDatabase.swift b/Sources/XCTFluent/DummyDatabase.swift index 5e4be52e..fd2f435a 100644 --- a/Sources/XCTFluent/DummyDatabase.swift +++ b/Sources/XCTFluent/DummyDatabase.swift @@ -18,18 +18,18 @@ public struct DummyDatabase: Database { false } - public func execute(query: DatabaseQuery, onOutput: @escaping (DatabaseOutput) -> ()) -> EventLoopFuture { + public func execute(query: DatabaseQuery, onOutput: @escaping (any DatabaseOutput) -> ()) -> EventLoopFuture { for _ in 0..(_ closure: @escaping (Database) -> EventLoopFuture) -> EventLoopFuture { + public func transaction(_ closure: @escaping (any Database) -> EventLoopFuture) -> EventLoopFuture { closure(self) } - public func withConnection(_ closure: (Database) -> EventLoopFuture) -> EventLoopFuture { + public func withConnection(_ closure: (any Database) -> EventLoopFuture) -> EventLoopFuture { closure(self) } @@ -43,27 +43,27 @@ public struct DummyDatabase: Database { } public struct DummyDatabaseConfiguration: DatabaseConfiguration { - public var middleware: [AnyModelMiddleware] + public var middleware: [any AnyModelMiddleware] - public func makeDriver(for databases: Databases) -> DatabaseDriver { + public func makeDriver(for databases: Databases) -> any DatabaseDriver { DummyDatabaseDriver(on: databases.eventLoopGroup) } } public final class DummyDatabaseDriver: DatabaseDriver { - public let eventLoopGroup: EventLoopGroup + public let eventLoopGroup: any EventLoopGroup var didShutdown: Bool - public var fieldDecoder: Decoder { + public var fieldDecoder: any Decoder { return DummyDecoder() } - public init(on eventLoopGroup: EventLoopGroup) { + public init(on eventLoopGroup: any EventLoopGroup) { self.eventLoopGroup = eventLoopGroup self.didShutdown = false } - public func makeDatabase(with context: DatabaseContext) -> Database { + public func makeDatabase(with context: DatabaseContext) -> any Database { DummyDatabase(context: context) } @@ -80,11 +80,11 @@ public final class DummyDatabaseDriver: DatabaseDriver { public struct DummyRow: DatabaseOutput { public init() { } - public func schema(_ schema: String) -> DatabaseOutput { + public func schema(_ schema: String) -> any DatabaseOutput { self } - public func nested(_ key: FieldKey) throws -> DatabaseOutput { + public func nested(_ key: FieldKey) throws -> any DatabaseOutput { self } @@ -114,11 +114,11 @@ public struct DummyRow: DatabaseOutput { } private struct DummyDecoder: Decoder { - var codingPath: [CodingKey] { + var codingPath: [any CodingKey] { return [] } - var userInfo: [CodingUserInfoKey : Any] { + var userInfo: [CodingUserInfoKey: Any] { return [:] } @@ -129,7 +129,7 @@ private struct DummyDecoder: Decoder { struct KeyedDecoder: KeyedDecodingContainerProtocol where Key: CodingKey { - var codingPath: [CodingKey] { + var codingPath: [any CodingKey] { return [] } var allKeys: [Key] { @@ -160,21 +160,21 @@ private struct DummyDecoder: Decoder { return KeyedDecodingContainer(KeyedDecoder()) } - func nestedUnkeyedContainer(forKey key: Key) throws -> UnkeyedDecodingContainer { + func nestedUnkeyedContainer(forKey key: Key) throws -> any UnkeyedDecodingContainer { return UnkeyedDecoder() } - func superDecoder() throws -> Decoder { + func superDecoder() throws -> any Decoder { return DummyDecoder() } - func superDecoder(forKey key: Key) throws -> Decoder { + func superDecoder(forKey key: Key) throws -> any Decoder { return DummyDecoder() } } struct UnkeyedDecoder: UnkeyedDecodingContainer { - var codingPath: [CodingKey] + var codingPath: [any CodingKey] var count: Int? var isAtEnd: Bool { guard let count = self.count else { @@ -202,17 +202,17 @@ private struct DummyDecoder: Decoder { return KeyedDecodingContainer(KeyedDecoder()) } - mutating func nestedUnkeyedContainer() throws -> UnkeyedDecodingContainer { + mutating func nestedUnkeyedContainer() throws -> any UnkeyedDecodingContainer { return UnkeyedDecoder() } - mutating func superDecoder() throws -> Decoder { + mutating func superDecoder() throws -> any Decoder { return DummyDecoder() } } struct SingleValueDecoder: SingleValueDecodingContainer { - var codingPath: [CodingKey] { + var codingPath: [any CodingKey] { return [] } @@ -291,11 +291,11 @@ private struct DummyDecoder: Decoder { return .init(KeyedDecoder()) } - func unkeyedContainer() throws -> UnkeyedDecodingContainer { + func unkeyedContainer() throws -> any UnkeyedDecodingContainer { return UnkeyedDecoder() } - func singleValueContainer() throws -> SingleValueDecodingContainer { + func singleValueContainer() throws -> any SingleValueDecodingContainer { return SingleValueDecoder() } } diff --git a/Sources/XCTFluent/TestDatabase.swift b/Sources/XCTFluent/TestDatabase.swift index a430658c..a84bce4a 100644 --- a/Sources/XCTFluent/TestDatabase.swift +++ b/Sources/XCTFluent/TestDatabase.swift @@ -43,13 +43,13 @@ import NIOCore /// ]) /// public final class ArrayTestDatabase: TestDatabase { - var results: [[DatabaseOutput]] + var results: [[any DatabaseOutput]] public init() { self.results = [] } - public func append(_ result: [DatabaseOutput]) { + public func append(_ result: [any DatabaseOutput]) { self.results.append(result) } @@ -59,7 +59,7 @@ public final class ArrayTestDatabase: TestDatabase { self.results.append(result.map { TestOutput($0) }) } - public func execute(query: DatabaseQuery, onOutput: (DatabaseOutput) -> ()) throws { + public func execute(query: DatabaseQuery, onOutput: (any DatabaseOutput) -> ()) throws { guard !self.results.isEmpty else { throw TestDatabaseError.ranOutOfResults } @@ -70,13 +70,13 @@ public final class ArrayTestDatabase: TestDatabase { } public final class CallbackTestDatabase: TestDatabase { - var callback: (DatabaseQuery) -> [DatabaseOutput] + var callback: (DatabaseQuery) -> [any DatabaseOutput] - public init(callback: @escaping (DatabaseQuery) -> [DatabaseOutput]) { + public init(callback: @escaping (DatabaseQuery) -> [any DatabaseOutput]) { self.callback = callback } - public func execute(query: DatabaseQuery, onOutput: (DatabaseOutput) -> ()) throws { + public func execute(query: DatabaseQuery, onOutput: (any DatabaseOutput) -> ()) throws { for output in self.callback(query) { onOutput(output) } @@ -86,12 +86,12 @@ public final class CallbackTestDatabase: TestDatabase { public protocol TestDatabase { func execute( query: DatabaseQuery, - onOutput: (DatabaseOutput) -> () + onOutput: (any DatabaseOutput) -> () ) throws } extension TestDatabase { - public var db: Database { + public var db: any Database { self.database(context: .init( configuration: self.configuration, logger: Logger(label: "codes.vapor.fluent.test"), @@ -99,7 +99,7 @@ extension TestDatabase { )) } - public func database(context: DatabaseContext) -> Database { + public func database(context: DatabaseContext) -> any Database { _TestDatabase(test: self, context: context) } } @@ -108,12 +108,12 @@ private struct _TestDatabase: Database { var inTransaction: Bool { false } - let test: TestDatabase + let test: any TestDatabase var context: DatabaseContext func execute( query: DatabaseQuery, - onOutput: @escaping (DatabaseOutput) -> () + onOutput: @escaping (any DatabaseOutput) -> () ) -> EventLoopFuture { guard context.eventLoop.inEventLoop else { return self.eventLoop.flatSubmit { @@ -128,11 +128,11 @@ private struct _TestDatabase: Database { return self.eventLoop.makeSucceededFuture(()) } - func transaction(_ closure: @escaping (Database) -> EventLoopFuture) -> EventLoopFuture { + func transaction(_ closure: @escaping (any Database) -> EventLoopFuture) -> EventLoopFuture { closure(self) } - func withConnection(_ closure: (Database) -> EventLoopFuture) -> EventLoopFuture { + func withConnection(_ closure: (any Database) -> EventLoopFuture) -> EventLoopFuture { closure(self) } @@ -146,25 +146,25 @@ private struct _TestDatabase: Database { } extension TestDatabase { - public var configuration: DatabaseConfiguration { + public var configuration: any DatabaseConfiguration { _TestConfiguration(test: self) } } private struct _TestConfiguration: DatabaseConfiguration { - let test: TestDatabase - var middleware: [AnyModelMiddleware] = [] + let test: any TestDatabase + var middleware: [any AnyModelMiddleware] = [] - func makeDriver(for databases: Databases) -> DatabaseDriver { + func makeDriver(for databases: Databases) -> any DatabaseDriver { _TestDriver(test: self.test) } } private struct _TestDriver: DatabaseDriver { - let test: TestDatabase + let test: any TestDatabase - func makeDatabase(with context: DatabaseContext) -> Database { + func makeDatabase(with context: DatabaseContext) -> any Database { self.test.database(context: context) } @@ -178,7 +178,7 @@ public enum TestDatabaseError: Error { } public struct TestOutput: DatabaseOutput { - public func schema(_ schema: String) -> DatabaseOutput { + public func schema(_ schema: String) -> any DatabaseOutput { self } @@ -196,7 +196,7 @@ public struct TestOutput: DatabaseOutput { } - public func nested(_ key: FieldKey) throws -> DatabaseOutput { + public func nested(_ key: FieldKey) throws -> any DatabaseOutput { self } diff --git a/Tests/FluentKitTests/CompositeIDTests.swift b/Tests/FluentKitTests/CompositeIDTests.swift index 91955d92..7f42783b 100644 --- a/Tests/FluentKitTests/CompositeIDTests.swift +++ b/Tests/FluentKitTests/CompositeIDTests.swift @@ -191,7 +191,7 @@ final class CompositeIDTests: XCTestCase { let allPlanetFields = #""composite+planet"."system_id" AS "composite+planet_system_id", "composite+planet"."nrm_ord" AS "composite+planet_nrm_ord", "composite+planet"."name" AS "composite+planet_name" FROM "composite+planet""# let allMoonFields = #""composite+moon"."id" AS "composite+moon_id", "composite+moon"."name" AS "composite+moon_name", "composite+moon"."planet_system_id" AS "composite+moon_planet_system_id", "composite+moon"."planet_nrm_ord" AS "composite+moon_planet_nrm_ord", "composite+moon"."progenitorSystem_id" AS "composite+moon_progenitorSystem_id", "composite+moon"."progenitorNrm_ord" AS "composite+moon_progenitorNrm_ord", "composite+moon"."planetoid_system_id" AS "composite+moon_planetoid_system_id", "composite+moon"."planetoid_nrm_ord" AS "composite+moon_planetoid_nrm_ord" FROM "composite+moon""# - let expectedQueries: [(String, [Encodable])] = [ + let expectedQueries: [(String, [any Encodable])] = [ (#"SELECT \#(allPlanetFields) WHERE ("composite+planet"."system_id" = $1 AND "composite+planet"."nrm_ord" = $2)"#, [systemId, 1]), (#"SELECT \#(allPlanetFields) WHERE ("composite+planet"."system_id" = $1 AND "composite+planet"."nrm_ord" = $2)"#, [systemId, 2]), (#"SELECT \#(allPlanetFields) WHERE ("composite+planet"."system_id" IS NULL AND "composite+planet"."nrm_ord" IS NULL)"#, []), @@ -237,7 +237,7 @@ final class CompositeIDTests: XCTestCase { let moonCols = #""id", "name", "planet_system_id", "planet_nrm_ord", "progenitorSystem_id", "progenitorNrm_ord", "planetoid_system_id", "planetoid_nrm_ord""# let fourVals = "$1, $2, $3, $4, NULL, NULL, NULL, NULL" let sixVals1 = "$1, $2, $3, $4, $5, $6, NULL, NULL", sixVals2 = "$1, $2, $3, $4, NULL, NULL, $5, $6" - let expectedQueries: [(String, [Encodable], UInt)] = [ + let expectedQueries: [(String, [any Encodable], UInt)] = [ (#"INSERT INTO "composite+planet" ("system_id", "nrm_ord", "name") VALUES ($1, $2, $3)"#, [sysId, 1, "A"], #line), (#"INSERT INTO "composite+moon" (\#(moonCols)) VALUES (\#(fourVals))"#, [moon1.id!, "B", sysId, 1], #line), (#"INSERT INTO "composite+moon" (\#(moonCols)) VALUES (\#(sixVals1))"#, [moon2.id!, "C", sysId, 1, sysId, 2], #line), @@ -407,7 +407,7 @@ final class CompositePlanetTag: Model { struct CompositePlanetTagMigration: Migration { init() {} - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: any Database) -> EventLoopFuture { database.schema(CompositePlanetTag.schema) .field("planet_id", .uuid, .required, .references(PlanetUsingCompositePivot.schema, "id")) .field("tag_id", .uuid, .required, .references(Tag.schema, "id")) @@ -419,7 +419,7 @@ struct CompositePlanetTagMigration: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: any Database) -> EventLoopFuture { database.schema(CompositePlanetTag.schema).delete() } } diff --git a/Tests/FluentKitTests/DummyDatabaseForTestSQLSerializer.swift b/Tests/FluentKitTests/DummyDatabaseForTestSQLSerializer.swift index 123e8c73..2cf3d2f8 100644 --- a/Tests/FluentKitTests/DummyDatabaseForTestSQLSerializer.swift +++ b/Tests/FluentKitTests/DummyDatabaseForTestSQLSerializer.swift @@ -10,17 +10,17 @@ public class DummyDatabaseForTestSQLSerializer: Database, SQLDatabase { } struct Configuration: DatabaseConfiguration { - func makeDriver(for databases: Databases) -> DatabaseDriver { + func makeDriver(for databases: Databases) -> any DatabaseDriver { fatalError() } - var middleware: [AnyModelMiddleware] + var middleware: [any AnyModelMiddleware] init() { self.middleware = [] } } - public var dialect: SQLDialect { + public var dialect: any SQLDialect { DummyDatabaseDialect() } @@ -42,7 +42,7 @@ public class DummyDatabaseForTestSQLSerializer: Database, SQLDatabase { public func execute( query: DatabaseQuery, - onOutput: @escaping (DatabaseOutput) -> () + onOutput: @escaping (any DatabaseOutput) -> () ) -> EventLoopFuture { var sqlSerializer = SQLSerializer(database: self) let sqlExpression = SQLQueryConverter(delegate: DummyDatabaseConverterDelegate()).convert(query) @@ -52,11 +52,11 @@ public class DummyDatabaseForTestSQLSerializer: Database, SQLDatabase { return self.eventLoop.makeSucceededFuture(()) } - public func execute(sql query: SQLExpression, _ onRow: @escaping (SQLRow) -> ()) -> EventLoopFuture { + public func execute(sql query: any SQLExpression, _ onRow: @escaping (any SQLRow) -> ()) -> EventLoopFuture { fatalError() } - public func transaction(_ closure: @escaping (Database) -> EventLoopFuture) -> EventLoopFuture { + public func transaction(_ closure: @escaping (any Database) -> EventLoopFuture) -> EventLoopFuture { closure(self) } @@ -74,7 +74,7 @@ public class DummyDatabaseForTestSQLSerializer: Database, SQLDatabase { } public func withConnection( - _ closure: @escaping (Database) -> EventLoopFuture + _ closure: @escaping (any Database) -> EventLoopFuture ) -> EventLoopFuture { closure(self) } @@ -98,19 +98,19 @@ struct DummyDatabaseDialect: SQLDialect { "dummy db" } - var identifierQuote: SQLExpression { + var identifierQuote: any SQLExpression { return SQLRaw("\"") } - var literalStringQuote: SQLExpression { + var literalStringQuote: any SQLExpression { return SQLRaw("'") } - func bindPlaceholder(at position: Int) -> SQLExpression { + func bindPlaceholder(at position: Int) -> any SQLExpression { return SQLRaw("$" + position.description) } - func literalBoolean(_ value: Bool) -> SQLExpression { + func literalBoolean(_ value: Bool) -> any SQLExpression { switch value { case false: return SQLRaw("false") @@ -119,22 +119,22 @@ struct DummyDatabaseDialect: SQLDialect { } } - var autoIncrementClause: SQLExpression { + var autoIncrementClause: any SQLExpression { return SQLRaw("GENERATED BY DEFAULT AS IDENTITY") } - var sharedSelectLockExpression: SQLExpression? { + var sharedSelectLockExpression: (any SQLExpression)? { SQLRaw("FOR SHARE") } - var exclusiveSelectLockExpression: SQLExpression? { + var exclusiveSelectLockExpression: (any SQLExpression)? { SQLRaw("FOR UPDATE") } } // Copy from PostgresConverterDelegate struct DummyDatabaseConverterDelegate: SQLConverterDelegate { - func customDataType(_ dataType: DatabaseSchema.DataType) -> SQLExpression? { + func customDataType(_ dataType: DatabaseSchema.DataType) -> (any SQLExpression)? { switch dataType { case .uuid: return SQLRaw("UUID") @@ -149,7 +149,7 @@ struct DummyDatabaseConverterDelegate: SQLConverterDelegate { } } - func nestedFieldExpression(_ column: String, _ path: [String]) -> SQLExpression { + func nestedFieldExpression(_ column: String, _ path: [String]) -> any SQLExpression { return SQLRaw("\(column)->>'\(path[0])'") } } diff --git a/Tests/FluentKitTests/FluentKitTests.swift b/Tests/FluentKitTests/FluentKitTests.swift index 1fc25e3d..2087d7ee 100644 --- a/Tests/FluentKitTests/FluentKitTests.swift +++ b/Tests/FluentKitTests/FluentKitTests.swift @@ -497,7 +497,7 @@ final class FluentKitTests: XCTestCase { } func testLoggerOverride() throws { - let db: Database = DummyDatabaseForTestSQLSerializer() + let db: any Database = DummyDatabaseForTestSQLSerializer() XCTAssertEqual(db.logger.logLevel, env("LOG_LEVEL").flatMap { Logger.Level(rawValue: $0) } ?? .info) var logger = db.logger logger.logLevel = .critical From efd08df63c3f6205f117856f76c1dc731d3a2086 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Mon, 15 Apr 2024 05:29:12 -0500 Subject: [PATCH 5/6] Add 5.9 manifest to enforce ExistentialAny --- Package@swift-5.9.swift | 74 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Package@swift-5.9.swift diff --git a/Package@swift-5.9.swift b/Package@swift-5.9.swift new file mode 100644 index 00000000..24bf34f1 --- /dev/null +++ b/Package@swift-5.9.swift @@ -0,0 +1,74 @@ +// swift-tools-version:5.9 +import PackageDescription + +let package = Package( + name: "fluent-kit", + platforms: [ + .macOS(.v10_15), + .iOS(.v13), + .watchOS(.v6), + .tvOS(.v13), + ], + products: [ + .library(name: "FluentKit", targets: ["FluentKit"]), + .library(name: "FluentBenchmark", targets: ["FluentBenchmark"]), + .library(name: "FluentSQL", targets: ["FluentSQL"]), + .library(name: "XCTFluent", targets: ["XCTFluent"]), + ], + dependencies: [ + .package(url: "https://github.com/apple/swift-nio.git", from: "2.55.0"), + .package(url: "https://github.com/apple/swift-log.git", from: "1.5.2"), + .package(url: "https://github.com/vapor/sql-kit.git", from: "3.28.0"), + .package(url: "https://github.com/vapor/async-kit.git", from: "1.17.0"), + ], + targets: [ + .target( + name: "FluentKit", + dependencies: [ + .product(name: "NIO", package: "swift-nio"), + .product(name: "NIOCore", package: "swift-nio"), + .product(name: "Logging", package: "swift-log"), + .product(name: "AsyncKit", package: "async-kit"), + .product(name: "SQLKit", package: "sql-kit"), + ], + swiftSettings: swiftSettings + ), + .target( + name: "FluentBenchmark", + dependencies: [ + .target(name: "FluentKit"), + .target(name: "FluentSQL"), + ], + swiftSettings: swiftSettings + ), + .target( + name: "FluentSQL", + dependencies: [ + .target(name: "FluentKit"), + .product(name: "SQLKit", package: "sql-kit"), + ], + swiftSettings: swiftSettings + ), + .target( + name: "XCTFluent", + dependencies: [ + .target(name: "FluentKit"), + .product(name: "NIOEmbedded", package: "swift-nio"), + ], + swiftSettings: swiftSettings + ), + .testTarget( + name: "FluentKitTests", + dependencies: [ + .target(name: "FluentBenchmark"), + .target(name: "FluentSQL"), + .target(name: "XCTFluent"), + ], + swiftSettings: swiftSettings + ), + ] +) + +var swiftSettings: [SwiftSetting] { [ + .enableUpcomingFeature("ExistentialAny"), +] } From 6030a724570addcd93ab9fd1a5bdde748043ff49 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Mon, 15 Apr 2024 06:59:11 -0500 Subject: [PATCH 6/6] CI update --- .github/workflows/test.yml | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 202f17e7..95ed7db5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,22 +42,22 @@ jobs: linux-integration: if: ${{ !(github.event.pull_request.draft || false) }} runs-on: ubuntu-latest - container: swift:5.8-jammy + container: swift:5.10-jammy services: mysql-a: - image: mysql:8.0 + image: mysql:8 env: { MYSQL_ALLOW_EMPTY_PASSWORD: true, MYSQL_USER: test_username, MYSQL_PASSWORD: test_password, MYSQL_DATABASE: test_database } mysql-b: - image: mysql:8.0 + image: mysql:8 env: { MYSQL_ALLOW_EMPTY_PASSWORD: true, MYSQL_USER: test_username, MYSQL_PASSWORD: test_password, MYSQL_DATABASE: test_database } psql-a: - image: postgres:15 + image: postgres:16 env: { POSTGRES_USER: test_username, POSTGRES_PASSWORD: test_password, POSTGRES_DB: test_database, POSTGRES_HOST_AUTH_METHOD: scram-sha-256, POSTGRES_INITDB_ARGS: --auth-host=scram-sha-256 } psql-b: - image: postgres:15 + image: postgres:16 env: { POSTGRES_USER: test_username, POSTGRES_PASSWORD: test_password, POSTGRES_DB: test_database, POSTGRES_HOST_AUTH_METHOD: scram-sha-256, POSTGRES_INITDB_ARGS: --auth-host=scram-sha-256 @@ -76,11 +76,11 @@ jobs: - { dependent: 'fluent-mongo-driver', ref: 'main' } steps: - name: Check out package - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: fluent-kit - name: Check out dependent - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: vapor/${{ matrix.dependent }} path: ${{ matrix.dependent }} @@ -92,10 +92,7 @@ jobs: swift package --package-path ${DEPENDENT} edit fluent-kit --path fluent-kit swift test --package-path ${DEPENDENT} - # also serves as code coverage baseline update unit-tests: uses: vapor/ci/.github/workflows/run-unit-tests.yml@main with: - with_coverage: true - with_tsan: true coverage_ignores: '/Tests/|/Sources/FluentBenchmark/'