-
-
Notifications
You must be signed in to change notification settings - Fork 35
feat: support Dapper overloads with CommandDefinition #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: support Dapper overloads with CommandDefinition #153
Conversation
| } | ||
|
|
||
| // we want a common understanding of the setup between the analyzer and generator | ||
| internal static Location SharedParseArgsAndFlags(in ParseState ctx, IInvocationOperation op, ref OperationFlags flags, out string? sql, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put viaCommandDefinition in OperationFlags
| global::System.Diagnostics.Debug.Assert(command.Buffered is false); | ||
| global::System.Diagnostics.Debug.Assert(command.Parameters is null); | ||
|
|
||
| return global::Dapper.DapperAotExtensions.Command(cnn, command.Transaction, command.CommandText, command.CommandType ?? default, command.CommandTimeout ?? default, DefaultCommandFactory).ExecuteScalarAsync<string>(command.Parameters, cancellationToken: command.CancellationToken); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- check if it works at all
- if it does not and we cant detect it; we should let user know via analyzer warning / just not generate AOT out of it
- if it does - its ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if parameters is null - then it is probably fine, we will not fallback to any specific type handler
Dapper.AOT doesn't intercept CommandDefinition overloads yet, so CancellationToken cannot be passed to Dapper queries in trimmed builds. Tracking: DapperLib/DapperAOT#153 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Current PR adds a support to parse use cases with
CommandDefinition.Usage check
If an user invocation has 2 or more parameters which are 1)
cnn; 2)commandwhere it is of typeCommandDefinition, then I consider it to be a proper Dapper usage withCommandDefinition.DapperAnalyzer has built-in argument processing to fix sql / detect buffering etc.
DapperAOT/src/Dapper.AOT.Analyzers/CodeAnalysis/DapperAnalyzer.cs
Lines 514 to 517 in 4f8cd50
Unfortunately, it is too complicated to cover many other usages of
CommandDefinition, so I only added a case for in-place object creation:Other cases will work (i.e.
CommandDefinitionas local variable), but will not have argument processing done.Generator
Since the Dapper.AOT has its own API, it is very easy to just pass in the same parameters who are the
CommandDefinitionmembers. So I just do this for example:CommandDefinitionimplementation is very convenient for such usage - for example I dont care what CancellationToken to pass in, because if it is not passed intoCommandDefinition, it will be simply default. So I just map all members into the underlying SQL APITests
Added code-generation + integration tests.
Fixes #112