Skip to content

Commit b2a033d

Browse files
committed
2.16.0 Initial
1 parent 7ae757a commit b2a033d

11 files changed

Lines changed: 316 additions & 106 deletions

File tree

NpgsqlRest/Consts.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,12 @@ public static class Consts
1717
public const char OpenBracket = '[';
1818
public const char CloseBracket = ']';
1919
public const char Space = ' ';
20+
public const string DoubleColon = "::";
21+
public const string FirstParam = "$1";
22+
public const string FirstNamedParam = "=>$1";
23+
public const string CloseParenthesisStr = ")";
24+
public const char Dollar = '$';
25+
public const string NamedParam = "=>$";
26+
public const string OpenRow = "=>row(";
27+
public const string CloseRow = ")::";
2028
}

NpgsqlRest/Defaults/DefaultCommentParser.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,13 @@ internal static class DefaultCommentParser
149149
else
150150
{
151151
string[] lines = comment.Split(newlineSeparator, StringSplitOptions.RemoveEmptyEntries);
152+
routineEndpoint.CommentWordLines = new string[lines.Length][];
152153
bool hasHttpTag = false;
153154
for (var i = 0; i < lines.Length; i++)
154155
{
155156
string line = lines[i].Trim();
156157
string[] words = Split(line);
158+
routineEndpoint.CommentWordLines[i] = words;
157159
var len = words.Length;
158160
if (len == 0)
159161
{

NpgsqlRest/Interfaces.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ public interface IRoutineSourceParameterFormatter
4848
/// </summary>
4949
/// <param name="parameter">NpgsqlRestParameter extended parameter with actual name and type descriptor</param>
5050
/// <param name="index">index of the current parameter</param>
51-
/// <param name="count">total parameter count</param>
5251
/// <returns>string to append to expression or null to skip (404 if endpoint is not handled in the next handler)</returns>
53-
string? AppendCommandParameter(NpgsqlRestParameter parameter, int index, int count) => null;
52+
string? AppendCommandParameter(NpgsqlRestParameter parameter, int index) => null;
5453

5554
/// <summary>
5655
/// Formats the command expression string.
@@ -71,10 +70,9 @@ public interface IRoutineSourceParameterFormatter
7170
/// </summary>
7271
/// <param name="parameter">NpgsqlRestParameter extended parameter with actual name and type descriptor</param>
7372
/// <param name="index">index of the current parameter</param>
74-
/// <param name="count">total parameter count</param>
7573
/// <param name="context">HTTP context reference</param>
7674
/// <returns>string to append to expression or null to skip (404 if endpoint is not handled in the next handler)</returns>
77-
string? AppendCommandParameter(NpgsqlRestParameter parameter, int index, int count, HttpContext context) => null;
75+
string? AppendCommandParameter(NpgsqlRestParameter parameter, int index, HttpContext context) => null;
7876

7977
/// <summary>
8078
/// Formats the command expression string.

NpgsqlRest/NpgsqlRest.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
<GenerateDocumentationFile>true</GenerateDocumentationFile>
3030
<PackageReadmeFile>README.MD</PackageReadmeFile>
3131
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).xml</DocumentationFile>
32-
<Version>2.15.0</Version>
33-
<AssemblyVersion>2.15.0</AssemblyVersion>
34-
<FileVersion>2.15.0</FileVersion>
35-
<PackageVersion>2.15.0</PackageVersion>
32+
<Version>2.16.0</Version>
33+
<AssemblyVersion>2.16.0</AssemblyVersion>
34+
<FileVersion>2.16.0</FileVersion>
35+
<PackageVersion>2.16.0</PackageVersion>
3636
</PropertyGroup>
3737

3838
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">

NpgsqlRest/NpgsqlRestMiddleware.cs

Lines changed: 238 additions & 61 deletions
Large diffs are not rendered by default.

NpgsqlRest/RoutineEndpoint.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ public string? BodyParameterName
5858
public string? RawValueSeparator { get; set; } = rawValueSeparator;
5959
public string? RawNewLineSeparator { get; set; } = rawNewLineSeparator;
6060
public bool RawColumnNames { get; set; } = rawColumnNames;
61+
public string[][]? CommentWordLines { get; internal set; }
6162
}

NpgsqlRest/RoutineSourceParameterFormatter.cs

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Text;
1+
using System.Globalization;
2+
using System.Text;
23
using Npgsql;
34

45
namespace NpgsqlRest;
@@ -7,33 +8,27 @@ public class RoutineSourceParameterFormatter : IRoutineSourceParameterFormatter
78
{
89
public bool IsFormattable { get; } = false;
910

10-
public string AppendCommandParameter(NpgsqlRestParameter parameter, int index, int count)
11+
public string AppendCommandParameter(NpgsqlRestParameter parameter, int index)
1112
{
12-
var suffix = parameter.TypeDescriptor.IsCastToText() ? $"::{parameter.TypeDescriptor.OriginalType}" : "";
13+
var suffix = parameter.TypeDescriptor.IsCastToText() ?
14+
string.Concat(Consts.DoubleColon, parameter.TypeDescriptor.OriginalType) :
15+
string.Empty;
16+
1317
if (index == 0)
1418
{
15-
if (count == 1)
16-
{
17-
return parameter.ActualName is null ?
18-
string.Concat("$1", suffix, ")") :
19-
string.Concat(parameter.ActualName, "=>$1", suffix, ")");
20-
}
21-
return parameter.ActualName is null ?
22-
string.Concat("$1", suffix) :
23-
string.Concat(parameter.ActualName, "=>$1", suffix);
24-
}
25-
if (index == count - 1)
26-
{
27-
return parameter.ActualName is null ?
28-
string.Concat(",", "$", (index + 1).ToString(), suffix, ")") :
29-
string.Concat(",", parameter.ActualName, "=>$", (index + 1).ToString(), suffix, ")");
19+
return parameter.ActualName is null ?
20+
string.Concat(Consts.FirstParam, suffix) :
21+
string.Concat(parameter.ActualName, Consts.FirstNamedParam, suffix);
3022
}
23+
24+
var indexStr = (index + 1).ToString(CultureInfo.InvariantCulture);
25+
3126
return parameter.ActualName is null ?
32-
string.Concat(",", "$", (index + 1).ToString(), suffix) :
33-
string.Concat(",", parameter.ActualName, "=>$", (index + 1).ToString(), suffix);
27+
string.Concat(Consts.Comma, Consts.Dollar, indexStr, suffix) :
28+
string.Concat(Consts.Comma, parameter.ActualName, Consts.NamedParam, indexStr, suffix);
3429
}
3530

36-
public string? AppendEmpty() => ")";
31+
public string? AppendEmpty() => Consts.CloseParenthesisStr;
3732
}
3833

3934
public class RoutineSourceCustomTypesParameterFormatter : IRoutineSourceParameterFormatter
@@ -42,36 +37,64 @@ public class RoutineSourceCustomTypesParameterFormatter : IRoutineSourceParamete
4237

4338
public string FormatCommand(Routine routine, NpgsqlParameterCollection parameters)
4439
{
45-
var sb = new StringBuilder(routine.Expression);
40+
var sb = new StringBuilder(routine.Expression, routine.Expression.Length + parameters.Count * 20);
4641
var count = parameters.Count;
42+
43+
var culture = CultureInfo.InvariantCulture;
44+
4745
for (var i = 0; i < count; i++)
4846
{
49-
NpgsqlRestParameter parameter = (NpgsqlRestParameter)parameters[i];
50-
var suffix = parameter.TypeDescriptor.IsCastToText() ? $"::{parameter.TypeDescriptor.OriginalType}" : "";
47+
var parameter = (NpgsqlRestParameter)parameters[i];
48+
var typeDescriptor = parameter.TypeDescriptor;
49+
50+
var suffix = typeDescriptor.IsCastToText() ?
51+
string.Concat(Consts.DoubleColon, typeDescriptor.OriginalType) :
52+
string.Empty;
53+
5154
if (i > 0)
5255
{
5356
sb.Append(Consts.Comma);
5457
}
55-
if (parameter.TypeDescriptor.CustomType is null)
58+
59+
var indexStr = (i + 1).ToString(culture);
60+
61+
if (typeDescriptor.CustomType is null)
5662
{
57-
sb.Append(parameter.ActualName is null ?
58-
string.Concat("$", (i + 1).ToString(), suffix) :
59-
string.Concat(parameter.ActualName, "=>$", (i + 1).ToString()));
63+
if (parameter.ActualName is null)
64+
{
65+
sb.Append(Consts.Dollar)
66+
.Append(indexStr)
67+
.Append(suffix);
68+
}
69+
else
70+
{
71+
sb.Append(parameter.ActualName)
72+
.Append(Consts.NamedParam)
73+
.Append(indexStr);
74+
}
6075
}
6176
else
6277
{
63-
if (parameter.TypeDescriptor.CustomTypePosition == 1)
78+
if (typeDescriptor.CustomTypePosition == 1)
6479
{
65-
sb.Append(parameter.TypeDescriptor.OriginalParameterName);
66-
sb.Append("=>row(");
80+
sb.Append(typeDescriptor.OriginalParameterName)
81+
.Append(Consts.OpenRow);
6782
}
68-
sb.Append(string.Concat("$", (i + 1).ToString(), suffix));
69-
if (i == count - 1 || parameter.TypeDescriptor.CustomTypePosition != ((NpgsqlRestParameter)parameters[i + 1]).TypeDescriptor.CustomTypePosition - 1)
83+
84+
sb.Append(Consts.Dollar)
85+
.Append(indexStr)
86+
.Append(suffix);
87+
88+
if (i == count - 1 ||
89+
typeDescriptor.CustomTypePosition !=
90+
((NpgsqlRestParameter)parameters[i + 1]).TypeDescriptor.CustomTypePosition - 1)
7091
{
71-
sb.Append(string.Concat(")::", parameter.TypeDescriptor.CustomType));
92+
sb.Append(Consts.CloseRow)
93+
.Append(typeDescriptor.CustomType);
7294
}
7395
}
7496
}
97+
7598
sb.Append(Consts.CloseParenthesis);
7699
return sb.ToString();
77100
}

NpgsqlRestClient/Builder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ public static bool ConfigureResponseCompression()
419419

420420
// Connection doesn't participate in ambient TransactionScope
421421
connectionStringBuilder.Enlist = false;
422+
connectionStringBuilder.NoResetOnClose = true;
422423

423424
connectionString = connectionStringBuilder.ConnectionString;
424425
connectionStringBuilder.Remove("password");

NpgsqlRestClient/NpgsqlRestClient.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<InvariantGlobalization>true</InvariantGlobalization>
99
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
1010
<PublishAot>true</PublishAot>
11-
<Version>2.6.0</Version>
11+
<Version>2.7.0</Version>
1212
</PropertyGroup>
1313

1414
<ItemGroup>

PerfomanceTests/k6/script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import http from "k6/http";
33
import { textSummary } from 'https://jslib.k6.io/k6-summary/0.0.2/index.js';
44

55
const now = new Date();
6-
const stamp = '2_15__2__' + now.getFullYear() +
6+
const stamp = '2_16__0__' + now.getFullYear() +
77
String(now.getMonth() + 1).padStart(2, '0') +
88
String(now.getDate()).padStart(2, '0') +
99
String(now.getHours()).padStart(2, '0') +

0 commit comments

Comments
 (0)