From fcc0c6e8c14cbac038f22a2f6c0c9530055f1b99 Mon Sep 17 00:00:00 2001 From: staffanhedstrom Date: Fri, 16 Aug 2024 13:52:15 +0000 Subject: [PATCH] add postgis geometry as valid column type --- .../Tables/TableColumnTests.cs | 11 +++++++++++ src/Weasel.Postgresql/NpgsqlTypeMapping.cs | 4 +++- src/Weasel.Postgresql/Weasel.Postgresql.csproj | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Weasel.Postgresql.Tests/Tables/TableColumnTests.cs b/src/Weasel.Postgresql.Tests/Tables/TableColumnTests.cs index af9ab85a..82de9e2c 100644 --- a/src/Weasel.Postgresql.Tests/Tables/TableColumnTests.cs +++ b/src/Weasel.Postgresql.Tests/Tables/TableColumnTests.cs @@ -1,3 +1,4 @@ +using NetTopologySuite.Geometries; using Shouldly; using Weasel.Postgresql.Tables; using Xunit; @@ -119,4 +120,14 @@ public void add_column_sql() column.AddColumnSql(table) .ShouldBe($"alter table {Instance.Parse("public.people")} add column name1 varchar NOT NULL;"); } + + [Fact] + public void add_column_sql_geometry() + { + var table = new Table("map"); + var column = table.AddColumn("geom").NotNull().Column; + + column.AddColumnSql(table) + .ShouldBe($"alter table {Instance.Parse("public.map")} add column geom geometry NOT NULL;"); + } } diff --git a/src/Weasel.Postgresql/NpgsqlTypeMapping.cs b/src/Weasel.Postgresql/NpgsqlTypeMapping.cs index df3c0ccb..2ec5506f 100644 --- a/src/Weasel.Postgresql/NpgsqlTypeMapping.cs +++ b/src/Weasel.Postgresql/NpgsqlTypeMapping.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; using System.Collections.Immutable; using System.Collections.Specialized; using System.Data; @@ -7,6 +7,7 @@ using System.Numerics; using System.Text.Json; using JasperFx.Core; +using NetTopologySuite.Geometries; using NpgsqlTypes; namespace Weasel.Postgresql; @@ -103,6 +104,7 @@ public class NpgsqlTypeMapper {NpgsqlDbType.Path, new NpgsqlTypeMapping(NpgsqlDbType.Path, DbType.Object, "path", typeof(NpgsqlPath))}, {NpgsqlDbType.Point, new NpgsqlTypeMapping(NpgsqlDbType.Point, DbType.Object, "point", typeof(NpgsqlPoint))}, {NpgsqlDbType.Polygon, new NpgsqlTypeMapping(NpgsqlDbType.Polygon, DbType.Object, "polygon", typeof(NpgsqlPolygon))}, + {NpgsqlDbType.Geometry, new NpgsqlTypeMapping(NpgsqlDbType.Geometry, DbType.Object, "geometry", typeof(Geometry))}, // LTree types {NpgsqlDbType.LQuery, new NpgsqlTypeMapping(NpgsqlDbType.LQuery, DbType.Object, "lquery")}, diff --git a/src/Weasel.Postgresql/Weasel.Postgresql.csproj b/src/Weasel.Postgresql/Weasel.Postgresql.csproj index dadc6b74..a7bc0262 100644 --- a/src/Weasel.Postgresql/Weasel.Postgresql.csproj +++ b/src/Weasel.Postgresql/Weasel.Postgresql.csproj @@ -33,6 +33,7 @@ +