Skip to content

feat: Add built-in PostgreSQL geometric types support (#282) - #3156

Open
kAif-gh wants to merge 1 commit into
SeaQL:masterfrom
kAif-gh:feat/postgis-geometry-282
Open

feat: Add built-in PostgreSQL geometric types support (#282)#3156
kAif-gh wants to merge 1 commit into
SeaQL:masterfrom
kAif-gh:feat/postgis-geometry-282

Conversation

@kAif-gh

@kAif-gh kAif-gh commented Aug 4, 2026

Copy link
Copy Markdown

Add support for built-in PostgreSQL geometric types

Closes #282

What

Adds support for PostgreSQL's built-in geometric types in entities:
point, line, lseg, box, path, polygon, circle.
These are the core Postgres geometric types (Postgres manual §8.8) — not
PostGIS, so no extension is required.

How

sqlx already provides structs for these types (PgPoint, PgPolygon, …), but
Rust's orphan rules stop us from implementing sea-orm's traits on them directly.
So this adds a thin Geo<T> newtype wrapper that implements the needed traits
(ValueType, TryGetable, Nullable, IntoActiveValue, …) and derefs to the
inner sqlx type.
Values cross the DB boundary as canonical Postgres text using the existing
save_as / select_as casts, so the core Value enum is left unchanged.
Everything is gated behind a new postgres-geometry feature.

Usage

use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "geo")]
pub struct Model {
    #[sea_orm(primary_key, auto_increment = false)]
    pub id: i32,
    #[sea_orm(column_type = r#"custom("point")"#, select_as = "text", save_as = "point")]
    pub location: Geo<PgPoint>,
    #[sea_orm(column_type = r#"custom("polygon")"#, select_as = "text", save_as = "polygon")]
    pub boundary: Geo<PgPolygon>,
}

Tests

Adds tests/postgres_geometry_tests.rs covering insert/select round-trips of all
seven types (including a NULL case) and native spatial queries (@>, <->).

cargo test --features sqlx-postgres,postgres-geometry --test postgres_geometry_tests

@kAif-gh
kAif-gh force-pushed the feat/postgis-geometry-282 branch from 29549f2 to f8b857e Compare August 4, 2026 16:28
@Huliiiiii

Copy link
Copy Markdown
Member

https://github.com/SeaQL/.github/blob/master/AI_POLICY.md

We should not directly depend on sqlx types. Newtype wrapper is not a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add postgis types support and allow custom types

2 participants