Charalamm
Charalamm

Reputation: 1947

Use PostGIS geometry types in SQLModel

Is it possible to use PostGIS geometry types in models created in SQLModel? If yes, how can it be done?

Upvotes: 2

Views: 1734

Answers (1)

Charalamm
Charalamm

Reputation: 1947

Yes it is.

Just take advantage of the sqlalchemy package that makes the work underneath SQLModel and the the GeoAlchemy2 package which is compatible with sqlalchemy and has already defined geometry types.

So,

from geoalchemy2 import Geometry
from sqlmodel import SQLModel, Field, Column

class Record(SQLModel, table=True):
    point: Any = Field(sa_column=Column(Geometry('POINT'))) # Here POINT is used but could be other geometries as well

Upvotes: 10

Related Questions