Skip to content

Commit

Permalink
Primary Sendable support for Fluent (#601)
Browse files Browse the repository at this point in the history
* Bump min Swift to 5.8, add feature flags
* Mark as many things Sendable as we can
* Package structure and CI updates
* MirrorBypass is valid in 5.10 (looks like it'll be valid in 6.0 too, but holding off on that just in case)
* SomeCodingKey is now provided by SQLKit
* Add the missing utilities for encoding Fluent models to SQLKit queries
* Minor code and docs cleanup
* Update the fake database used for testing to be more flexible and fix tests accordingly
* Add tests for new FluentSQL APIs
* Remove the last few uses of print() (all in tests)
* Fix locking of QueryHistory
  • Loading branch information
gwynne authored Apr 26, 2024
1 parent 81db32f commit 4fffbaa
Show file tree
Hide file tree
Showing 141 changed files with 1,698 additions and 1,051 deletions.

This file was deleted.

38 changes: 38 additions & 0 deletions .github/.codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
codecov:
notify:
after_n_builds: 1
wait_for_ci: false
require_ci_to_pass: false
comment:
behavior: default
layout: diff, files
require_changes: true
coverage:
status:
patch:
default:
branches:
- ^main$
informational: true
only_pulls: false
paths:
- ^Sources.*
target: auto
project:
default:
branches:
- ^main$
informational: true
only_pulls: false
paths:
- ^Sources.*
target: auto
github_checks:
annotations: true
ignore:
- ^Sources/XCTFluent/.*
- ^Sources/FluentBenchmarks/.*
- ^Tests/.*
- ^.build/.*
slack_app: false

104 changes: 61 additions & 43 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,60 +39,78 @@ env:

jobs:

linux-integration:
linux-integration-sqlite:
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:5.10-jammy
steps:
- name: Check out package
uses: actions/checkout@v4
with: { path: fluent-kit }
- name: Check out dependent
uses: actions/checkout@v4
with: { repository: vapor/fluent-sqlite-driver, path: fluent-sqlite-driver }
- name: Use local package and run tests
run: |
swift package --package-path fluent-sqlite-driver edit fluent-kit --path fluent-kit
swift test --package-path fluent-sqlite-driver --sanitize=thread
linux-integration-mysql:
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:5.10-jammy
services:
mysql-a: { 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', env: { MYSQL_ALLOW_EMPTY_PASSWORD: true, MYSQL_USER: test_username, MYSQL_PASSWORD: test_password, MYSQL_DATABASE: test_database } }
steps:
- name: Check out package
uses: actions/checkout@v4
with: { path: fluent-kit }
- name: Check out dependent
uses: actions/checkout@v4
with: { repository: vapor/fluent-mysql-driver, path: fluent-mysql-driver }
- name: Use local package and run tests
run: |
swift package --package-path fluent-mysql-driver edit fluent-kit --path fluent-kit
swift test --package-path fluent-mysql-driver --sanitize=thread
linux-integration-psql:
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:5.10-jammy
services:
psql-a: { 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: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 } }
steps:
- name: Check out package
uses: actions/checkout@v4
with: { path: fluent-kit }
- name: Check out dependent
uses: actions/checkout@v4
with: { repository: vapor/fluent-postgres-driver, path: fluent-postgres-driver }
- name: Use local package and run tests
run: |
swift package --package-path fluent-postgres-driver edit fluent-kit --path fluent-kit
swift test --package-path fluent-postgres-driver --sanitize=thread
linux-integration-mongo:
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:5.10-jammy
services:
mysql-a:
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
env: { MYSQL_ALLOW_EMPTY_PASSWORD: true, MYSQL_USER: test_username, MYSQL_PASSWORD: test_password, MYSQL_DATABASE: test_database }
psql-a:
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: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
}
mongo-a:
image: mongo:6
mongo-b:
image: mongo:6
strategy:
fail-fast: false
matrix:
include:
- { dependent: 'fluent-sqlite-driver', ref: 'main' }
- { dependent: 'fluent-postgres-driver', ref: 'main' }
- { dependent: 'fluent-mysql-driver', ref: 'main' }
- { dependent: 'fluent-mongo-driver', ref: 'main' }
mongo-a: { image: 'mongo:6' }
mongo-b: { image: 'mongo:6' }
steps:
- name: Check out package
uses: actions/checkout@v4
with:
path: fluent-kit
with: { path: fluent-kit }
- name: Check out dependent
uses: actions/checkout@v4
with:
repository: vapor/${{ matrix.dependent }}
path: ${{ matrix.dependent }}
ref: ${{ matrix.ref }}
with: { repository: vapor/fluent-mongo-driver, path: fluent-mongo-driver }
- name: Use local package and run tests
env:
DEPENDENT: ${{ matrix.dependent }}
run: |
swift package --package-path ${DEPENDENT} edit fluent-kit --path fluent-kit
swift test --package-path ${DEPENDENT}
swift package --package-path fluent-mongo-driver edit fluent-kit --path fluent-kit
swift test --package-path fluent-mongo-driver --sanitize=thread
unit-tests:
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main
with:
coverage_ignores: '/Tests/|/Sources/FluentBenchmark/'
81 changes: 56 additions & 25 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version:5.8
import PackageDescription

let package = Package(
Expand All @@ -22,29 +22,60 @@ let package = Package(
.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"),
]),
.target(name: "FluentBenchmark", dependencies: [
.target(name: "FluentKit"),
.target(name: "FluentSQL"),
]),
.target(name: "FluentSQL", dependencies: [
.target(name: "FluentKit"),
.product(name: "SQLKit", package: "sql-kit"),
]),
.target(name: "XCTFluent", dependencies: [
.target(name: "FluentKit"),
.product(name: "NIOEmbedded", package: "swift-nio"),
]),
.testTarget(name: "FluentKitTests", dependencies: [
.target(name: "FluentBenchmark"),
.target(name: "FluentSQL"),
.target(name: "XCTFluent"),
]),
.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: [
.product(name: "SQLKit", package: "sql-kit"),
.target(name: "FluentKit"),
],
swiftSettings: swiftSettings
),
.target(
name: "XCTFluent",
dependencies: [
.product(name: "NIOEmbedded", package: "swift-nio"),
.target(name: "FluentKit"),
],
swiftSettings: swiftSettings
),
.testTarget(
name: "FluentKitTests",
dependencies: [
.target(name: "FluentBenchmark"),
.target(name: "FluentSQL"),
.target(name: "XCTFluent"),
],
swiftSettings: swiftSettings
),
]
)

var swiftSettings: [SwiftSetting] { [
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("ForwardTrailingClosures"),
.enableUpcomingFeature("ImportObjcForwardDeclarations"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableUpcomingFeature("IsolatedDefaultValues"),
.enableUpcomingFeature("GlobalConcurrency"),
.enableUpcomingFeature("StrictConcurrency"),
.enableExperimentalFeature("StrictConcurrency=complete"),
] }
12 changes: 10 additions & 2 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ let package = Package(
.target(
name: "FluentSQL",
dependencies: [
.target(name: "FluentKit"),
.product(name: "SQLKit", package: "sql-kit"),
.target(name: "FluentKit"),
],
swiftSettings: swiftSettings
),
.target(
name: "XCTFluent",
dependencies: [
.target(name: "FluentKit"),
.product(name: "NIOEmbedded", package: "swift-nio"),
.target(name: "FluentKit"),
],
swiftSettings: swiftSettings
),
Expand All @@ -71,4 +71,12 @@ let package = Package(

var swiftSettings: [SwiftSetting] { [
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("ForwardTrailingClosures"),
.enableUpcomingFeature("ImportObjcForwardDeclarations"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableUpcomingFeature("IsolatedDefaultValues"),
.enableUpcomingFeature("GlobalConcurrency"),
.enableUpcomingFeature("StrictConcurrency"),
.enableExperimentalFeature("StrictConcurrency=complete"),
] }
54 changes: 29 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
<p align="center">
<img
src="https://user-images.githubusercontent.com/1342803/58727365-19b1a280-83b2-11e9-8240-601f3e5fa68f.png"
height="64"
alt="FluentKit"
>
<br>
<br>
<a href="https://docs.vapor.codes/4.0/">
<img src="http://img.shields.io/badge/read_the-docs-2196f3.svg" alt="Documentation">
</a>
<a href="https://discord.gg/vapor">
<img src="https://img.shields.io/discord/431917998102675485.svg" alt="Team Chat">
</a>
<a href="LICENSE">
<img src="http://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License">
</a>
<a href="https://github.com/vapor/fluent-kit/actions/workflows/test.yml">
<img src="https://github.com/vapor/fluent-kit/actions/workflows/test.yml/badge.svg?event=push" alt="Continuous Integration">
</a>
<a href="https://codecov.io/gh/vapor/fluent-kit">
<img src="https://codecov.io/gh/vapor/fluent-kit/branch/main/graph/badge.svg?token=6slVbnp1mV" alt="Test Coverage">
</a>
<a href="https://swift.org">
<img src="http://img.shields.io/badge/swift-5.6-brightgreen.svg" alt="Swift 5.6">
</a>
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/vapor/fluent-kit/assets/1130717/1da9ba22-253a-43ba-ac03-5cecf0075c30">
<source media="(prefers-color-scheme: light)" srcset="https://github.com/vapor/fluent-kit/assets/1130717/89800da9-2651-4fff-900a-be8f691bedb9">
<img src="https://github.com/vapor/fluent-kit/assets/1130717/89800da9-2651-4fff-900a-be8f691bedb9" height="96" alt="FluentKit">
</picture>
<br>
<br>
<a href="https://docs.vapor.codes/4.0/"><img src="https://design.vapor.codes/images/readthedocs.svg" alt="Documentation"></a>
<a href="https://discord.gg/vapor"><img src="https://design.vapor.codes/images/discordchat.svg" alt="Team Chat"></a>
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg" alt="MIT License"></a>
<a href="https://github.com/vapor/fluent-kit/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/vapor/fluent-kit/test.yml?event=push&style=plastic&logo=github&label=tests&logoColor=%23ccc" alt="Continuous Integration"></a>
<a href="https://codecov.io/github/vapor/fluent-kit"><img src="https://img.shields.io/codecov/c/github/vapor/fluent-kit?style=plastic&logo=codecov&label=codecov"></a>
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift58up.svg" alt="Swift 5.8+"></a>
</p>

<br>

An Object-Relational Mapper (ORM) for Swift. It allows you to write type safe, database agnostic models and queries. It takes advantage of Swift's type system to provide a powerful, yet easy to use API.

An example query looks like:

```swift
let planets = try await Planet.query(on: database)
.filter(\.$type == .gasGiant)
.sort(\.$name)
.with(\.$star)
.all()
```

For more information, see the [Fluent documentation](https://docs.vapor.codes/fluent/overview/).
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import FluentKit
import Foundation
import NIOCore

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

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

Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentBenchmark/SolarSystem/Galaxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
import NIOCore
import XCTest

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

@ID(key: .id)
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentBenchmark/SolarSystem/Governor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
import NIOCore
import XCTest

public final class Governor: Model {
public final class Governor: Model, @unchecked Sendable {
public static let schema = "governors"

@ID(key: .id)
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentBenchmark/SolarSystem/Jurisdiction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
import NIOCore
import XCTest

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

@ID(key: .id)
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentBenchmark/SolarSystem/Moon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import FluentKit
import Foundation
import NIOCore

public final class Moon: Model {
public final class Moon: Model, @unchecked Sendable {
public static let schema = "moons"

@ID(key: .id)
Expand Down
Loading

0 comments on commit 4fffbaa

Please sign in to comment.