Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cf5f2cd
Convert everything to Vapor 4
rabc Apr 13, 2020
8a64543
Start refactor unit tests
rabc Apr 17, 2020
6019e95
Update packages
rabc May 5, 2020
4bf3bed
Remove encode/decode from GeometricGeometryCollection2D
rabc May 5, 2020
522994d
Convert QueryTests
rabc May 5, 2020
54bd868
Change WKCodable URL
rabc May 5, 2020
90a956f
Update readme
rabc May 5, 2020
d224b8c
Remove travis
rabc May 5, 2020
57eac96
Fix conflicts
rabc May 6, 2020
005505e
Re-organize code
rabc May 7, 2020
4f268bd
Change package name
rabc May 24, 2020
a0b14aa
update visiblity
joeblau May 25, 2020
0c97c0b
Update to newest Vapor 4
rabc Jun 19, 2020
6f95424
Mark dataType as public
rabc Aug 8, 2020
0aba6b2
Add init
rabc Aug 9, 2020
63d4dae
Merge pull request #1 from joeblau/vapor_4
rabc Oct 9, 2020
56c194b
Merge pull request #2 from rabc/vapor_4
rabc Oct 9, 2020
93cff8c
Fix double init
rabc Oct 9, 2020
147c20d
Merge remote-tracking branch 'rabc/master' into vapor4
Apr 26, 2022
84dcb4d
Clean up
Apr 26, 2022
db7b2b7
Fixes and cleanup
Apr 26, 2022
1f07346
Introduce new overload of filterGeographyDistanceWithin
Apr 26, 2022
7425d02
Add tests for filterDistanceWithin and sortByDistance
May 2, 2022
9573d06
Async/await, better tests, and more
May 2, 2022
ca1aa1e
Run swiftformat
May 2, 2022
7aabb86
Update README.md
May 2, 2022
838fb9b
Add CI
May 2, 2022
c4d6909
Clean up tests
May 2, 2022
0b9de0b
Use await for all Migration.prepare in tests
May 2, 2022
57b2362
Clean up test case setup and teardown
May 2, 2022
4cdd34d
Add static properties to DatabaseSchema.DataType
May 2, 2022
487cbbe
Clean up folder naming and data type extension
May 3, 2022
5f31290
Simplify query builder implementation
May 3, 2022
3f67541
Also trigger CI on Pull Request
May 3, 2022
e910c6d
Remove enable-test-discovery flag
May 3, 2022
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
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CI
on:
- push
- pull_request
jobs:
test:
name: Run tests
runs-on: ubuntu-latest
services:
postgres:
image: postgis/postgis
ports:
- "5432:5432"
env:
POSTGRES_USER: fluentpostgis
POSTGRES_PASSWORD: fluentpostgis
POSTGRES_DB: postgis_tests
steps:
- uses: actions/checkout@v3
- run: swift test
8 changes: 8 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--extensionacl on-declarations
--header strip
--maxwidth 100
--self insert
--swiftversion 5.5
--wraparguments before-first
--wrapcollections before-first
--wrapparameters before-first
44 changes: 0 additions & 44 deletions .travis.yml

This file was deleted.

2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test-db:
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
35 changes: 21 additions & 14 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
// swift-tools-version:4.1
// swift-tools-version:5.5
import PackageDescription

let package = Package(
name: "FluentPostGIS",
name: "fluent-postgis",
platforms: [
.macOS(.v12),
],
products: [
// FluentPostgreSQL support for PostGIS
.library(
name: "FluentPostGIS",
targets: ["FluentPostGIS"]),
targets: ["FluentPostGIS"]
),
],
dependencies: [
// Swift ORM framework (queries, models, and relations) for building NoSQL and SQL database integrations.
.package(url: "https://github.com/vapor/fluent.git", from: "3.0.0"),

// 🐘 Non-blocking, event-driven Swift client for PostgreSQL.
.package(url: "https://github.com/vapor/fluent-postgresql.git", from: "1.0.0"),

// Well Known Binary Encoding and Decoding
.package(url: "https://github.com/plarson/WKCodable", from: "0.1.1"),
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.0.0"),
.package(url: "https://github.com/vapor/fluent-postgres-driver.git", from: "2.0.0"),
.package(url: "https://github.com/rabc/WKCodable.git", from: "0.1.0"),
],
targets: [
.target(
name: "FluentPostGIS",
dependencies: ["FluentPostgreSQL", "WKCodable"]),
dependencies: [
.product(name: "FluentKit", package: "fluent-kit"),
.product(name: "FluentPostgresDriver", package: "fluent-postgres-driver"),
.product(name: "WKCodable", package: "WKCodable"),
]
),
.testTarget(
name: "FluentPostGISTests",
dependencies: ["FluentBenchmark", "FluentPostGIS"]),
dependencies: [
.target(name: "FluentPostGIS"),
.product(name: "FluentBenchmark", package: "fluent-kit"),
]
),
]
)
73 changes: 58 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,73 @@
# FluentPostGIS

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

PostGIS support for [FluentPostgreSQL](https://github.com/vapor/fluent-postgresql) and [Vapor](https://github.com/vapor/vapor)
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).

# Installation

## Swift Package Manager

Add this line to your dependencies in `Package.swift`:

```swift
.package(url: "https://github.com/brokenhandsio/fluent-postgis.git", from: "0.3.0")
```

Then add this line to a target's dependencies:

```swift
.package(url: "https://github.com/plarson/fluent-postgis.git", .branch("master"))
.product(name: "FluentPostGIS", package: "fluent-postgis"),
```

# Setup

Import module

```swift
import FluentPostGIS
```

Add to ```configure.swift```
Optionally, you can add a `Migration` to enable PostGIS:

```swift
try services.register(FluentPostGISProvider())
app.migrations.add(EnablePostGISMigration())

```

# Models
Add ```GISGeographicPoint2D``` to your models

Add a type to your model

```swift
final class User: PostgreSQLModel {
var id: Int?
var name: String
var location: GISGeographicPoint2D?
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`:

```swift
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|
Expand All @@ -44,10 +79,14 @@ final class User: PostgreSQLModel {
|GeometricGeometryCollection2D|GeographicGeometryCollection2D|

# Queries
Query locations using ```ST_DWithin```
```swift
let searchLocation = GISGeographicPoint2D(longitude: -71.060316, latitude: 48.432044)
try User.query(on: conn).filterGeometryDistanceWithin(\User.location, searchLocation, 1000).all().wait()

Query using any of the filter functions:

```swift
let eiffelTower = GeographicPoint2D(longitude: 2.2945, latitude: 48.858222)
try await User.query(on: database)
.filterGeographyDistanceWithin(\.$location, eiffelTower, 1000)
.all()
```

| Queries |
Expand All @@ -57,11 +96,13 @@ try User.query(on: conn).filterGeometryDistanceWithin(\User.location, searchLoca
|filterGeometryDisjoint|
|filterGeometryDistance|
|filterGeometryDistanceWithin|
|filterGeographyDistanceWithin|
|filterGeometryEquals|
|filterGeometryIntersects|
|filterGeometryOverlaps|
|filterGeometryTouches|
|filterGeometryWithin|
|sortByDistance|

:gift_heart: Contributing
------------
Expand All @@ -73,4 +114,6 @@ MIT

:alien: Author
------
BrokenHands, Tim Condon, Nikolai Guyot - https://www.brokenhands.io/
Ricardo Carvalho - https://rabc.github.io/
Phil Larson - http://dizm.com
42 changes: 0 additions & 42 deletions Sources/FluentPostGIS/Geographic/GeographicLineString2D.swift

This file was deleted.

42 changes: 0 additions & 42 deletions Sources/FluentPostGIS/Geographic/GeographicMultiPoint2D.swift

This file was deleted.

44 changes: 0 additions & 44 deletions Sources/FluentPostGIS/Geographic/GeographicMultiPolygon2D.swift

This file was deleted.

Loading