A fork of the FluentPostGIS package which adds support for geographic queries. FluentPostGIS provides PostGIS support for fluent-postgres-driver and Vapor 4.
Add this line to your dependencies in Package.swift:
.package(url: "https://github.com/brokenhandsio/fluent-postgis.git", from: "0.3.0")Then add this line to a target's dependencies:
.product(name: "FluentPostGIS", package: "fluent-postgis"),Import module
import FluentPostGISOptionally, you can add a Migration to enable PostGIS:
app.migrations.add(EnablePostGISMigration())Add a type to your model
final class User: Model, @unchecked Sendable {
    static let schema = "user"
    
    @ID(key: .id)
    var id: UUID?
    @Field(key: "location")
    var location: GeometricPoint2D
}Then use its data type in the Migration:
struct UserMigration: AsyncMigration {
    func prepare(on database: Database) async throws -> {
        try await database.schema(User.schema)
            .id()
            .field("location", .geometricPoint2D)
            .create()
    }
    func revert(on database: Database) async throws -> {
        try await database.schema(User.schema).delete()
    }
}| Geometric Types | Geographic Types | 
|---|---|
| GeometricPoint2D | GeographicPoint2D | 
| GeometricLineString2D | GeographicLineString2D | 
| GeometricPolygon2D | GeographicPolygon2D | 
| GeometricMultiPoint2D | GeographicMultiPoint2D | 
| GeometricMultiLineString2D | GeographicMultiLineString2D | 
| GeometricMultiPolygon2D | GeographicMultiPolygon2D | 
| GeometricGeometryCollection2D | GeographicGeometryCollection2D | 
Query using any of the filter functions:
let eiffelTower = GeographicPoint2D(longitude: 2.2945, latitude: 48.858222)
try await User.query(on: database)
    .filterGeographyDistanceWithin(\.$location, eiffelTower, 1000)
    .all()| Queries | 
|---|
| filterGeometryContains | 
| filterGeometryCrosses | 
| filterGeometryDisjoint | 
| filterGeometryDistance | 
| filterGeometryDistanceWithin | 
| filterGeographyDistanceWithin | 
| filterGeometryEquals | 
| filterGeometryIntersects | 
| filterGeometryOverlaps | 
| filterGeometryTouches | 
| filterGeometryWithin | 
| sortByDistance | 
Please create an issue with a description of your problem or open a pull request with a fix.
MIT
BrokenHands, Tim Condon, Nikolai Guyot - https://www.brokenhands.io/ Ricardo Carvalho - https://rabc.github.io/ Phil Larson - http://dizm.com