Sharpify.Data 2.3.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Sharpify.Data --version 2.3.0                
NuGet\Install-Package Sharpify.Data -Version 2.3.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sharpify.Data" Version="2.3.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sharpify.Data --version 2.3.0                
#r "nuget: Sharpify.Data, 2.3.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Sharpify.Data as a Cake Addin
#addin nuget:?package=Sharpify.Data&version=2.3.0

// Install Sharpify.Data as a Cake Tool
#tool nuget:?package=Sharpify.Data&version=2.3.0                

CHANGELOG

v2.3.0

  • The codebase was refactored and separated into smaller files, to make it much easier to work with.
  • Upserts of all overloads and entry points will now throw an exception if the value is null. This change was made to ensure the integrity of TryGetValue (from all variants) as it checks nullability of the value to ensure the key exists. This is also no point to add null values, as they are not meaningful data, by enforcing not null, the code becomes simpler, and less error prone.
  • Added StringEncoding choice to DatabaseConfiguration, it defaults to UTF8, but can also be UTF16, UTF8 requires less memory in default cases, but UTF16 can be more efficient if most of the strings are Unicode.
  • The factory methods named Create and CreateAsync were renamed to CreateOrLoad and CreateOrLoadAsync respectively, which better explains exactly what they do at a glance. This should make more sense to code reviewers who are not familiar with the package.
  • Filtering
    • IDatabaseFilter which is the abstraction of the filters now has proxies for Serialize and SerializeAsync which previously couldn't be accessed via this layer, but may be required if SerializeOnUpdate=false.
    • DatabaseFilter<T> where T : IMemoryPackable<T> was renamed to MemoryPackDatabaseFilter<T>, and the Database method to create an instance was renamed from Database.FilterByType<T> to CreateMemoryPackFilter<T>.
    • A new filter is introduced: FlexibleDatabaseFilter<T> where T : IFilterable<T>, which enables filtering on any type, without depending on MemoryPack implementation, for this an interface IFilterable<T> was also added, the interface will require implementing a few methods which dictate how to serialize and deserialize the specific value type. The FlexibleDatabaseFilter inturn will use those implementation to provide the same experience. The filter can be created by Database.CreateFlexibleFilter<T>
  • All JSON based T overloads now require a JsonTypeInfo<T> instead of the JsonSerializerContext, this change increases safety in cases where a JsonSerializerContext which didn't implement T would still be accepted and an exception would've been thrown at runtime, All the changes necessary at the client side are to add .T at the end of JsonSerializerContext.Default parameter.

Workaround for broken NativeAot support from MemoryPack

As of writing this, MemoryPack's NativeAot support is broken, for any type that isn't already in their cached types, the MemoryPackFormatterProvider uses reflection to get the formatter, which fails in NativeAot. As a workaround, we need to add the formatters ourselves, to do this, take any 1 static entry point, that activates before the database is loaded, and add this:

// for every T type that relies on MemoryPack for serialization, and their inheritance hierarchy
// This includes types that implement IMemoryPackable (i.e types that are decorated with MemoryPackable)
MemoryPackFormatterProvider.Register<T>();
// If the type is a collection or dictionary use the other corresponding overloads:
MemoryPackFormatterProvider.RegisterCollection<TCollection, TElement>();
// or
MemoryPackFormatterProvider.RegisterDictionary<TDictionary, TKey, TValue>();
// and so on...
// for all overloads check peek the definition of MemoryPackFormatterProvider, or their Github Repo

Note: Make sure you don't create a new static constructor in those types, MemoryPack already creates those, you will need to find a different entry point.

With this the serializer should be able to bypass the part using reflection, and thus work even on NativeAot.

P.S. The base type of the Database is already registered the same way on its own static constructor.

Announcement

Internal benchmarks already show a considerable performance improvement in the .NET8 version vs .NET7, and there are already multiple cases where the separate implementations have to be made in order to change to accommodate both versions, with .NET9 release approaching, more cases like this are expected, due the added complexity, .NET7 support will be dropped with the release of version 2.4.0 in the future. Codebases that are enable to migrate to newer .NET version will be forced to use older version of Sharpify.Data.

.NET8 support will be maintained much longer since it is an LTS release.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.6.0 79 11/13/2024
2.5.0 83 7/30/2024
2.4.1 84 6/3/2024
2.4.0 82 5/30/2024
2.3.0 125 4/17/2024
2.2.0 132 3/2/2024
2.1.3 114 1/25/2024
2.1.2 103 1/25/2024
2.1.1 107 1/25/2024
2.1.0 127 1/25/2024
2.0.2 103 1/23/2024
2.0.1 104 1/22/2024
2.0.0 99 1/20/2024
1.1.0 116 1/15/2024
1.0.3 125 1/8/2024
1.0.2 130 1/5/2024
1.0.1 124 1/4/2024
1.0.0 120 1/4/2024