BTDB 33.8.3

dotnet add package BTDB --version 33.8.3
                    
NuGet\Install-Package BTDB -Version 33.8.3
                    
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="BTDB" Version="33.8.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BTDB" Version="33.8.3" />
                    
Directory.Packages.props
<PackageReference Include="BTDB" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BTDB --version 33.8.3
                    
#r "nuget: BTDB, 33.8.3"
                    
#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.
#:package BTDB@33.8.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BTDB&version=33.8.3
                    
Install as a Cake Addin
#tool nuget:?package=BTDB&version=33.8.3
                    
Install as a Cake Tool

BTDB

BTDB Logo

Currently this project these parts:

  • Key Value Database
  • Wrapped Dynamic IL generation with debugging + extensions
  • IOC Container (SourceGenerator based)
  • Object Database with Relations
  • Snappy Compression
  • Event Storage
  • Bon (Binary object notation)
  • Incremental SourceGenerator for IOC Container factory generation

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.


Breaking changes

33.0.0

KeyValueDB

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.

ObjectDB

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.


Key Value Database

Features

  • This is Key Value store written in C# with implementation on native heap (has also prefix compression). InMemory version uses managed heap.
  • It is easily embeddable.
  • One storage is just one directory.
  • It has ACID properties with MVCC.
  • At one time there could be multiple read only transactions and one read/write transaction.
  • Export/Import to stream - could be used for compaction, snapshotting
  • Automatic compaction
  • Customizable compression (key index file could be Brotli compressed)
  • Relatively Fast DB Open due to key index file - though it still needs to load all keys to memory
  • Inspired by Bitcask [https://github.com/basho/bitcask/blob/develop/doc/bitcask-intro.pdf]

Design limits

  • All keys data needs to fit in RAM
  • Maximum Key length is limited by 31bits (2GB).
  • Maximum value length is limited by 31bits (2GB).

Sample code

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();
    }
}

Roadmap

  • Everything is there just use it

Wrapped Dynamic IL generation with debugging + extensions

This help you to write fluent code which generates IL code in runtime. It is used in Object Database part.

Sample code

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();

Roadmap

  • Add support for all IL instructions as needed
  • Deprecate this by replacing its usages by Source Generator

Object Database

Features

  • Builds on top of Key Value Database and Reflection.Emit extensions.
  • It stores Plain .Net Objects and only their public properties with getters and setters.
  • All ACID and MVCC properties are preserved of course.
  • Automatic upgrading of model on read with dynamically generated optimal IL code.
  • Automatic versioning of model changes.
  • Enumeration of all objects
  • Each object type could store its "singleton" - very useful for root objects
  • Relations - Table with primary key and multiple secondary keys
  • By default objects are stored inline in parent object, use IIndirect for objects with Oid which will load lazily

Documentation: [https://github.com/Bobris/BTDB/blob/master/Doc/ODBDictionary.md]

Relations doc: [https://github.com/Bobris/BTDB/blob/master/Doc/Relations.md]

Sample code

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);
}

Roadmap

  • Support more types of properties
  • Free text search (far future if ever)

Event storage

Features

  • Optimal serialization with metadata
  • Deserialization also to dynamic
  • Storage is transactional
  • As storage could be used Azure Page Blobs
  • EventStorage2 is specialized to be used with Kafka, metadata are stored in separate topic

Bon

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.


Snappy Compression

Features

  • Ported and inspired mainly by Go version of Snappy Compression [http://code.google.com/p/snappy/]
  • Fully compatible with original
  • Fully managed and safe implementation
  • Compression is aborted when target buffer size is not big enough

Roadmap

  • Some speed optimizations around Spans would help
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on BTDB:

Package Downloads
Bbcore.Lib

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
33.8.3 2,395 6/1/2025
33.8.2 310 5/27/2025
33.8.1 225 5/26/2025
33.8.0 219 5/26/2025
33.7.3 220 5/25/2025
33.7.2 541 5/12/2025
33.7.1 363 5/6/2025
33.7.0 276 4/29/2025
33.6.9 7,078 11/7/2025
33.6.8 280 6/9/2025
33.6.7 76,069 5/27/2025
33.6.6 204 5/25/2025
33.6.5 11,361 5/12/2025
33.6.4 14,209 4/28/2025
33.6.3 4,165 4/16/2025
33.6.2 2,946 4/11/2025
33.6.1 234 4/10/2025
33.6.0 268 4/10/2025
33.5.0 18,492 4/6/2025
33.4.4 4,281 3/30/2025
33.4.3 1,186 3/27/2025
33.4.2 222 3/26/2025
33.4.1 205 3/21/2025
33.4.0 233 3/20/2025
33.3.0 1,141 2/24/2025
33.2.0 188 2/13/2025
33.1.3 27,915 1/14/2025
33.1.2 222 1/14/2025
33.1.1 218 1/14/2025
33.1.0 209 1/13/2025
33.0.7 227 1/13/2025
33.0.6 220 1/13/2025
33.0.5 159 1/13/2025
33.0.4 185 1/12/2025
33.0.3 222 1/9/2025
33.0.2 178 1/9/2025
33.0.1 175 1/7/2025
33.0.0 214 1/3/2025
32.17.0 47,785 12/17/2024
32.16.4 31,565 11/6/2024
32.16.3 408 10/25/2024
32.16.2 11,632 10/14/2024
32.16.1 13,081 10/11/2024
32.16.0 17,160 10/4/2024
32.15.1 832 8/29/2024
32.15.0 208 8/29/2024
32.14.1 1,537 8/17/2024
32.14.0 217 8/4/2024
32.13.1 30,570 7/31/2024
32.13.0 2,167 7/26/2024
32.12.1 375 7/21/2024
32.12.0 250 7/18/2024
32.11.0 4,089 7/6/2024
32.10.0 4,844 6/20/2024
32.9.0 256 6/15/2024
32.8.0 10,120 6/14/2024
32.7.1 17,576 5/15/2024
32.7.0 195 5/14/2024
32.6.2 3,731 5/6/2024
32.6.1 204 5/6/2024
32.6.0 275 5/1/2024
32.5.0 54,578 2/29/2024
32.4.29 546 2/26/2024
32.4.28 205 2/26/2024
32.4.26 17,983 2/21/2024
32.4.25 2,142 2/20/2024
32.4.24 604 2/19/2024
32.4.23 3,649 2/14/2024
32.4.22 230 2/13/2024
32.4.21 3,945 2/12/2024
32.4.20 363 2/7/2024
32.4.19 248 2/7/2024
32.4.18 357 2/1/2024
32.4.17 200 1/31/2024
32.4.16 192 1/30/2024
32.4.15 335 1/29/2024
32.4.14 214 1/29/2024
32.4.13 194 1/27/2024
32.4.12 196 1/26/2024
32.4.11 227 1/26/2024
32.4.10 219 1/26/2024
32.4.9 202 1/26/2024
32.4.8 191 1/26/2024
32.4.7 183 1/25/2024
32.4.6 214 1/25/2024
32.4.5 219 1/25/2024
32.4.4 176 1/24/2024
32.4.3 201 1/23/2024
32.4.2 188 1/23/2024
32.4.1 202 1/22/2024
32.4.0 214 1/21/2024
32.3.2 234 1/19/2024
32.3.1 177 1/18/2024
32.3.0 214 1/18/2024
32.2.0 234 1/17/2024
32.1.0 216 1/14/2024
32.0.3 239 1/8/2024
32.0.2 699 1/2/2024
32.0.1 205 1/2/2024
32.0.0 252 1/1/2024
31.15.0 9,902 1/22/2024
31.14.0 24,120 11/23/2023
31.13.0 4,467 11/21/2023
31.12.7 1,730 11/16/2023
31.12.6 359 11/16/2023
31.12.5 312 11/13/2023 31.12.5 is deprecated because it has critical bugs.
31.12.4 725 11/12/2023
31.12.3 8,991 10/30/2023
31.12.2 4,748 10/16/2023
31.12.1 5,206 10/5/2023
31.12.0 346 9/17/2023
31.11.3 30,233 8/10/2023
31.11.2 292 8/9/2023
31.11.1 289 8/8/2023
31.11.0 5,055 8/8/2023
31.10.0 1,164 8/3/2023
31.9.0 316 8/1/2023
31.8.2 2,841 8/1/2023
31.8.1 278 8/1/2023
31.8.0 25,141 6/8/2023
31.7.0 10,432 5/23/2023
31.6.0 333 5/21/2023
31.5.2 1,813 5/16/2023
31.5.1 17,788 4/13/2023
31.5.0 9,027 3/28/2023
31.4.3 3,829 3/24/2023
31.4.2 3,944 3/21/2023
31.4.1 415 3/21/2023
31.4.0 457 3/21/2023
31.3.2 17,191 2/20/2023
31.3.1 769 2/17/2023
31.3.0 420 2/15/2023
31.2.1 460 2/15/2023
31.2.0 2,146 2/15/2023
31.1.1 27,282 2/4/2023
31.1.0 484 2/3/2023
31.0.0 497 2/3/2023
30.5.0 14,059 1/10/2023
30.4.0 710 1/9/2023
30.3.0 6,917 1/3/2023
30.2.2 10,506 1/2/2023
30.2.1 557 1/2/2023
30.2.0 589 1/1/2023
30.1.0 493 12/21/2022
30.0.0 23,209 11/14/2022
29.12.1 613 11/3/2022
29.12.0 1,054 11/2/2022
29.11.0 672 9/7/2022
29.10.1 675 8/1/2022
29.10.0 660 8/1/2022
29.9.1 689 7/22/2022
29.9.0 696 7/17/2022
29.8.0 727 6/13/2022
29.7.0 687 6/8/2022
29.6.0 705 6/5/2022
29.5.0 711 5/18/2022
29.4.0 707 5/17/2022
29.3.0 725 5/13/2022
29.2.0 712 5/3/2022
29.1.1 8,929 3/29/2022
29.1.0 701 3/28/2022
29.0.0 743 2/28/2022
28.3.2 786 1/21/2022
28.3.1 742 1/21/2022
28.3.0 594 1/4/2022
28.2.0 570 12/19/2021
28.1.2 627 12/7/2021
28.1.1 540 12/6/2021
28.1.0 584 11/29/2021
28.0.0 599 11/17/2021
27.0.3 626 11/17/2021
27.0.2 1,911 11/7/2021
27.0.0 592 11/2/2021
26.2.1 877 5/8/2021
24.0.2 21,419 6/15/2020
24.0.1 990 6/13/2020
24.0.0 845 6/13/2020
23.1.0 1,028 5/23/2020
23.0.0 876 5/18/2020
22.2.2 883 5/14/2020
22.2.1 867 5/14/2020
22.2.0 848 5/13/2020
22.1.0 865 5/12/2020
22.0.0 880 5/10/2020
21.0.0 909 5/6/2020
20.3.0 909 5/2/2020
20.0.0 995 4/25/2020
19.5.0 1,420 3/10/2020
19.4.0 1,888 11/30/2019
19.3.0 1,315 11/6/2019
19.2.0 977 11/3/2019
19.1.0 1,186 10/13/2019
19.0.0 1,014 10/6/2019
18.2.2 1,295 9/19/2019
18.2.1 1,079 9/16/2019
18.2.0 1,095 9/8/2019
18.1.0 1,106 9/2/2019
18.0.0 1,004 9/1/2019
17.10.0 1,044 8/28/2019
17.9.0 2,206 7/24/2019
17.8.0 1,938 7/13/2019
17.7.0 1,635 6/9/2019
17.6.0 1,583 5/10/2019
17.5.2 1,602 5/9/2019
17.5.1 1,614 5/9/2019
17.5.0 1,643 4/16/2019
17.4.2 1,766 2/12/2019
17.4.1 1,671 2/6/2019
17.4.0 1,660 2/6/2019
17.3.0 1,672 1/25/2019
17.2.0 1,722 1/8/2019
17.1.0 1,667 12/24/2018
17.0.1 1,712 12/20/2018
17.0.0 1,738 12/16/2018
16.2.1 1,793 12/11/2018
14.12.2 1,937 10/15/2018
14.7.0 2,121 8/16/2018
14.6.0 2,057 8/2/2018
14.5.2 2,298 7/9/2018
14.5.1 2,285 6/20/2018
14.5.0 2,277 6/13/2018
14.4.0 2,311 6/10/2018
14.3.0 2,342 6/10/2018
14.2.1 2,316 6/7/2018
14.2.0 2,038 6/6/2018
14.1.0 2,054 6/6/2018
14.0.0 2,246 6/5/2018
13.1.0 2,299 6/3/2018
13.0.0 2,332 5/7/2018
12.7.0 2,411 4/15/2018
12.6.1 2,383 3/23/2018
12.6.0 2,374 3/18/2018
12.5.1 2,347 2/26/2018
12.5.0 2,389 2/12/2018
12.4.0 2,406 1/31/2018
12.3.0 2,332 1/29/2018
12.2.0 2,387 1/9/2018
12.1.0 2,418 12/10/2017
12.0.0 2,164 12/3/2017
11.10.1 2,329 11/20/2017
11.10.0 2,333 11/3/2017
11.9.1 2,343 11/2/2017
11.9.0 2,285 10/31/2017
11.8.1 2,315 10/30/2017
11.8.0 2,288 10/28/2017
11.7.0 2,340 10/26/2017
11.6.5 2,360 10/24/2017
11.6.4 2,333 10/23/2017
11.6.3 2,374 10/20/2017
11.6.2 2,320 10/19/2017
11.6.1 2,328 10/18/2017
11.6.0 2,329 10/15/2017
11.5.0 2,291 10/8/2017
11.4.0 2,560 9/6/2017
11.3.0 2,328 9/4/2017
11.2.0 2,131 8/20/2017
11.1.0 2,065 8/9/2017
11.0.4 2,164 7/30/2017
11.0.3 2,193 7/24/2017
11.0.2 2,277 7/21/2017
11.0.1 2,140 7/21/2017
11.0.0 2,196 7/19/2017
10.6.0 2,197 6/27/2017
10.5.2 2,255 6/23/2017
10.5.1 2,244 6/22/2017
10.5.0 2,197 6/17/2017
10.4.3 2,162 5/31/2017
10.4.2 2,129 5/25/2017
10.4.1 2,206 5/22/2017
10.4.0 2,152 5/19/2017
10.3.0 2,140 5/11/2017
10.2.0 2,171 4/21/2017
10.1.2 2,143 4/14/2017
10.1.1 2,143 4/12/2017
10.1.0 2,186 4/7/2017
10.0.2 2,135 3/28/2017
10.0.1 2,154 3/26/2017
10.0.0 2,157 3/20/2017
9.4.0 2,158 3/12/2017
9.3.1 2,178 3/9/2017
9.3.0 2,189 3/6/2017
9.2.1 2,131 2/28/2017
9.2.0 2,247 2/21/2017
9.1.1 2,160 2/15/2017
9.1.0 2,273 2/8/2017
9.0.4 2,276 1/23/2017
9.0.3 2,226 12/20/2016
9.0.2 2,152 12/18/2016
9.0.0 2,223 12/12/2016
8.0.1 2,222 12/10/2016
8.0.0 2,229 11/28/2016
7.0.0 2,226 11/23/2016
6.0.0 2,714 11/17/2016
5.7.0 2,782 11/3/2016
5.6.4 2,719 11/2/2016
5.6.3 2,414 10/30/2016
5.6.2 2,455 10/26/2016
5.6.1 2,402 10/26/2016
5.6.0 2,419 10/24/2016
5.5.0 2,471 10/22/2016
5.4.0 2,497 10/21/2016
5.3.2 2,506 10/16/2016
5.3.1 2,439 9/14/2016
5.3.0 2,532 9/13/2016
5.2.0 2,465 9/11/2016
5.1.0 2,461 9/9/2016
5.0.0 2,414 9/8/2016
4.0.1 2,430 9/8/2016
4.0.0 2,399 9/7/2016
3.6.0 2,402 9/4/2016
3.5.0 2,464 9/1/2016
3.4.0 2,482 8/8/2016
3.3.0 2,506 7/18/2016
3.2.3 2,522 6/28/2016
3.2.2 2,900 6/15/2016
3.2.1 2,499 6/7/2016
3.2.0 2,495 6/5/2016
3.1.0 2,493 5/30/2016
3.0.0 2,568 5/19/2016
2.12.0 2,585 4/10/2016
2.11.0 2,640 4/9/2016
2.10.1 2,320 3/16/2016
2.10.0 2,581 2/17/2016
2.9.1 2,565 12/13/2015
2.9.0 2,567 12/8/2015
2.8.5 2,612 11/27/2015
2.8.4 2,593 11/27/2015
2.8.2 2,578 11/4/2015
2.8.1 2,519 11/4/2015
2.8.0 2,578 11/1/2015
2.7.0 2,761 6/27/2015
2.6.3 2,631 6/16/2015
2.6.2 2,735 6/14/2015
2.6.1 2,651 5/15/2015
2.6.0 2,721 4/13/2015
2.5.3 2,743 1/26/2015
2.5.2 2,962 12/13/2014
2.5.1 2,875 11/18/2014
2.5.0 2,742 10/13/2014
2.4.5 2,675 10/6/2014
2.4.4 2,861 6/3/2014
2.4.3 2,706 6/2/2014
2.4.2 2,738 5/30/2014
2.4.0 3,081 3/14/2014
2.3.2 2,640 2/3/2014
2.3.1 2,486 12/15/2013
2.3.0 2,487 12/14/2013
2.2.2 2,592 12/12/2013
2.2.1 2,546 12/11/2013
2.2.0 2,610 12/8/2013
2.1.0 2,594 12/8/2013
2.0.2 2,642 12/2/2013
2.0.1 2,648 11/26/2013
2.0.0 2,587 11/14/2013
1.2.1 2,566 11/11/2013
1.1.0 2,616 9/5/2013
1.0.0 2,617 9/1/2013