Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Ensure curl is available
run: apt-get update -y && apt-get install -y curl
- name: Check out code
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Run unit tests
env:
TRAITS_FLAG: ${{ matrix.swift == 'swift:6.1-noble' && '--enable-all-traits' || '' }}
Expand All @@ -47,7 +47,7 @@ jobs:
with:
xcode-version: ${{ matrix.xcode-version }}
- name: Check out code
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Run unit tests
run: |
swift test --enable-code-coverage -Xswiftc -warnings-as-errors --enable-all-traits
Expand Down
9 changes: 5 additions & 4 deletions Sources/FluentKitExtras/OptionalPointerProperty.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ extension Model {
public typealias OptionalPointer<To, ToProp> = OptionalPointerProperty<Self, To, ToProp>
where
To: FluentKit.Model,
ToProp: QueryableProperty, ToProp.Model == To, ToProp.Value: Hashable
ToProp: FluentKit.QueryableProperty & _SQLKitExtrasSendableMetatype,
ToProp.Model == To, ToProp.Value: Hashable
}

// MARK: Type
Expand All @@ -30,7 +31,7 @@ extension Model {
public final class OptionalPointerProperty<From, To, ToProp>: @unchecked Sendable
where
From: FluentKit.Model, To: FluentKit.Model,
ToProp: QueryableProperty, ToProp.Model == To, ToProp.Value: Hashable
ToProp: FluentKit.QueryableProperty & _SQLKitExtrasSendableMetatype, ToProp.Model == To, ToProp.Value: Hashable
{
@OptionalFieldProperty<From, ToProp.Value>
public var ref: ToProp.Value?
Expand Down Expand Up @@ -185,7 +186,7 @@ extension OptionalPointerProperty: EagerLoadable {
private struct OptionalPointerEagerLoader<From, To, ToProp>: EagerLoader
where
From: FluentKit.Model, To: FluentKit.Model,
ToProp: FluentKit.QueryableProperty, ToProp.Model == To, ToProp.Value: Hashable
ToProp: FluentKit.QueryableProperty & _SQLKitExtrasSendableMetatype, ToProp.Model == To, ToProp.Value: Hashable
{
// Needed because the extension that normally adds this inside FluentKit is not public.
func anyRun(models: [any AnyModel], on database: any Database) -> EventLoopFuture<Void> {
Expand Down Expand Up @@ -236,7 +237,7 @@ private struct ThroughOptionalPointerEagerLoader<From, Through, ThroughProp, Loa
where
From: FluentKit.Model,
Loader: EagerLoader, Loader.Model == Through,
ThroughProp: QueryableProperty, ThroughProp.Model == Through, ThroughProp.Value: Hashable
ThroughProp: QueryableProperty & _SQLKitExtrasSendableMetatype, ThroughProp.Model == Through, ThroughProp.Value: Hashable
{
// Needed because the extension that normally adds this inside FluentKit is not public.
func anyRun(models: [any AnyModel], on database: any Database) -> EventLoopFuture<Void> {
Expand Down
10 changes: 6 additions & 4 deletions Sources/FluentKitExtras/OptionalReferenceProperty.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extension Model {
public typealias OptionalReference<To, FromProp> = OptionalReferenceProperty<Self, To, FromProp>
where
To: FluentKit.Model,
FromProp: QueryableProperty, FromProp.Model == Self, FromProp.Value: Hashable
FromProp: FluentKit.QueryableProperty & _SQLKitExtrasSendableMetatype, FromProp.Model == Self, FromProp.Value: Hashable
}

// MARK: Type
Expand All @@ -22,7 +22,7 @@ extension Model {
@propertyWrapper
public final class OptionalReferenceProperty<From, To, FromProp>: @unchecked Sendable
where From: FluentKit.Model, To: FluentKit.Model,
FromProp: QueryableProperty, FromProp.Model == From, FromProp.Value: Hashable
FromProp: FluentKit.QueryableProperty & _SQLKitExtrasSendableMetatype, FromProp.Model == From, FromProp.Value: Hashable
{
public let parentKey: RelationPointerKey<From, To, FromProp>
let fromKeypath: KeyPath<From, FromProp>
Expand Down Expand Up @@ -229,7 +229,8 @@ extension OptionalReferenceProperty: EagerLoadable {
private struct OptionalReferenceEagerLoader<From, To, FromProp>: EagerLoader
where
From: FluentKit.Model, To: FluentKit.Model,
FromProp: QueryableProperty, FromProp.Model == From, FromProp.Value: Hashable
FromProp: FluentKit.QueryableProperty & _SQLKitExtrasSendableMetatype,
FromProp.Model == From, FromProp.Value: Hashable
{
// Needed because the extension that normally adds this inside FluentKit is not public.
func anyRun(models: [any AnyModel], on database: any Database) -> EventLoopFuture<Void> {
Expand Down Expand Up @@ -270,7 +271,8 @@ private struct OptionalReferenceEagerLoader<From, To, FromProp>: EagerLoader
private struct ThroughReferenceEagerLoader<From, Through, FromProp, Loader>: EagerLoader
where
From: FluentKit.Model,
Loader: EagerLoader, Loader.Model == Through, FromProp: QueryableProperty, FromProp.Model == From, FromProp.Value: Hashable
Loader: EagerLoader, Loader.Model == Through, FromProp: FluentKit.QueryableProperty & _SQLKitExtrasSendableMetatype,
FromProp.Model == From, FromProp.Value: Hashable
{
// Needed because the extension that normally adds this inside FluentKit is not public.
func anyRun(models: [any AnyModel], on database: any Database) -> EventLoopFuture<Void> {
Expand Down
9 changes: 5 additions & 4 deletions Sources/FluentKitExtras/PointerProperty.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ extension Model {
public typealias Pointer<To, ToProp> = PointerProperty<Self, To, ToProp>
where
To: FluentKit.Model,
ToProp: QueryableProperty, ToProp.Model == To, ToProp.Value: Hashable
ToProp: FluentKit.QueryableProperty & _SQLKitExtrasSendableMetatype,
ToProp.Model == To, ToProp.Value: Hashable
}

// MARK: Type
Expand All @@ -29,7 +30,7 @@ extension Model {
@propertyWrapper
public final class PointerProperty<From, To, ToProp>: @unchecked Sendable
where From: FluentKit.Model, To: FluentKit.Model,
ToProp: QueryableProperty, ToProp.Model == To, ToProp.Value: Hashable
ToProp: FluentKit.QueryableProperty & _SQLKitExtrasSendableMetatype, ToProp.Model == To, ToProp.Value: Hashable
{
@FieldProperty<From, ToProp.Value>
public var ref: ToProp.Value
Expand Down Expand Up @@ -184,7 +185,7 @@ extension PointerProperty: EagerLoadable {
private struct PointerEagerLoader<From, To, ToProp>: EagerLoader
where
From: FluentKit.Model, To: FluentKit.Model,
ToProp: FluentKit.QueryableProperty, ToProp.Model == To, ToProp.Value: Hashable
ToProp: FluentKit.QueryableProperty & _SQLKitExtrasSendableMetatype, ToProp.Model == To, ToProp.Value: Hashable
{
// Needed because the extension that normally adds this inside FluentKit is not public.
func anyRun(models: [any AnyModel], on database: any Database) -> EventLoopFuture<Void> {
Expand Down Expand Up @@ -222,7 +223,7 @@ private struct ThroughPointerEagerLoader<From, Through, ThroughProp, Loader>: Ea
where
From: FluentKit.Model,
Loader: EagerLoader, Loader.Model == Through,
ThroughProp: QueryableProperty, ThroughProp.Model == Through, ThroughProp.Value: Hashable
ThroughProp: QueryableProperty & _SQLKitExtrasSendableMetatype, ThroughProp.Model == Through, ThroughProp.Value: Hashable
{
// Needed because the extension that normally adds this inside FluentKit is not public.
func anyRun(models: [any AnyModel], on database: any Database) -> EventLoopFuture<Void> {
Expand Down
10 changes: 6 additions & 4 deletions Sources/FluentKitExtras/ReferencesProperty.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ extension Model {
public typealias References<To, FromProp> = ReferencesProperty<Self, To, FromProp>
where
To: FluentKit.Model,
FromProp: QueryableProperty, FromProp.Model == Self, FromProp.Value: Hashable
FromProp: FluentKit.QueryableProperty & _SQLKitExtrasSendableMetatype,
FromProp.Model == Self, FromProp.Value: Hashable
}

// MARK: Type
Expand All @@ -23,7 +24,7 @@ extension Model {
public final class ReferencesProperty<From, To, FromProp>: @unchecked Sendable
where
From: FluentKit.Model, To: FluentKit.Model,
FromProp: QueryableProperty, FromProp.Model == From, FromProp.Value: Hashable
FromProp: FluentKit.QueryableProperty & _SQLKitExtrasSendableMetatype, FromProp.Model == From, FromProp.Value: Hashable
{
public let parentKey: RelationPointerKey<From, To, FromProp>
let fromKeypath: KeyPath<From, FromProp>
Expand Down Expand Up @@ -243,7 +244,7 @@ extension ReferencesProperty: EagerLoadable {
private struct ReferencesEagerLoader<From, To, FromProp>: EagerLoader
where
From: FluentKit.Model, To: FluentKit.Model,
FromProp: QueryableProperty, FromProp.Model == From, FromProp.Value: Hashable
FromProp: FluentKit.QueryableProperty & _SQLKitExtrasSendableMetatype, FromProp.Model == From, FromProp.Value: Hashable
{
// Needed because the extension that normally adds this inside FluentKit is not public.
func anyRun(models: [any AnyModel], on database: any Database) -> EventLoopFuture<Void> {
Expand Down Expand Up @@ -282,7 +283,8 @@ private struct ReferencesEagerLoader<From, To, FromProp>: EagerLoader
private struct ThroughReferencesEagerLoader<From, Through, FromProp, Loader>: EagerLoader
where
From: FluentKit.Model,
Loader: EagerLoader, Loader.Model == Through, FromProp: QueryableProperty, FromProp.Model == From, FromProp.Value: Hashable
Loader: EagerLoader, Loader.Model == Through, FromProp: FluentKit.QueryableProperty & _SQLKitExtrasSendableMetatype,
FromProp.Model == From, FromProp.Value: Hashable
{
// Needed because the extension that normally adds this inside FluentKit is not public.
func anyRun(models: [any AnyModel], on database: any Database) -> EventLoopFuture<Void> {
Expand Down
3 changes: 2 additions & 1 deletion Sources/FluentKitExtras/RelationPointerKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import FluentKit
public enum RelationPointerKey<From, To, FromProp>: Sendable
where
From: FluentKit.Model, To: FluentKit.Model,
FromProp: QueryableProperty, FromProp.Model == From, FromProp.Value: Hashable
FromProp: FluentKit.QueryableProperty & _SQLKitExtrasSendableMetatype,
FromProp.Model == From, FromProp.Value: Hashable
{
case required(KeyPath<To, To.Pointer<From, FromProp>>)
case optional(KeyPath<To, To.OptionalPointer<From, FromProp>>)
Expand Down
9 changes: 9 additions & 0 deletions Sources/FluentKitExtras/SwiftCompatibility.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import FluentKit

#if compiler(>=6.2)
@_marker public protocol _SQLKitExtrasSendableMetatype: SendableMetatype {}
#else
@_marker public protocol _SQLKitExtrasSendableMetatype {}
#endif

extension FluentKit.FieldProperty: _SQLKitExtrasSendableMetatype {}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ extension SQLJoinBuilder {
method: SQLJoinMethod = .inner,
on expression: some SQLExpression
) -> Self {
if let alias = alias.map(String.init(_:)) ?? type.alias {
if let alias = alias.map({ String($0) }) ?? type.alias {
self.join(.table(type.schema, space: type.space), as: alias, method: method, on: expression)
} else {
self.join(.table(type.schema, space: type.space), method: method, on: expression)
Expand Down Expand Up @@ -76,7 +76,7 @@ extension SQLJoinBuilder {
method: SQLJoinMethod = .inner,
using columns: some Sequence<any SQLExpression>
) -> Self {
if let alias = alias.map(String.init(_:)) ?? type.alias {
if let alias = alias.map({ String($0) }) ?? type.alias {
self.join(.table(type.schema, space: type.space), as: alias, method: method, using: columns)
} else {
self.join(.table(type.schema, space: type.space), method: method, using: .list(columns))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#if FluentSQLKitExtras
Copy link

Choose a reason for hiding this comment

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

Didn't remember you're already using package traits

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, this package was my very first use of traits. Still my only one so far, in fact.

import FluentKit
import SQLKit

extension SQLQueryString {
/// Allow specifying a Fluent keypath as an identifier interpolation in an `SQLQueryString`.
@inlinable
public mutating func appendInterpolation(ident: KeyPath<some Schema, some QueryAddressableProperty>) {
self.appendInterpolation(.identifier(ident))
}

/// Allow specifying a Fluent keypath as an column interpolation in an `SQLQueryString`.
@inlinable
public mutating func appendInterpolation(col: KeyPath<some Schema, some QueryAddressableProperty>) {
self.appendInterpolation(.column(col))
}
}
#endif

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extension SQLExpression {
_ name: some StringProtocol,
table: (some StringProtocol)? = String?.none
) -> Self where Self == SQLColumn {
.init(String(name), table: table.map(String.init(_:)))
.init(String(name), table: table.map { String($0) })
}

/// A convenience method for creating an `SQLColumn` from a column name and table expression.
Expand Down
6 changes: 6 additions & 0 deletions Tests/SQLKitExtrasTests/FluentSQLKitExtrasTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ struct FluentSQLKitExtrasTests {
#expect(MockSQLDatabase(dialect: "mysql").serialize(.cast(\FooModel.$field, to: "text")).sql == #"CAST("foos"."field" AS text)"#)
#expect(MockSQLDatabase(dialect: "postgresql").serialize(.cast(\FooModel.$field, to: "text")).sql == #"CAST("foos"."field" AS "text")"#)
}

@Test
func queryStringExpression() {
#expect(serialize("foo \(ident: \FooModel.$field) bar" as SQLQueryString) == #"foo "field" bar"#)
#expect(serialize("foo \(col: \FooModel.$field) bar" as SQLQueryString) == #"foo "foos"."field" bar"#)
}
}
}

Expand Down