Sharpify.Data
2.3.0
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
<PackageReference Include="Sharpify.Data" Version="2.3.0" />
paket add Sharpify.Data --version 2.3.0
#r "nuget: Sharpify.Data, 2.3.0"
// 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 thevalue
isnull
. This change was made to ensure the integrity ofTryGetValue
(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 toDatabaseConfiguration
, it defaults toUTF8
, but can also beUTF16
,UTF8
requires less memory in default cases, butUTF16
can be more efficient if most of the strings areUnicode
. - The factory methods named
Create
andCreateAsync
were renamed toCreateOrLoad
andCreateOrLoadAsync
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 forSerialize
andSerializeAsync
which previously couldn't be accessed via this layer, but may be required ifSerializeOnUpdate=false
.DatabaseFilter<T> where T : IMemoryPackable<T>
was renamed toMemoryPackDatabaseFilter<T>
, and the Database method to create an instance was renamed fromDatabase.FilterByType<T>
toCreateMemoryPackFilter<T>
.- A new filter is introduced:
FlexibleDatabaseFilter<T> where T : IFilterable<T>
, which enables filtering on any type, without depending onMemoryPack
implementation, for this an interfaceIFilterable<T>
was also added, the interface will require implementing a few methods which dictate how to serialize and deserialize the specific value type. TheFlexibleDatabaseFilter
inturn will use those implementation to provide the same experience. The filter can be created byDatabase.CreateFlexibleFilter<T>
- All JSON based
T
overloads now require aJsonTypeInfo<T>
instead of theJsonSerializerContext
, this change increases safety in cases where aJsonSerializerContext
which didn't implementT
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 ofJsonSerializerContext.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 | Versions 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. |
-
net7.0
- MemoryPack (>= 1.21.0)
- Sharpify (>= 1.7.3)
-
net8.0
- MemoryPack (>= 1.21.0)
- Sharpify (>= 1.7.3)
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 |