Skip to content

kasthack-labs/kasthack.AutoTagging

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kasthack.AutoTagging

What

Nuget NuGet GitHub release license .NET Status Patreon pledges Patreon patrons

Automatic SQL tagging proxies for .NET:

  • Dapper is currently supported.
  • A custom DbConnection proxy that would be able to capture proper tags without recompilation is in development.

Why does this exist?

I needed a way to tag database queries in an existing project without having to rewrite a large amount of code.

Usage

  • Install nuget package kasthack.Autotagging.DapperProxy
  • Remove using Dapper from your source files.
  • Add using kasthack.Autotagging.DapperProxy to your source files or as a global using.
  • (Optional) Set TaggingSqlMapper.AppName
  • That's it! All database queries sent through Dapper will be prefixed with the following comment:
-- App: {app_name}
-- File: {callerFile}:{callerLine}
-- Method: {callerMethod}

<your query>
  • This allows your DBAs and DevOps teams to easily identify the sources of problematic queries and address them.

How does it work?

  • Source generator mirrors all Dapper methods, adds optional [Caller(MemberName|FilePath|LineNumber)] parameters to these methods, and generates a nuget-package with proxying extension methods.
  • Your code automatically picks up matching overloads, while the compiler fills in caller information during the build.