From 68afd1fc198af059f3d2e60a5ecb071463659c53 Mon Sep 17 00:00:00 2001 From: Andrew Nosenko Date: Sat, 27 Dec 2025 21:41:37 +1100 Subject: [PATCH] support for MSSQL 2025 vector and json types --- src/Pingmint.CodeGen.Sql/Analyzer.cs | 17 ++++++++++++++++- src/Pingmint.CodeGen.Sql/CodeFile.cs | 1 + .../Pingmint.CodeGen.Sql.csproj | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Pingmint.CodeGen.Sql/Analyzer.cs b/src/Pingmint.CodeGen.Sql/Analyzer.cs index 77cdeb7..3331e7d 100644 --- a/src/Pingmint.CodeGen.Sql/Analyzer.cs +++ b/src/Pingmint.CodeGen.Sql/Analyzer.cs @@ -466,6 +466,8 @@ private async Task> GetTableTypeColumnsAsync(SqlCon "xml" => SqlDbType.Xml, "uniqueidentifier" => SqlDbType.UniqueIdentifier, "image" => SqlDbType.Image, + "vector" => SqlDbType.Vector, + "json" => SqlDbType.Json, _ => (SqlDbType?)null, } is not { } value) @@ -502,7 +504,8 @@ SqlDbType.NText or SqlDbType.NVarChar or SqlDbType.Text or SqlDbType.VarChar or - SqlDbType.Xml + SqlDbType.Xml or + SqlDbType.Json => typeof(String), SqlDbType.DateTimeOffset => typeof(DateTimeOffset), @@ -559,6 +562,18 @@ private async Task GetCSharpTypeInfoAsync(SqlConnection server, throw new InvalidOperationException("Could not find sys.types row for " + systemTypeId + ", " + userTypeId); } + if (foundSysType.Name == "vector") + { + _csharpTypeInfosById[(systemTypeId, userTypeId)] = cachedValue = new() + { + TypeRef = "SqlVector", + TypeRefNullable = "SqlVector?", + IsValueType = true, + SqlDbType = SqlDbType.Vector, + }; + return cachedValue; + } + if (!foundSysType.IsUserDefined) { if (await GetSqlDbTypeAsync(server, systemTypeId, userTypeId) is { } sqlDbType) diff --git a/src/Pingmint.CodeGen.Sql/CodeFile.cs b/src/Pingmint.CodeGen.Sql/CodeFile.cs index c969e72..5fca9b4 100644 --- a/src/Pingmint.CodeGen.Sql/CodeFile.cs +++ b/src/Pingmint.CodeGen.Sql/CodeFile.cs @@ -41,6 +41,7 @@ public String GenerateCode() code.UsingNamespace("System.Threading"); code.UsingNamespace("System.Threading.Tasks"); code.UsingNamespace("Microsoft.Data.SqlClient"); + code.UsingNamespace("Microsoft.Data.SqlTypes"); code.Line($"using static {Namespace}.FileMethods;"); code.Line(); diff --git a/src/Pingmint.CodeGen.Sql/Pingmint.CodeGen.Sql.csproj b/src/Pingmint.CodeGen.Sql/Pingmint.CodeGen.Sql.csproj index 29b6821..e65eae5 100644 --- a/src/Pingmint.CodeGen.Sql/Pingmint.CodeGen.Sql.csproj +++ b/src/Pingmint.CodeGen.Sql/Pingmint.CodeGen.Sql.csproj @@ -1,7 +1,7 @@ - 0.48 + 0.49 Exe net10.0 latest