diff --git a/.swiftformat b/.swiftformat index b7c1330..40707df 100644 --- a/.swiftformat +++ b/.swiftformat @@ -1,8 +1,8 @@ --extensionacl on-declarations --header strip ---maxwidth 100 +--maxwidth 140 --self insert ---swiftversion 5.5 +--swiftversion 5.10 --wraparguments before-first --wrapcollections before-first --wrapparameters before-first diff --git a/Package.swift b/Package.swift index 1ca8cba..f8d4fbf 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.9 +// swift-tools-version:5.10 import PackageDescription let package = Package( @@ -7,11 +7,11 @@ let package = Package( .macOS(.v12), ], products: [ - .library( name: "FluentPostGIS", targets: ["FluentPostGIS"] ), + .library(name: "FluentPostGIS", targets: ["FluentPostGIS"]), ], dependencies: [ - .package(url: "https://github.com/vapor/fluent-kit.git", from: "1.49.0"), - .package(url: "https://github.com/vapor/fluent-postgres-driver.git", from: "2.10.0"), + .package(url: "https://github.com/vapor/fluent-kit.git", from: "1.52.2"), + .package(url: "https://github.com/vapor/fluent-postgres-driver.git", from: "2.10.1"), .package(url: "https://github.com/rabc/WKCodable.git", from: "0.1.2"), ], targets: [ @@ -21,14 +21,25 @@ let package = Package( .product(name: "FluentKit", package: "fluent-kit"), .product(name: "FluentPostgresDriver", package: "fluent-postgres-driver"), .product(name: "WKCodable", package: "WKCodable"), - ] + ], + swiftSettings: swiftSettings ), .testTarget( name: "FluentPostGISTests", dependencies: [ .target(name: "FluentPostGIS"), .product(name: "FluentBenchmark", package: "fluent-kit"), - ] + ], + swiftSettings: swiftSettings ), ] ) + +var swiftSettings: [SwiftSetting] { [ + .enableUpcomingFeature("ExistentialAny"), + .enableUpcomingFeature("ConciseMagicFile"), + .enableUpcomingFeature("ForwardTrailingClosures"), + .enableUpcomingFeature("DisableOutwardActorInference"), + .enableUpcomingFeature("StrictConcurrency"), + .enableExperimentalFeature("StrictConcurrency=complete"), +] } diff --git a/README.md b/README.md index f8d1a89..b951109 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ app.migrations.add(EnablePostGISMigration()) Add a type to your model ```swift -final class User: Model { +final class User: Model, @unchecked Sendable { static let schema = "user" @ID(key: .id) diff --git a/Sources/FluentPostGIS/Geography/GeographicGeometryCollection2D.swift b/Sources/FluentPostGIS/Geography/GeographicGeometryCollection2D.swift index eafc4e1..002d206 100644 --- a/Sources/FluentPostGIS/Geography/GeographicGeometryCollection2D.swift +++ b/Sources/FluentPostGIS/Geography/GeographicGeometryCollection2D.swift @@ -1,12 +1,12 @@ import FluentKit import WKCodable -public struct GeographicGeometryCollection2D: Codable, Equatable, CustomStringConvertible { +public struct GeographicGeometryCollection2D: Codable, Equatable, CustomStringConvertible, Sendable { /// The points - public let geometries: [GeometryCollectable] + public let geometries: [any GeometryCollectable] /// Create a new `GISGeographicGeometryCollection2D` - public init(geometries: [GeometryCollectable]) { + public init(geometries: [any GeometryCollectable]) { self.geometries = geometries } } @@ -43,17 +43,17 @@ extension GeographicGeometryCollection2D: GeometryConvertible, GeometryCollectab return .init(geometries: geometries, srid: FluentPostGISSrid) } - public var baseGeometry: Geometry { + public var baseGeometry: any Geometry { self.geometry } - public init(from decoder: Decoder) throws { + public init(from decoder: any Decoder) throws { let value = try decoder.singleValueContainer().decode(String.self) let wkbGeometry: GeometryCollection = try WKTDecoder().decode(from: value) self.init(geometry: wkbGeometry) } - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { let wktEncoder = WKTEncoder() let value = wktEncoder.encode(self.geometry) var container = encoder.singleValueContainer() diff --git a/Sources/FluentPostGIS/Geography/GeographicLineString2D.swift b/Sources/FluentPostGIS/Geography/GeographicLineString2D.swift index 918c272..2e6c138 100644 --- a/Sources/FluentPostGIS/Geography/GeographicLineString2D.swift +++ b/Sources/FluentPostGIS/Geography/GeographicLineString2D.swift @@ -1,7 +1,7 @@ import FluentKit import WKCodable -public struct GeographicLineString2D: Codable, Equatable, CustomStringConvertible { +public struct GeographicLineString2D: Codable, Equatable, CustomStringConvertible, Sendable { /// The points public var points: [GeographicPoint2D] @@ -24,7 +24,7 @@ extension GeographicLineString2D: GeometryConvertible, GeometryCollectable { .init(points: self.points.map(\.geometry), srid: FluentPostGISSrid) } - public var baseGeometry: Geometry { + public var baseGeometry: any Geometry { self.geometry } } diff --git a/Sources/FluentPostGIS/Geography/GeographicMultiLineString2D.swift b/Sources/FluentPostGIS/Geography/GeographicMultiLineString2D.swift index 86052c8..74654f8 100644 --- a/Sources/FluentPostGIS/Geography/GeographicMultiLineString2D.swift +++ b/Sources/FluentPostGIS/Geography/GeographicMultiLineString2D.swift @@ -1,7 +1,7 @@ import FluentKit import WKCodable -public struct GeographicMultiLineString2D: Codable, Equatable, CustomStringConvertible { +public struct GeographicMultiLineString2D: Codable, Equatable, CustomStringConvertible, Sendable { /// The points public let lineStrings: [GeographicLineString2D] @@ -25,7 +25,7 @@ extension GeographicMultiLineString2D: GeometryConvertible, GeometryCollectable return .init(lineStrings: lineStrings, srid: FluentPostGISSrid) } - public var baseGeometry: Geometry { + public var baseGeometry: any Geometry { self.geometry } } diff --git a/Sources/FluentPostGIS/Geography/GeographicMultiPoint2D.swift b/Sources/FluentPostGIS/Geography/GeographicMultiPoint2D.swift index af18549..72629c6 100644 --- a/Sources/FluentPostGIS/Geography/GeographicMultiPoint2D.swift +++ b/Sources/FluentPostGIS/Geography/GeographicMultiPoint2D.swift @@ -1,7 +1,7 @@ import FluentKit import WKCodable -public struct GeographicMultiPoint2D: Codable, Equatable, CustomStringConvertible { +public struct GeographicMultiPoint2D: Codable, Equatable, CustomStringConvertible, Sendable { /// The points public var points: [GeographicPoint2D] @@ -24,7 +24,7 @@ extension GeographicMultiPoint2D: GeometryConvertible, GeometryCollectable { .init(points: self.points.map(\.geometry), srid: FluentPostGISSrid) } - public var baseGeometry: Geometry { + public var baseGeometry: any Geometry { self.geometry } } diff --git a/Sources/FluentPostGIS/Geography/GeographicMultiPolygon2D.swift b/Sources/FluentPostGIS/Geography/GeographicMultiPolygon2D.swift index 08f8e07..9fd4fe6 100644 --- a/Sources/FluentPostGIS/Geography/GeographicMultiPolygon2D.swift +++ b/Sources/FluentPostGIS/Geography/GeographicMultiPolygon2D.swift @@ -1,7 +1,7 @@ import FluentKit import WKCodable -public struct GeographicMultiPolygon2D: Codable, Equatable, CustomStringConvertible { +public struct GeographicMultiPolygon2D: Codable, Equatable, CustomStringConvertible, Sendable { /// The points public let polygons: [GeographicPolygon2D] @@ -25,7 +25,7 @@ extension GeographicMultiPolygon2D: GeometryConvertible, GeometryCollectable { return .init(polygons: polygons, srid: FluentPostGISSrid) } - public var baseGeometry: Geometry { + public var baseGeometry: any Geometry { self.geometry } } diff --git a/Sources/FluentPostGIS/Geography/GeographicPoint2D.swift b/Sources/FluentPostGIS/Geography/GeographicPoint2D.swift index 9541066..97d224d 100644 --- a/Sources/FluentPostGIS/Geography/GeographicPoint2D.swift +++ b/Sources/FluentPostGIS/Geography/GeographicPoint2D.swift @@ -1,7 +1,7 @@ import FluentKit import WKCodable -public struct GeographicPoint2D: Codable, Equatable, CustomStringConvertible { +public struct GeographicPoint2D: Codable, Equatable, CustomStringConvertible, Sendable { /// The point's x coordinate. public var longitude: Double @@ -27,7 +27,7 @@ extension GeographicPoint2D: GeometryConvertible, GeometryCollectable { .init(vector: [self.longitude, self.latitude], srid: FluentPostGISSrid) } - public var baseGeometry: Geometry { + public var baseGeometry: any Geometry { self.geometry } } diff --git a/Sources/FluentPostGIS/Geography/GeographicPolygon2D.swift b/Sources/FluentPostGIS/Geography/GeographicPolygon2D.swift index af36b77..601570f 100644 --- a/Sources/FluentPostGIS/Geography/GeographicPolygon2D.swift +++ b/Sources/FluentPostGIS/Geography/GeographicPolygon2D.swift @@ -1,7 +1,7 @@ import FluentKit import WKCodable -public struct GeographicPolygon2D: Codable, Equatable, CustomStringConvertible { +public struct GeographicPolygon2D: Codable, Equatable, CustomStringConvertible, Sendable { /// The points public let exteriorRing: GeographicLineString2D public let interiorRings: [GeographicLineString2D] @@ -37,7 +37,7 @@ extension GeographicPolygon2D: GeometryConvertible, GeometryCollectable { ) } - public var baseGeometry: Geometry { + public var baseGeometry: any Geometry { self.geometry } } diff --git a/Sources/FluentPostGIS/Geometry/GeometricGeometryCollection2D.swift b/Sources/FluentPostGIS/Geometry/GeometricGeometryCollection2D.swift index caece2e..5253013 100644 --- a/Sources/FluentPostGIS/Geometry/GeometricGeometryCollection2D.swift +++ b/Sources/FluentPostGIS/Geometry/GeometricGeometryCollection2D.swift @@ -1,12 +1,12 @@ import FluentKit import WKCodable -public struct GeometricGeometryCollection2D: Codable, Equatable, CustomStringConvertible { +public struct GeometricGeometryCollection2D: Codable, Equatable, CustomStringConvertible, Sendable { /// The points - public let geometries: [GeometryCollectable] + public let geometries: [any GeometryCollectable] /// Create a new `GISGeometricGeometryCollection2D` - public init(geometries: [GeometryCollectable]) { + public init(geometries: [any GeometryCollectable]) { self.geometries = geometries } } @@ -42,7 +42,7 @@ extension GeometricGeometryCollection2D: GeometryConvertible, GeometryCollectabl return .init(geometries: geometries, srid: FluentPostGISSrid) } - public var baseGeometry: Geometry { + public var baseGeometry: any Geometry { self.geometry } diff --git a/Sources/FluentPostGIS/Geometry/GeometricLineString2D.swift b/Sources/FluentPostGIS/Geometry/GeometricLineString2D.swift index b9e71fc..f1e8afd 100644 --- a/Sources/FluentPostGIS/Geometry/GeometricLineString2D.swift +++ b/Sources/FluentPostGIS/Geometry/GeometricLineString2D.swift @@ -1,7 +1,7 @@ import FluentKit import WKCodable -public struct GeometricLineString2D: Codable, Equatable, CustomStringConvertible { +public struct GeometricLineString2D: Codable, Equatable, CustomStringConvertible, Sendable { /// The points public var points: [GeometricPoint2D] @@ -24,7 +24,7 @@ extension GeometricLineString2D: GeometryConvertible, GeometryCollectable { .init(points: self.points.map(\.geometry), srid: FluentPostGISSrid) } - public var baseGeometry: Geometry { + public var baseGeometry: any Geometry { self.geometry } } diff --git a/Sources/FluentPostGIS/Geometry/GeometricMultiLineString2D.swift b/Sources/FluentPostGIS/Geometry/GeometricMultiLineString2D.swift index ee0d8b0..c651309 100644 --- a/Sources/FluentPostGIS/Geometry/GeometricMultiLineString2D.swift +++ b/Sources/FluentPostGIS/Geometry/GeometricMultiLineString2D.swift @@ -1,7 +1,7 @@ import FluentKit import WKCodable -public struct GeometricMultiLineString2D: Codable, Equatable, CustomStringConvertible { +public struct GeometricMultiLineString2D: Codable, Equatable, CustomStringConvertible, Sendable { /// The points public let lineStrings: [GeometricLineString2D] @@ -25,7 +25,7 @@ extension GeometricMultiLineString2D: GeometryConvertible, GeometryCollectable { return .init(lineStrings: lineStrings, srid: FluentPostGISSrid) } - public var baseGeometry: Geometry { + public var baseGeometry: any Geometry { self.geometry } } diff --git a/Sources/FluentPostGIS/Geometry/GeometricMultiPoint2D.swift b/Sources/FluentPostGIS/Geometry/GeometricMultiPoint2D.swift index 9ee7ed0..f0a0652 100644 --- a/Sources/FluentPostGIS/Geometry/GeometricMultiPoint2D.swift +++ b/Sources/FluentPostGIS/Geometry/GeometricMultiPoint2D.swift @@ -1,7 +1,7 @@ import FluentKit import WKCodable -public struct GeometricMultiPoint2D: Codable, Equatable, CustomStringConvertible { +public struct GeometricMultiPoint2D: Codable, Equatable, CustomStringConvertible, Sendable { /// The points public var points: [GeometricPoint2D] @@ -24,7 +24,7 @@ extension GeometricMultiPoint2D: GeometryConvertible, GeometryCollectable { MultiPoint(points: self.points.map(\.geometry), srid: FluentPostGISSrid) } - public var baseGeometry: Geometry { + public var baseGeometry: any Geometry { self.geometry } } diff --git a/Sources/FluentPostGIS/Geometry/GeometricMultiPolygon2D.swift b/Sources/FluentPostGIS/Geometry/GeometricMultiPolygon2D.swift index 7502985..082cac3 100644 --- a/Sources/FluentPostGIS/Geometry/GeometricMultiPolygon2D.swift +++ b/Sources/FluentPostGIS/Geometry/GeometricMultiPolygon2D.swift @@ -1,7 +1,7 @@ import FluentKit import WKCodable -public struct GeometricMultiPolygon2D: Codable, Equatable, CustomStringConvertible { +public struct GeometricMultiPolygon2D: Codable, Equatable, CustomStringConvertible, Sendable { /// The points public let polygons: [GeometricPolygon2D] @@ -25,7 +25,7 @@ extension GeometricMultiPolygon2D: GeometryConvertible, GeometryCollectable { return .init(polygons: polygons, srid: FluentPostGISSrid) } - public var baseGeometry: Geometry { + public var baseGeometry: any Geometry { self.geometry } } diff --git a/Sources/FluentPostGIS/Geometry/GeometricPoint2D.swift b/Sources/FluentPostGIS/Geometry/GeometricPoint2D.swift index 73a0a27..3e033b8 100644 --- a/Sources/FluentPostGIS/Geometry/GeometricPoint2D.swift +++ b/Sources/FluentPostGIS/Geometry/GeometricPoint2D.swift @@ -1,7 +1,7 @@ import FluentKit import WKCodable -public struct GeometricPoint2D: Codable, Equatable, CustomStringConvertible { +public struct GeometricPoint2D: Codable, Equatable, CustomStringConvertible, Sendable { /// The point's x coordinate. public var x: Double @@ -27,7 +27,7 @@ extension GeometricPoint2D: GeometryConvertible, GeometryCollectable { .init(vector: [self.x, self.y], srid: FluentPostGISSrid) } - public var baseGeometry: Geometry { + public var baseGeometry: any Geometry { self.geometry } } diff --git a/Sources/FluentPostGIS/Geometry/GeometricPolygon2D.swift b/Sources/FluentPostGIS/Geometry/GeometricPolygon2D.swift index 597dd4d..602fe71 100644 --- a/Sources/FluentPostGIS/Geometry/GeometricPolygon2D.swift +++ b/Sources/FluentPostGIS/Geometry/GeometricPolygon2D.swift @@ -1,7 +1,7 @@ import FluentKit import WKCodable -public struct GeometricPolygon2D: Codable, Equatable, CustomStringConvertible { +public struct GeometricPolygon2D: Codable, Equatable, CustomStringConvertible, Sendable { /// The points public let exteriorRing: GeometricLineString2D public let interiorRings: [GeometricLineString2D] @@ -37,7 +37,7 @@ extension GeometricPolygon2D: GeometryConvertible, GeometryCollectable { ) } - public var baseGeometry: Geometry { + public var baseGeometry: any Geometry { self.geometry } } diff --git a/Sources/FluentPostGIS/Geometry/GeometryConvertible.swift b/Sources/FluentPostGIS/Geometry/GeometryConvertible.swift index e1e1531..a2f4f82 100644 --- a/Sources/FluentPostGIS/Geometry/GeometryConvertible.swift +++ b/Sources/FluentPostGIS/Geometry/GeometryConvertible.swift @@ -2,12 +2,12 @@ import FluentKit import Foundation import WKCodable -public protocol GeometryCollectable { - var baseGeometry: Geometry { get } +public protocol GeometryCollectable: Sendable { + var baseGeometry: any Geometry { get } func isEqual(to other: Any?) -> Bool } -public protocol GeometryConvertible { +public protocol GeometryConvertible: Sendable { associatedtype GeometryType: Geometry init(geometry: GeometryType) var geometry: GeometryType { get } @@ -27,14 +27,14 @@ extension GeometryConvertible where Self: CustomStringConvertible { } extension GeometryConvertible { - public init(from decoder: Decoder) throws { + public init(from decoder: any Decoder) throws { let value = try decoder.singleValueContainer().decode(Data.self) let decoder = WKBDecoder() let geometry: GeometryType = try decoder.decode(from: value) self.init(geometry: geometry) } - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { let wkEncoder = WKBEncoder(byteOrder: .littleEndian) let data = wkEncoder.encode(geometry) diff --git a/Sources/FluentPostGIS/Queries/QueryBuilder+Contains.swift b/Sources/FluentPostGIS/Queries/QueryBuilder+Contains.swift index 0785b01..59d742d 100644 --- a/Sources/FluentPostGIS/Queries/QueryBuilder+Contains.swift +++ b/Sources/FluentPostGIS/Queries/QueryBuilder+Contains.swift @@ -49,7 +49,7 @@ extension QueryBuilder { /// - parameters: /// - field: Field to filter. /// - value: Value type. - public func filterGeometryContains(_ args: SQLExpression...) -> Self { + public func filterGeometryContains(_ args: any SQLExpression...) -> Self { self.filter(function: "ST_Contains", args: args) } } diff --git a/Sources/FluentPostGIS/Queries/QueryBuilder+Crosses.swift b/Sources/FluentPostGIS/Queries/QueryBuilder+Crosses.swift index 9a146c5..744ff53 100644 --- a/Sources/FluentPostGIS/Queries/QueryBuilder+Crosses.swift +++ b/Sources/FluentPostGIS/Queries/QueryBuilder+Crosses.swift @@ -49,7 +49,7 @@ extension QueryBuilder { /// - parameters: /// - field: Field to filter. /// - value: Value type. - public func filterGeometryCrosses(_ args: SQLExpression...) -> Self { + public func filterGeometryCrosses(_ args: any SQLExpression...) -> Self { self.filter(function: "ST_Crosses", args: args) } } diff --git a/Sources/FluentPostGIS/Queries/QueryBuilder+Disjoint.swift b/Sources/FluentPostGIS/Queries/QueryBuilder+Disjoint.swift index 8160482..8ddd5cf 100644 --- a/Sources/FluentPostGIS/Queries/QueryBuilder+Disjoint.swift +++ b/Sources/FluentPostGIS/Queries/QueryBuilder+Disjoint.swift @@ -49,7 +49,7 @@ extension QueryBuilder { /// - parameters: /// - field: Field to filter. /// - value: Value type. - public func filterGeometryDisjoint(_ args: SQLExpression...) -> Self { + public func filterGeometryDisjoint(_ args: any SQLExpression...) -> Self { self.filter(function: "ST_Disjoint", args: args) } } diff --git a/Sources/FluentPostGIS/Queries/QueryBuilder+Distance.swift b/Sources/FluentPostGIS/Queries/QueryBuilder+Distance.swift index c4c6798..e9616d3 100644 --- a/Sources/FluentPostGIS/Queries/QueryBuilder+Distance.swift +++ b/Sources/FluentPostGIS/Queries/QueryBuilder+Distance.swift @@ -22,10 +22,10 @@ extension QueryBuilder { extension QueryBuilder { public func filterGeometryDistance( - _ path: SQLExpression, - _ filter: SQLExpression, + _ path: any SQLExpression, + _ filter: any SQLExpression, _ method: SQLBinaryOperator, - _ value: SQLExpression + _ value: any SQLExpression ) -> Self { self.filter(.sql(SQLFunction("ST_Distance", args: [path, filter]), method, value)) } diff --git a/Sources/FluentPostGIS/Queries/QueryBuilder+DistanceWithin.swift b/Sources/FluentPostGIS/Queries/QueryBuilder+DistanceWithin.swift index 8f8e088..71ffee7 100644 --- a/Sources/FluentPostGIS/Queries/QueryBuilder+DistanceWithin.swift +++ b/Sources/FluentPostGIS/Queries/QueryBuilder+DistanceWithin.swift @@ -55,7 +55,7 @@ extension QueryBuilder { } extension QueryBuilder { - func filterDistanceWithin(_ args: SQLExpression...) -> Self { + func filterDistanceWithin(_ args: any SQLExpression...) -> Self { self.filter(function: "ST_DWithin", args: args) } } diff --git a/Sources/FluentPostGIS/Queries/QueryBuilder+Equals.swift b/Sources/FluentPostGIS/Queries/QueryBuilder+Equals.swift index f599b46..304fabd 100644 --- a/Sources/FluentPostGIS/Queries/QueryBuilder+Equals.swift +++ b/Sources/FluentPostGIS/Queries/QueryBuilder+Equals.swift @@ -29,7 +29,7 @@ extension QueryBuilder { /// - parameters: /// - field: Field to filter. /// - value: Value type. - public func filterGeometryEquals(_ args: SQLExpression...) -> Self { + public func filterGeometryEquals(_ args: any SQLExpression...) -> Self { self.filter(function: "ST_Equals", args: args) } } diff --git a/Sources/FluentPostGIS/Queries/QueryBuilder+Helpers.swift b/Sources/FluentPostGIS/Queries/QueryBuilder+Helpers.swift index 8af9512..846c18d 100644 --- a/Sources/FluentPostGIS/Queries/QueryBuilder+Helpers.swift +++ b/Sources/FluentPostGIS/Queries/QueryBuilder+Helpers.swift @@ -2,17 +2,17 @@ import FluentSQL import WKCodable extension QueryBuilder { - static func queryExpressionGeometry(_ geometry: T) -> SQLExpression { + static func queryExpressionGeometry(_ geometry: T) -> any SQLExpression { let geometryText = WKTEncoder().encode(geometry.geometry) return SQLFunction("ST_GeomFromEWKT", args: [SQLLiteral.string(geometryText)]) } - static func queryExpressionGeography(_ geometry: T) -> SQLExpression { + static func queryExpressionGeography(_ geometry: T) -> any SQLExpression { let geometryText = WKTEncoder().encode(geometry.geometry) return SQLFunction("ST_GeogFromText", args: [SQLLiteral.string(geometryText)]) } - static func path(_ field: KeyPath) -> SQLExpression + static func path(_ field: KeyPath) -> any SQLExpression where M: Schema, F: QueryableProperty, F.Model == M { let path = M.path(for: field).map(\.description).joined(separator: "_") @@ -21,11 +21,11 @@ extension QueryBuilder { } extension QueryBuilder { - func filter(function: String, args: [SQLExpression]) -> Self { + func filter(function: String, args: [any SQLExpression]) -> Self { self.filter(.sql(SQLFunction(function, args: args))) } - func sort(function: String, args: [SQLExpression]) -> Self { + func sort(function: String, args: [any SQLExpression]) -> Self { self.sort(.sql(SQLFunction(function, args: args))) } } diff --git a/Sources/FluentPostGIS/Queries/QueryBuilder+Intersects.swift b/Sources/FluentPostGIS/Queries/QueryBuilder+Intersects.swift index 93ef90d..e52ea85 100644 --- a/Sources/FluentPostGIS/Queries/QueryBuilder+Intersects.swift +++ b/Sources/FluentPostGIS/Queries/QueryBuilder+Intersects.swift @@ -49,7 +49,7 @@ extension QueryBuilder { /// - parameters: /// - field: Field to filter. /// - value: Value type. - public func filterGeometryIntersects(_ args: SQLExpression...) -> Self { + public func filterGeometryIntersects(_ args: any SQLExpression...) -> Self { self.filter(function: "ST_Intersects", args: args) } } diff --git a/Sources/FluentPostGIS/Queries/QueryBuilder+Overlaps.swift b/Sources/FluentPostGIS/Queries/QueryBuilder+Overlaps.swift index eb4887b..410fc3d 100644 --- a/Sources/FluentPostGIS/Queries/QueryBuilder+Overlaps.swift +++ b/Sources/FluentPostGIS/Queries/QueryBuilder+Overlaps.swift @@ -49,7 +49,7 @@ extension QueryBuilder { /// - parameters: /// - field: Field to filter. /// - value: Value type. - public func filterGeometryOverlaps(_ args: SQLExpression...) -> Self { + public func filterGeometryOverlaps(_ args: any SQLExpression...) -> Self { self.filter(function: "ST_Overlaps", args: args) } } diff --git a/Sources/FluentPostGIS/Queries/QueryBuilder+Sort.swift b/Sources/FluentPostGIS/Queries/QueryBuilder+Sort.swift index a9a3789..b2d211e 100644 --- a/Sources/FluentPostGIS/Queries/QueryBuilder+Sort.swift +++ b/Sources/FluentPostGIS/Queries/QueryBuilder+Sort.swift @@ -24,7 +24,7 @@ extension QueryBuilder { } extension QueryBuilder { - public func sortByDistance(_ args: SQLExpression...) -> Self { + public func sortByDistance(_ args: any SQLExpression...) -> Self { self.sort(function: "ST_Distance", args: args) } } diff --git a/Sources/FluentPostGIS/Queries/QueryBuilder+Touches.swift b/Sources/FluentPostGIS/Queries/QueryBuilder+Touches.swift index c6b305e..25fbc15 100644 --- a/Sources/FluentPostGIS/Queries/QueryBuilder+Touches.swift +++ b/Sources/FluentPostGIS/Queries/QueryBuilder+Touches.swift @@ -49,7 +49,7 @@ extension QueryBuilder { /// - parameters: /// - field: Field to filter. /// - value: Value type. - public func filterGeometryTouches(_ args: SQLExpression...) -> Self { + public func filterGeometryTouches(_ args: any SQLExpression...) -> Self { self.filter(function: "ST_Touches", args: args) } } diff --git a/Sources/FluentPostGIS/Queries/QueryBuilder+Within.swift b/Sources/FluentPostGIS/Queries/QueryBuilder+Within.swift index bfe66f8..48d6e82 100644 --- a/Sources/FluentPostGIS/Queries/QueryBuilder+Within.swift +++ b/Sources/FluentPostGIS/Queries/QueryBuilder+Within.swift @@ -49,7 +49,7 @@ extension QueryBuilder { /// - parameters: /// - field: Field to filter. /// - value: Value type. - public func filterGeometryWithin(_ args: SQLExpression...) -> Self { + public func filterGeometryWithin(_ args: any SQLExpression...) -> Self { self.filter(function: "ST_Within", args: args) } } diff --git a/Sources/FluentPostGIS/Support/EnablePostGISMigration.swift b/Sources/FluentPostGIS/Support/EnablePostGISMigration.swift index 01a40cb..c0ffb8a 100644 --- a/Sources/FluentPostGIS/Support/EnablePostGISMigration.swift +++ b/Sources/FluentPostGIS/Support/EnablePostGISMigration.swift @@ -1,26 +1,26 @@ import FluentKit import SQLKit -public struct EnablePostGISMigration: AsyncMigration { +public struct EnablePostGISMigration: AsyncMigration, Sendable { public init() {} - public enum EnablePostGISMigrationError: Error { + public enum EnablePostGISMigrationError: Error, Sendable { case notSqlDatabase } - public func prepare(on database: Database) async throws { - guard let db = database as? SQLDatabase else { + public func prepare(on database: any Database) async throws { + guard let db = database as? any SQLDatabase else { throw EnablePostGISMigrationError.notSqlDatabase } try await db.raw("CREATE EXTENSION IF NOT EXISTS \"postgis\"").run() } - public func revert(on database: Database) async throws { - guard let db = database as? SQLDatabase else { + public func revert(on database: any Database) async throws { + guard let db = database as? any SQLDatabase else { throw EnablePostGISMigrationError.notSqlDatabase } try await db.raw("DROP EXTENSION IF EXISTS \"postgis\"").run() } } -public var FluentPostGISSrid: UInt = 4326 +public let FluentPostGISSrid: UInt = 4326 diff --git a/Tests/FluentPostGISTests/FluentPostGISTestCase.swift b/Tests/FluentPostGISTests/FluentPostGISTestCase.swift index 5d4c64e..91fcad1 100644 --- a/Tests/FluentPostGISTests/FluentPostGISTestCase.swift +++ b/Tests/FluentPostGISTests/FluentPostGISTestCase.swift @@ -5,7 +5,7 @@ import XCTest class FluentPostGISTestCase: XCTestCase { var dbs: Databases! - var db: Database { + var db: any Database { self.dbs.database( logger: .init(label: "lib.fluent.postgis"), on: self.dbs.eventLoopGroup.next() @@ -16,11 +16,12 @@ class FluentPostGISTestCase: XCTestCase { let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) let threadPool = NIOThreadPool(numberOfThreads: 1) self.dbs = Databases(threadPool: threadPool, on: eventLoopGroup) - let configuration = PostgresConfiguration( + let configuration = SQLPostgresConfiguration( hostname: "localhost", username: "fluentpostgis", password: "fluentpostgis", - database: "postgis_tests" + database: "postgis_tests", + tls: .disable ) self.dbs.use(.postgres(configuration: configuration), as: .psql) @@ -35,7 +36,7 @@ class FluentPostGISTestCase: XCTestCase { } } - private let migrations: [AsyncMigration] = [ + private let migrations: [any AsyncMigration] = [ UserLocationMigration(), CityMigration(), UserPathMigration(), diff --git a/Tests/FluentPostGISTests/GeometryTests.swift b/Tests/FluentPostGISTests/GeometryTests.swift index 5d30098..4b94cdd 100644 --- a/Tests/FluentPostGISTests/GeometryTests.swift +++ b/Tests/FluentPostGISTests/GeometryTests.swift @@ -56,7 +56,7 @@ final class GeometryTests: FluentPostGISTestCase { exteriorRing: lineString, interiorRings: [lineString, lineString] ) - let geometries: [GeometryCollectable] = [point, point2, point3, lineString, polygon] + let geometries: [any GeometryCollectable] = [point, point2, point3, lineString, polygon] let geometryCollection = GeometricGeometryCollection2D(geometries: geometries) let user = UserCollection(collection: geometryCollection) diff --git a/Tests/FluentPostGISTests/TestModels.swift b/Tests/FluentPostGISTests/TestModels.swift index 9194513..3a86028 100644 --- a/Tests/FluentPostGISTests/TestModels.swift +++ b/Tests/FluentPostGISTests/TestModels.swift @@ -1,7 +1,7 @@ import FluentKit import FluentPostGIS -final class UserLocation: Model { +final class UserLocation: Model, @unchecked Sendable { static let schema = "user_location" @ID(custom: .id, generatedBy: .database) @@ -18,20 +18,20 @@ final class UserLocation: Model { } struct UserLocationMigration: AsyncMigration { - func prepare(on database: Database) async throws { + func prepare(on database: any Database) async throws { try await database.schema(UserLocation.schema) .field(.id, .int, .identifier(auto: true)) .field("location", .geometricPoint2D) .create() } - func revert(on database: Database) async throws { + func revert(on database: any Database) async throws { try await database.schema(UserLocation.schema).delete() } } /// A model for testing `GeographicPoint2D`-related functionality -final class City: Model { +final class City: Model, @unchecked Sendable { static let schema = "city_location" @ID(custom: .id, generatedBy: .database) @@ -48,20 +48,20 @@ final class City: Model { } struct CityMigration: AsyncMigration { - func prepare(on database: Database) async throws { + func prepare(on database: any Database) async throws { try await database.schema(City.schema) .field(.id, .int, .identifier(auto: true)) .field("location", .geographicPoint2D) .create() } - func revert(on database: Database) async throws { + func revert(on database: any Database) async throws { try await database.schema(City.schema).delete() } } -final class UserPath: Model { - static var schema: String = "user_path" +final class UserPath: Model, @unchecked Sendable { + static let schema: String = "user_path" @ID(custom: .id, generatedBy: .database) var id: Int? @@ -77,20 +77,20 @@ final class UserPath: Model { } struct UserPathMigration: AsyncMigration { - func prepare(on database: Database) async throws { + func prepare(on database: any Database) async throws { try await database.schema(UserPath.schema) .field(.id, .int, .identifier(auto: true)) .field("path", .geometricLineString2D) .create() } - func revert(on database: Database) async throws { + func revert(on database: any Database) async throws { try await database.schema(UserPath.schema).delete() } } -final class UserArea: Model { - static var schema: String = "user_area" +final class UserArea: Model, @unchecked Sendable { + static let schema: String = "user_area" @ID(custom: .id, generatedBy: .database) var id: Int? @@ -106,20 +106,20 @@ final class UserArea: Model { } struct UserAreaMigration: AsyncMigration { - func prepare(on database: Database) async throws { + func prepare(on database: any Database) async throws { try await database.schema(UserArea.schema) .field(.id, .int, .identifier(auto: true)) .field("area", .geometricPolygon2D) .create() } - func revert(on database: Database) async throws { + func revert(on database: any Database) async throws { try await database.schema(UserArea.schema).delete() } } -final class UserCollection: Model { - static var schema: String = "user_collection" +final class UserCollection: Model, @unchecked Sendable { + static let schema: String = "user_collection" @ID(custom: .id, generatedBy: .database) var id: Int? @@ -135,14 +135,14 @@ final class UserCollection: Model { } struct UserCollectionMigration: AsyncMigration { - func prepare(on database: Database) async throws { + func prepare(on database: any Database) async throws { try await database.schema(UserCollection.schema) .field(.id, .int, .identifier(auto: true)) .field("collection", .geometricGeometryCollection2D) .create() } - func revert(on database: Database) async throws { + func revert(on database: any Database) async throws { try await database.schema(UserCollection.schema).delete() } }