SourceGenerator for BTDB features to not need runtime code generation
$ dotnet add package BTDB.SourceGenerator
Currently this project these parts:
All code written in C# 12 and licensed under very permissive MIT license. Targeting .Net 9.0, main code has just 2 dependencies (Microsoft.Extensions.Primitives, Microsoft.Extensions.ObjectPool). Code is tested using xUnit Framework. Used in production on Windows and Linux, on MacOS works as well. Please is you find it useful or have questions, write me e-mail boris.letocha@gmail.com so I know that it is used. It is available in Nuget http://www.nuget.org/packages/BTDB. Source code drops are Github releases.
Nearly all IKeyValueDBTransaction methods moved into IKeyValueDBCursor. IKeyValueDBTransaction has method CreateCursor() to create IKeyValueDBCursor. Created cursor must not be used after transaction Commit. And all cursors must be disposed before transaction is disposed. It makes implementation of custom transaction wrappers more difficult, look at KeyValueDBTransactionWithCount for example.
Positive breaking change is that DB could be modified in parallel to enumeration. It is possible due to KeyValueDB has now Cursors which correctly update their position even when DB is modified. It is even possible to delete current object in enumeration and enumeration will still continue correctly.
Relations cannot return IEnumerator<T> anymore, it must be replaced by IEnumerable<T>. Also IOrderedDictionaryEnumerator is now inherited from IDisposable and must be disposed. Forgetting dispose will cause exception during transaction disposal.
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateOrUpdateKeyValue(new byte[] { 1 }, new byte[100000]);
tr.Commit();
}
}
This help you to write fluent code which generates IL code in runtime. It is used in Object Database part.
var method = ILBuilder.Instance.NewMethod<Func<Nested>>("SampleCall");
var il = method.Generator;
var local = il.DeclareLocal(typeof(Nested), "n");
il
.Newobj(() => new Nested())
.Dup()
.Stloc(local)
.Ldstr("Test")
.Call(() => ((Nested)null).Fun(""))
.Ldloc(local)
.Ret();
var action = method.Create();
Documentation: [https://github.com/Bobris/BTDB/blob/master/Doc/ODBDictionary.md]
Relations doc: [https://github.com/Bobris/BTDB/blob/master/Doc/Relations.md]
public class Person
{
public string Name { get; set; }
public uint Age { get; set; }
}
using (var tr = _db.StartTransaction())
{
tr.Store(new Person { Name = "Bobris", Age = 35 });
tr.Commit();
}
using (var tr = _db.StartTransaction())
{
var p = tr.Enumerate<Person>().First();
Assert.AreEqual("Bobris", p.Name);
Assert.AreEqual(35, p.Age);
}
Bon Binary object notation is allows creating and reading JavaScript/C# values with extensions like Dictionary/Map into binary notation. It is much faster to parse, write, skip, search by keys than JSON, size will be also smaller in most cases, in some cases much more smaller.