GithubHelp home page GithubHelp logo

plarson / fluent-postgis Goto Github PK

View Code? Open in Web Editor NEW
33.0 33.0 34.0 104 KB

Swift PostGIS support for FluentPostgreSQL and Vapor

License: MIT License

Swift 100.00%
fluent fluent-database fluent-driver postgresql server-side-swift swift-linux vapor

fluent-postgis's People

Contributors

plarson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fluent-postgis's Issues

Not possible to filter with optional value

Hi,

I have a table where the GeographicPoint2D property is optional and it is not possible to use filterGeometryDistanceWithin with this property without force-unwrapping it. I made a unit test to showcase this situation:

func testOptionalLocation() throws {
    struct UserGeographicLocation: PostgreSQLModel, Migration {
        var id: Int?
        var name: String
        var location: GeographicPoint2D?
    }
    let conn = try benchmarker.pool.requestConnection().wait()
    conn.logger = DatabaseLogger(database: .psql, handler: PrintLogHandler())
    defer { benchmarker.pool.releaseConnection(conn) }

    try UserGeographicLocation.prepare(on: conn).wait()
    defer { try! UserGeographicLocation.revert(on: conn).wait() }

    let point: GeographicPoint2D = GeographicPoint2D(longitude: 1, latitude: 2)

    var user = UserGeographicLocation(id: nil, name: "My User", location: point)
    user = try user.save(on: conn).wait()

    // Crash:
    // Fatal error: Unexpectedly found nil while unwrapping an Optional value
    // without the `!`, it will not build
    let all = try UserGeographicLocation.query(on: conn).filterGeometryDistanceWithin(\UserGeographicLocation.location!, point, 1000).all().wait()
    XCTAssertEqual(all.count, 1)
}

I tried to look the code to find a solution, but couldn't find any way to workaround or fix it.

Optional type

I have model

final class Organization: PostgreSQLModel {
    var id: Int?
    var location: GeographicPoint2D?
}

However, I do receive error when passing KeyPath

Cannot convert value of type 'ReferenceWritableKeyPath<Organization, GeographicPoint2D?>' to expected argument type 'PostgreSQLDatabase.QueryField' (aka 'GenericSQLColumnIdentifier<GenericSQLTableIdentifier, GenericSQLIdentifier>')

.filterGeometryDistanceWithin(\Organization.location, searchLocation, distance).all()

It does work when I do it with force unwrap

.filterGeometryDistanceWithin(\Organization.location!, searchLocation, distance).all()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.