Skip to content

Commit ea14dfc

Browse files
authored
Merge pull request #4 from PoshAlpaca/vapor4
Support for Vapor 4
2 parents c13f032 + e910c6d commit ea14dfc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1156
-1887
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: CI
2+
on:
3+
- push
4+
- pull_request
5+
jobs:
6+
test:
7+
name: Run tests
8+
runs-on: ubuntu-latest
9+
services:
10+
postgres:
11+
image: postgis/postgis
12+
ports:
13+
- "5432:5432"
14+
env:
15+
POSTGRES_USER: fluentpostgis
16+
POSTGRES_PASSWORD: fluentpostgis
17+
POSTGRES_DB: postgis_tests
18+
steps:
19+
- uses: actions/checkout@v3
20+
- run: swift test

.swiftformat

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--extensionacl on-declarations
2+
--header strip
3+
--maxwidth 100
4+
--self insert
5+
--swiftversion 5.5
6+
--wraparguments before-first
7+
--wrapcollections before-first
8+
--wrapparameters before-first

.travis.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test-db:
2+
docker run --rm -e POSTGRES_PASSWORD=fluentpostgis -e POSTGRES_USER=fluentpostgis -e POSTGRES_DB=postgis_tests -p 5432:5432 odidev/postgis:11-2.5-alpine

Package.swift

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
1-
// swift-tools-version:4.1
1+
// swift-tools-version:5.5
22
import PackageDescription
33

44
let package = Package(
5-
name: "FluentPostGIS",
5+
name: "fluent-postgis",
6+
platforms: [
7+
.macOS(.v12),
8+
],
69
products: [
7-
// FluentPostgreSQL support for PostGIS
810
.library(
911
name: "FluentPostGIS",
10-
targets: ["FluentPostGIS"]),
12+
targets: ["FluentPostGIS"]
13+
),
1114
],
1215
dependencies: [
13-
// Swift ORM framework (queries, models, and relations) for building NoSQL and SQL database integrations.
14-
.package(url: "https://github.com/vapor/fluent.git", from: "3.0.0"),
15-
16-
// 🐘 Non-blocking, event-driven Swift client for PostgreSQL.
17-
.package(url: "https://github.com/vapor/fluent-postgresql.git", from: "1.0.0"),
18-
19-
// Well Known Binary Encoding and Decoding
20-
.package(url: "https://github.com/plarson/WKCodable", from: "0.1.1"),
16+
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.0.0"),
17+
.package(url: "https://github.com/vapor/fluent-postgres-driver.git", from: "2.0.0"),
18+
.package(url: "https://github.com/rabc/WKCodable.git", from: "0.1.0"),
2119
],
2220
targets: [
2321
.target(
2422
name: "FluentPostGIS",
25-
dependencies: ["FluentPostgreSQL", "WKCodable"]),
23+
dependencies: [
24+
.product(name: "FluentKit", package: "fluent-kit"),
25+
.product(name: "FluentPostgresDriver", package: "fluent-postgres-driver"),
26+
.product(name: "WKCodable", package: "WKCodable"),
27+
]
28+
),
2629
.testTarget(
2730
name: "FluentPostGISTests",
28-
dependencies: ["FluentBenchmark", "FluentPostGIS"]),
31+
dependencies: [
32+
.target(name: "FluentPostGIS"),
33+
.product(name: "FluentBenchmark", package: "fluent-kit"),
34+
]
35+
),
2936
]
3037
)

README.md

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,73 @@
11
# FluentPostGIS
22

3-
[![Build Status](https://travis-ci.org/plarson/fluent-postgis.svg?branch=master)](https://travis-ci.org/plarson/fluent-postgis)
43
![Platforms](https://img.shields.io/badge/platforms-Linux%20%7C%20OS%20X-blue.svg)
54
![Package Managers](https://img.shields.io/badge/package%20managers-SwiftPM-yellow.svg)
6-
[![Twitter dizm](https://img.shields.io/badge/twitter-dizm-green.svg)](http://twitter.com/dizm)
75

8-
PostGIS support for [FluentPostgreSQL](https://github.com/vapor/fluent-postgresql) and [Vapor](https://github.com/vapor/vapor)
6+
A fork of the [FluentPostGIS](https://github.com/plarson/fluent-postgis) package which adds support for geographic queries. FluentPostGIS provides PostGIS support for [fluent-postgres-driver](https://github.com/vapor/fluent-postgres-driver) and [Vapor 4](https://github.com/vapor/vapor).
97

108
# Installation
119

1210
## Swift Package Manager
1311

12+
Add this line to your dependencies in `Package.swift`:
13+
14+
```swift
15+
.package(url: "https://github.com/brokenhandsio/fluent-postgis.git", from: "0.3.0")
16+
```
17+
18+
Then add this line to a target's dependencies:
19+
1420
```swift
15-
.package(url: "https://github.com/plarson/fluent-postgis.git", .branch("master"))
21+
.product(name: "FluentPostGIS", package: "fluent-postgis"),
1622
```
23+
1724
# Setup
25+
1826
Import module
27+
1928
```swift
2029
import FluentPostGIS
2130
```
2231

23-
Add to ```configure.swift```
32+
Optionally, you can add a `Migration` to enable PostGIS:
33+
2434
```swift
25-
try services.register(FluentPostGISProvider())
35+
app.migrations.add(EnablePostGISMigration())
36+
2637
```
38+
2739
# Models
28-
Add ```GISGeographicPoint2D``` to your models
40+
41+
Add a type to your model
42+
2943
```swift
30-
final class User: PostgreSQLModel {
31-
var id: Int?
32-
var name: String
33-
var location: GISGeographicPoint2D?
44+
final class User: Model {
45+
static let schema = "user"
46+
47+
@ID(key: .id)
48+
var id: UUID?
49+
50+
@Field(key: "location")
51+
var location: GeometricPoint2D
3452
}
3553
```
54+
55+
Then use its data type in the `Migration`:
56+
57+
```swift
58+
struct UserMigration: AsyncMigration {
59+
func prepare(on database: Database) async throws -> {
60+
try await database.schema(User.schema)
61+
.id()
62+
.field("location", .geometricPoint2D)
63+
.create()
64+
}
65+
func revert(on database: Database) async throws -> {
66+
try await database.schema(User.schema).delete()
67+
}
68+
}
69+
```
70+
3671
| Geometric Types | Geographic Types |
3772
|---|---|
3873
|GeometricPoint2D|GeographicPoint2D|
@@ -44,10 +79,14 @@ final class User: PostgreSQLModel {
4479
|GeometricGeometryCollection2D|GeographicGeometryCollection2D|
4580

4681
# Queries
47-
Query locations using ```ST_DWithin```
48-
```swift
49-
let searchLocation = GISGeographicPoint2D(longitude: -71.060316, latitude: 48.432044)
50-
try User.query(on: conn).filterGeometryDistanceWithin(\User.location, searchLocation, 1000).all().wait()
82+
83+
Query using any of the filter functions:
84+
85+
```swift
86+
let eiffelTower = GeographicPoint2D(longitude: 2.2945, latitude: 48.858222)
87+
try await User.query(on: database)
88+
.filterGeographyDistanceWithin(\.$location, eiffelTower, 1000)
89+
.all()
5190
```
5291

5392
| Queries |
@@ -57,11 +96,13 @@ try User.query(on: conn).filterGeometryDistanceWithin(\User.location, searchLoca
5796
|filterGeometryDisjoint|
5897
|filterGeometryDistance|
5998
|filterGeometryDistanceWithin|
99+
|filterGeographyDistanceWithin|
60100
|filterGeometryEquals|
61101
|filterGeometryIntersects|
62102
|filterGeometryOverlaps|
63103
|filterGeometryTouches|
64104
|filterGeometryWithin|
105+
|sortByDistance|
65106

66107
:gift_heart: Contributing
67108
------------
@@ -73,4 +114,6 @@ MIT
73114

74115
:alien: Author
75116
------
117+
BrokenHands, Tim Condon, Nikolai Guyot - https://www.brokenhands.io/
118+
Ricardo Carvalho - https://rabc.github.io/
76119
Phil Larson - http://dizm.com

Sources/FluentPostGIS/Geographic/GeographicLineString2D.swift

Lines changed: 0 additions & 42 deletions
This file was deleted.

Sources/FluentPostGIS/Geographic/GeographicMultiPoint2D.swift

Lines changed: 0 additions & 42 deletions
This file was deleted.

Sources/FluentPostGIS/Geographic/GeographicMultiPolygon2D.swift

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)