jet
jet copied to clipboard
Postgis geography type shows as `postgres.ColumnString`
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))
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.
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.
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.