Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primary Sendable support for Fluent #601

Merged
merged 28 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a11f4bb
Bump min Swift to 5.8, add feature flags
gwynne Apr 19, 2024
e484211
Some minor code cleanup
gwynne Apr 19, 2024
90d7152
Various more or less isolated Sendable corrections
gwynne Apr 19, 2024
898f4bc
Mark as many things Sendable as we can
gwynne Apr 19, 2024
65f3430
Make QueryBuilder Sendable-safe
gwynne Apr 19, 2024
36a69a6
Make EnumBuilder fake-Sendable-safe for now
gwynne Apr 19, 2024
93807bd
Package structure and CI updates
gwynne Apr 23, 2024
0cd440c
Make EnumBuilder actually Sendable
gwynne Apr 23, 2024
c8f1583
Lots more Sendability
gwynne Apr 23, 2024
7334fb8
MirrorBypass is valid in 5.10 (looks like it'll be valid in 6.0 too, …
gwynne Apr 23, 2024
020927b
Make all the Fluent property wrappers as Sendable as they can be. Thi…
gwynne Apr 23, 2024
e496243
SomeCodingKey is now provided by SQLKit
gwynne Apr 23, 2024
57e6576
Remove old compiler condition
gwynne Apr 23, 2024
260d36d
Fix coverage CI
gwynne Apr 23, 2024
deaff9e
Make DatabaseDriver, DatabaseConfiguration, DatabaseConfigurationFact…
gwynne Apr 23, 2024
f70b62d
Remove locking from the property wrappers, just let them be unchecked…
gwynne Apr 23, 2024
4900e77
A few more Sendables that were missed.
gwynne Apr 23, 2024
eb505f0
Add the missing utilities for encoding Fluent models to SQLKit queries
gwynne Apr 23, 2024
40a18cb
Make benchmarks and tests Sendable
gwynne Apr 23, 2024
d50e8cc
Minor code and docs cleanup
gwynne Apr 24, 2024
52bf884
Update the fake database used for testing to be more flexible and fix…
gwynne Apr 26, 2024
91b62b8
Add tests for new FluentSQL APIs
gwynne Apr 26, 2024
1097e50
Fix Swift<5.10 build
gwynne Apr 26, 2024
bebc4da
Fix chunk test
gwynne Apr 26, 2024
459950e
Remove the last few uses of print() (all in tests)
gwynne Apr 26, 2024
929ee98
Remove unneeded @unchecked Sendable usage
gwynne Apr 26, 2024
d0a83ca
Fix locking of QueryHistory
gwynne Apr 26, 2024
ad1ead6
JSONDecoder's behavior here apparently changes on Linux, so don't do …
gwynne Apr 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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
Loading