Skip to content
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

attempt NRT makeover #1928

Merged
merged 15 commits into from
Sep 12, 2023
Merged

attempt NRT makeover #1928

merged 15 commits into from
Sep 12, 2023

Conversation

mgravell
Copy link
Member

@mgravell mgravell commented Jun 26, 2023

Functionally, the only real changes here are in a few API surfaces (not a real change, but NRT changes things slightly):

NOTE: the intention is to do a minor rev here, i.e. ship this as 2.1.0

  • type handlers take and return ?
  • {Query|Read}{First|Single}OrDefault[Async] return ?
  • ExecuteScalar[Async] return ?
  • update libs
  • package readme.md (this is the current NuGet recommendation)
  • enable [SkipLocalsInit] everywhere; simplify the remoting warning logic

for Dapper.AOT purposes (although everything here applies to any consumer), I'm also applying some tweaks to make GridReader more usable from externals; GridReader is not sealed, but was mostly unusable from custom implementations - added some things:

  • protected constructor
  • switched to Action<object?>?/object? callback rather than type-specific (so external consumers aren't bound to same types)
  • added protected int OnBeforeGrid() (pre-grid book-keeping)
  • added protected void OnAfterGrid(int) and protected Task OnAfterGridAsync(int) (post-grid book-keeping)
  • made all existing usage consistently use that OnBeforeGrid/OnAfterGrid API
  • exposed the reader and cancellation-token via protected APIs
  • allow the Identity to be constructed on-the-fly if/when needed

(the NRT issue was also partly driven from AOT)

- annotate NRTs on GridReader API
- add protected access to some of the GridReader internals
- switch GridReader callbacks to be more type-independent

docs

lib updates; deal with yellow warnings and test failures (SQL server certs and cancellation surfacing differently)

fix break

simplify proposed GridReader changes to protected OnBeforeGrid and OnAfterGrid[Async]

Builds: Bump library versions (#1935)

Tests: Upgrade dependencies for Dependabot (#1936)

I'll do a pass at all of these later, but getting CVE versions out of the pipe.

Resolving 4 alerts here: https://github.com/DapperLib/Dapper/security/dependabot

merge and lib updates

allow Identity to be constructed on-the-fly inside GridReader

fix build warnings

include readme

rev minor

- enable [SkipLocalsInit] everywhere
- use NET5_0_OR_GREATER
 for remoting check

# Conflicts:
#	Dapper/CommandDefinition.cs
#	Dapper/DefaultTypeMap.cs
#	Dapper/SqlMapper.Async.cs
#	Dapper/SqlMapper.IDataReader.cs
#	Dapper/SqlMapper.Link.cs
#	Dapper/SqlMapper.cs
#	Directory.Build.props
@mgravell
Copy link
Member Author

@NickCraver I've added API proof to this; do you have an opinion on this? otherwise, ima merge

@NickCraver
Copy link
Member

@mgravell I can this afternoon or tonight - but if not doing a release and this is blocking, happy to comment after the merge too and we can tidy to parallel - your call!

@mgravell
Copy link
Member Author

Not immediately blocking; however it is a pain to have to keep rebasing it (which is why it is heavily squashed and force-pushed), as it touches a lot

Dapper/SqlMapper.cs Outdated Show resolved Hide resolved
@NickCraver
Copy link
Member

@mgravell Tried to give good eyes here, admittedly glossed over the NRT exclusions in the Emit section as the last reviewed thing, I'll review it fresh next round (just a lot to consume in one go - nothing wrong on PR structure)

@mgravell
Copy link
Member Author

addressed all, I think

@mgravell mgravell merged commit aecffec into main Sep 12, 2023
1 of 2 checks passed
@@ -16,28 +16,28 @@ public abstract class TypeHandler<T> : ITypeHandler
/// </summary>
/// <param name="parameter">The parameter to configure</param>
/// <param name="value">Parameter value</param>
public abstract void SetValue(IDbDataParameter parameter, T value);
public abstract void SetValue(IDbDataParameter parameter, T? value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mgravell Since this causes implementers of the class to have to annotate their T value parameter as nullable, how would we handle null being passed here? What would it mean?

I know for SqlParameter.Value, DBNull means "set to null" and null means "unset." Does null carry the same "unset" connotation if implementers see it here?

Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there isn't a constraint on T, this doesn't strictly change the API shape - in particular, a TypeHandler<SomeValueType> still has SetValue(..., SomeValueType) and not SetValue(..., SomeValueType?) ; however, to answer your question: it should mean DBNull, but with the opportunity to configure the parameter correctly, and mostly just applies in the TypeHandler<SomeReferenceType> scenario, it acknowledges that the incoming parameter might be null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants