Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/valk-guard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
**/*.sql
**/*.go
**/*.py
**/*.cs

- uses: reviewdog/action-setup@v1
if: steps.changed.outputs.any_changed == 'true'
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Expected result on `main`:

```text
valk-guard-example/
├── csharp/
│ └── efcore/
├── go/
│ ├── std/
│ └── goqu/
Expand Down
48 changes: 48 additions & 0 deletions csharp/efcore/UserRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace ValkGuardExample.Data;

/// <summary>
/// Example repository demonstrating clean EF Core raw SQL usage.
/// All queries here should pass valk-guard with 0 findings.
/// </summary>
public class UserRepository
{
private readonly AppDbContext _db;

public UserRepository(AppDbContext db)
{
_db = db;
}

/// <summary>Safe: bounded SELECT with WHERE and LIMIT.</summary>
public void GetActiveUserCount()
{
_db.Database.ExecuteSqlRaw(
"SELECT count(*) FROM users WHERE active = true");
}

/// <summary>Safe: DELETE with WHERE clause.</summary>
public async Task CleanupExpiredSessions()
{
await _db.Database.ExecuteSqlRawAsync(
@"DELETE FROM orders
WHERE status = 'expired'
AND created_at < NOW() - INTERVAL '90 days'");
}

/// <summary>Safe: parameterized UPDATE with WHERE.</summary>
public void DeactivateUser(int userId)
{
_db.Database.ExecuteSqlRaw(
"UPDATE users SET active = false WHERE id = {0}", userId);
}

/// <summary>Safe: interpolated DELETE with WHERE.</summary>
public async Task RemoveUser(int userId)
{
await _db.Database.ExecuteSqlInterpolatedAsync(
$"DELETE FROM users WHERE id = {userId}");
}
}
Loading