Merge pull request #4 from PoshAlpaca/vapor4 Support for Vapor 4
Merge pull request #4 from PoshAlpaca/vapor4
Support for Vapor 4
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.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 FluentPostGIS
Optionally, you can add a Migration to enable PostGIS:
Migration
app.migrations.add(EnablePostGISMigration())
Add a type to your model
final class User: Model { 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() } }
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()
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
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
FluentPostGIS
A fork of the FluentPostGIS package which adds support for geographic queries. FluentPostGIS provides PostGIS support for fluent-postgres-driver and Vapor 4.
Installation
Swift Package Manager
Add this line to your dependencies in
Package.swift
:Then add this line to a target’s dependencies:
Setup
Import module
Optionally, you can add a
Migration
to enable PostGIS:Models
Add a type to your model
Then use its data type in the
Migration
:Queries
Query using any of the filter functions:
Please create an issue with a description of your problem or open a pull request with a fix.
MIT
👽 Author
BrokenHands, Tim Condon, Nikolai Guyot - https://www.brokenhands.io/ Ricardo Carvalho - https://rabc.github.io/ Phil Larson - http://dizm.com