Add SqlFileSource:LogCommandText setting to control multi-command SQL… · sdaves/NpgsqlRest@be1cf1d · GitHub
Skip to content

Commit be1cf1d

Browse files
vbilopavclaude
andcommitted
Add SqlFileSource:LogCommandText setting to control multi-command SQL log verbosity
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6f62353 commit be1cf1d

8 files changed

Lines changed: 55 additions & 4 deletions

File tree

NpgsqlRest/NpgsqlRestEndpoint.cs

Lines changed: 10 additions & 2 deletions

NpgsqlRest/Routine.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ public class Routine
166166
/// True if this routine uses multi-command rendering (JSON object with named result sets).
167167
/// </summary>
168168
public bool IsMultiCommand => MultiCommandInfo is not null;
169+
170+
/// <summary>
171+
/// When true, multi-command log includes full SQL text. When false, only file path and statement count.
172+
/// </summary>
173+
public bool LogCommandText { get; set; }
169174
}
170175

171176
/// <summary>

NpgsqlRestClient/ConfigSchemaGenerator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ public static partial class ConfigSchemaGenerator
460460
["NpgsqlRest:SqlFileSource:UnnamedSingleColumnSet"] = "When true, queries returning a single column produce a flat JSON array of values (e.g., [\"a\", \"b\", \"c\"]) instead of an array of objects (e.g., [{\"col\": \"a\"}, {\"col\": \"b\"}]). This matches the behavior of PostgreSQL functions returning setof single values. Default is true.",
461461
["NpgsqlRest:SqlFileSource:NestedJsonForCompositeTypes"] = "When true, composite type columns in return results are serialized as nested JSON objects.\nFor example, a column \"data\" of type \"my_type(id int, name text)\" becomes {\"data\": {\"id\": 1, \"name\": \"test\"}}\ninstead of the default flat structure {\"id\": 1, \"name\": \"test\"}.\nDefault is false for backward compatibility. Can also be enabled per-endpoint with the 'nested' annotation.",
462462
["NpgsqlRest:SqlFileSource:SkipNonQueryCommands"] = "When true, non-query commands (BEGIN, COMMIT, SET, DO blocks, etc.) in multi-command SQL files are still executed but excluded from the JSON response result keys.\nDefault is true.",
463+
["NpgsqlRest:SqlFileSource:LogCommandText"] = "When true, multi-command SQL file endpoints include the full SQL text in command logs.\nWhen false (default), only the file path and statement count are logged.\nSingle-command SQL files always log the SQL text regardless of this setting.\nThis only applies when LogCommands is true.",
463464
};
464465

465466
/// <summary>

NpgsqlRestClient/ConfigTemplate.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2630,7 +2630,14 @@ public static partial class ConfigSchemaGenerator
26302630
// are still executed but excluded from the JSON response result keys.
26312631
// Default is true.
26322632
//
2633-
"SkipNonQueryCommands": true
2633+
"SkipNonQueryCommands": true,
2634+
//
2635+
// When true, multi-command SQL file endpoints include the full SQL text in command logs.
2636+
// When false (default), only the file path and statement count are logged.
2637+
// Single-command SQL files always log the SQL text regardless of this setting.
2638+
// This only applies when LogCommands is true.
2639+
//
2640+
"LogCommandText": false
26342641
}
26352642
}
26362643
}

NpgsqlRestClient/appsettings.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2621,7 +2621,14 @@
26212621
// are still executed but excluded from the JSON response result keys.
26222622
// Default is true.
26232623
//
2624-
"SkipNonQueryCommands": true
2624+
"SkipNonQueryCommands": true,
2625+
//
2626+
// When true, multi-command SQL file endpoints include the full SQL text in command logs.
2627+
// When false (default), only the file path and statement count are logged.
2628+
// Single-command SQL files always log the SQL text regardless of this setting.
2629+
// This only applies when LogCommands is true.
2630+
//
2631+
"LogCommandText": false
26252632
}
26262633
}
26272634
}

changelog.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,20 @@ On `ApplicationStopping`, all broadcaster channels are now completed, causing SS
805805

806806
---
807807

808+
### `SqlFileSource:LogCommandText` Setting
809+
810+
New setting `LogCommandText` in the `SqlFileSource` configuration (default `false`) controls whether multi-command SQL file endpoints include the full SQL text in debug command logs. When false, only the file path and statement count are logged:
811+
812+
```
813+
[DBG] -- POST http://127.0.0.1:8080/api/send-message
814+
-- $1 text = 'hello'
815+
SQL file: sql/send-message.sql (5 statements)
816+
```
817+
818+
When true, the full SQL body is logged (previous behavior). Single-command SQL file endpoints always log the SQL text regardless of this setting. This only applies when `LogCommands` is true.
819+
820+
---
821+
808822
### New Annotation: `@void` — Force Void Response
809823

810824
New comment annotation `void` (alias: `void_result`) that forces an endpoint to return 204 No Content instead of a JSON response. All statements are executed for side effects only.

plugins/NpgsqlRest.SqlFileSource/SqlFileSource.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ columnTypeDescriptors[i].ArrayCompositeFieldNames is not null &&
408408
if (multiCommandInfo is not null)
409409
{
410410
routine.MultiCommandInfo = multiCommandInfo;
411+
routine.LogCommandText = options.LogCommandText;
411412
}
412413

413414
return (routine, SqlFileParameterFormatter.Instance);

plugins/NpgsqlRest.SqlFileSource/SqlFileSourceOptions.cs

Lines changed: 8 additions & 0 deletions

0 commit comments

Comments
 (0)