vapor / postgres-nio

🐘 Non-blocking, event-driven Swift client for PostgreSQL.
https://api.vapor.codes/postgresnio/documentation/postgresnio/
MIT License
321 stars 75 forks source link

Multi-dimensional arrays #101

Open IgorRosocha opened 5 years ago

IgorRosocha commented 5 years ago

I have been trying to parse a GeoJSON, which has a multidimensional array coordinates, example:

{
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            14.3894460970001,
                            49.951972148
                        ],
                        [
                            14.3891214220001,
                            49.9524958600001
                        ]
                    ]
                ]
            }
        }
    ]
}

I'm having problem of saving multidimensional coordinates of type [[[Double]]] as a column into my database (which is described in my PosgtreSQLModel). In the DDL of created database, it has type jsonb[], and when I try to save it, I get PostgreSQLError.server.error.array_recv: wrong element type. It would be really great if the support for multidimensional arrays would be available.

Cassini-17 commented 5 years ago

I have the same error, have you found solution?

IgorRosocha commented 5 years ago

I have the same error, have you found solution?

The only way that worked for me was to create a struct for geometry in my model and then save the whole geometry json as a database column, so the code looks like this:

/// A representation of Geometry
    struct Geometry: Content {

        /// Type of Geometry object
        let type: String

        /// Coordinates of Geometry object
        let coordinates: [[[Double]]]
    }

    /// Geometry of Feature
    var geometry: Geometry
RamblinWreck77 commented 4 years ago

@IgorRosocha This looks to be supported in the latest beta release. In my migrations I can do .array(of: .array(of .json)) and it seems to be working.