Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgis geography type shows as postgres.ColumnString #336

Open
ayaanqui opened this issue Mar 20, 2024 · 3 comments
Open

Postgis geography type shows as postgres.ColumnString #336

ayaanqui opened this issue Mar 20, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@ayaanqui
Copy link

ayaanqui commented Mar 20, 2024

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 ayaanqui added the bug Something isn't working label Mar 20, 2024
@houten11
Copy link

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.

@ayaanqui
Copy link
Author

ayaanqui commented Mar 21, 2024

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.

@go-jet
Copy link
Owner

go-jet commented Mar 24, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants