jet icon indicating copy to clipboard operation
jet copied to clipboard

Postgis geography type shows as `postgres.ColumnString`

Open ayaanqui opened this issue 1 year ago • 3 comments
trafficstars

Describe the bug I have a project that uses Postgis to handle geospatial data. The issue is that columns using any Postgis types are generated with the postgres.ColumnString type. So when I try to make an insert with the following code the result is wrapped with a string, so postgres never executes the postgis functions.

longitude := -80.292191
latitude := 42.841367
qb := table.Address.
    INSERT(table.Address.Coordinates).
    MODEL(model.Address{
        Coordinates: fmt.Sprintf(
            "ST_SetSRID(ST_MakePoint(%f, %f), 4326)",
            longitude,
            latitude,
        )
    })

The code above returns this output when use the debugger function:

INSERT INTO public.address (coordinates)
VALUES ('ST_SetSRID(ST_MakePoint(-80.292191, 42.841367), 4326)')

In the output the value is surrounded by single quotes, so postgres treats it as text instead of geography(POINT, 4326). Is there any way I could handle this case?

Environment:

  • OS: linux
  • Database: postgres
  • Database driver: pq
  • Jet version: 2.11.0

Code snippet Here's the minimal SQL schema to get this to work. this does assume Postgis is installed (see installation instructions here)

CREATE EXTENSION IF NOT EXISTS postgis;

CREATE TABLE "address" (
    "id" BIGSERIAL UNIQUE PRIMARY KEY,
    "coordinates" geography(POINT, 4326) NOT NULL
);

Expected behavior The insert should return without surrounding the value for column coordinate with single quotes. Like so:

INSERT INTO public.address (coordinates)
VALUES (ST_SetSRID(ST_MakePoint(-80.292191, 42.841367), 4326))

ayaanqui avatar Mar 20 '24 23:03 ayaanqui

You'll need to customize the generator to use your postgis geography type of choice. Check the wiki - https://github.com/go-jet/jet/wiki/Generator#generator-customization.

houtn11 avatar Mar 21 '24 10:03 houtn11

Can Jet generate these types? When I take a look at the database I clearly see all the data types geometry, geography, and all the functions associated with these types. But Jet doesn't seem to generate these types. However, when I create enum types they seem to be getting generated properly as their corresponding go types.

ayaanqui avatar Mar 21 '24 17:03 ayaanqui

Hi @ayaanqui, geometry, geography and some other types are currently unsupported. All unsupported types are always generated as string. Using generator customization developers can overwrite this behavior, with their types. Enum types are supported.

go-jet avatar Mar 24 '24 12:03 go-jet