Skip to content

Commit

Permalink
add postgis geometry as valid column type
Browse files Browse the repository at this point in the history
  • Loading branch information
staffanhedstrom authored and jeremydmiller committed Sep 14, 2024
1 parent 34ba979 commit fcc0c6e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/Weasel.Postgresql.Tests/Tables/TableColumnTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using NetTopologySuite.Geometries;
using Shouldly;
using Weasel.Postgresql.Tables;
using Xunit;
Expand Down Expand Up @@ -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<Geometry>("geom").NotNull().Column;

column.AddColumnSql(table)
.ShouldBe($"alter table {Instance.Parse("public.map")} add column geom geometry NOT NULL;");
}
}
4 changes: 3 additions & 1 deletion src/Weasel.Postgresql/NpgsqlTypeMapping.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections;
using System.Collections;
using System.Collections.Immutable;
using System.Collections.Specialized;
using System.Data;
Expand All @@ -7,6 +7,7 @@
using System.Numerics;
using System.Text.Json;
using JasperFx.Core;
using NetTopologySuite.Geometries;
using NpgsqlTypes;

namespace Weasel.Postgresql;
Expand Down Expand Up @@ -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")},
Expand Down
1 change: 1 addition & 0 deletions src/Weasel.Postgresql/Weasel.Postgresql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="Npgsql.NetTopologySuite" Version="8.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Weasel.Core\Weasel.Core.csproj" />
Expand Down

0 comments on commit fcc0c6e

Please sign in to comment.