VOOZH about

URL: https://www.nuget.org/packages/LightningDB/

⇱ NuGet Gallery | LightningDB 0.21.0




👁 Image
LightningDB 0.21.0

dotnet add package LightningDB --version 0.21.0
 
 
NuGet\Install-Package LightningDB -Version 0.21.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="LightningDB" Version="0.21.0" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LightningDB" Version="0.21.0" />
 
Directory.Packages.props
<PackageReference Include="LightningDB" />
 
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 LightningDB --version 0.21.0
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LightningDB, 0.21.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.
#:package LightningDB@0.21.0
 
 
#: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=LightningDB&version=0.21.0
 
Install as a Cake Addin
#tool nuget:?package=LightningDB&version=0.21.0
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Lightning.NET

👁 .NET Tests
👁 NuGet version

Lightning.NET is a .NET library that provides a fast and easy-to-use interface to the Lightning Memory-Mapped Database (LMDB), a high-performance key-value store. This library enables .NET developers to leverage LMDB's efficiency and reliability in their applications.

Features

  • High Performance: Direct interaction with LMDB ensures minimal overhead (no copies / 0-alloc when using Span) and maximum speed.
  • Simplicity: The API is designed to be straightforward, making it easy to integrate into existing projects.
  • Flexibility: Supports various database configurations, including handling multiple values for the same key.
  • Reliable: It is fully transactional with complete ACID semantics.

Installation

Lightning.NET is available as a NuGet package. To install it, run the following command in the Package Manager Console:

Install-Package LightningDB

Alternatively, you can install it via the .NET CLI:

dotnet add package LightningDB

Basic Usage

Here's a simple example demonstrating how to create an environment, open a database, and perform basic put and get operations:

using System;
using System.Text;
using LightningDB;

class Program
{
 static void Main()
 {
 // Specify the path to the database environment
 using var env = new LightningEnvironment("path_to_your_database");
 env.Open();

 // Begin a transaction and open (or create) a database
 using (var tx = env.BeginTransaction())
 using (var db = tx.OpenDatabase(configuration: new DatabaseConfiguration { Flags = DatabaseOpenFlags.Create }))
 {
 // Put a key-value pair into the database
 tx.Put(db, UTF8.GetBytes("hello"), UTF8.GetBytes("world"));
 tx.Commit();
 }

 // Begin a read-only transaction to retrieve the value
 using (var tx = env.BeginTransaction(TransactionBeginFlags.ReadOnly))
 using (var db = tx.OpenDatabase())
 {
 var (resultCode, key, value) = tx.Get(db, Encoding.UTF8.GetBytes("hello"));
 if (resultCode == MDBResultCode.Success)
 {
 Console.WriteLine($"{UTF8.GetString(key)}: {UTF8.GetString(value)}");
 }
 else
 {
 Console.WriteLine("Key not found.");
 }
 }
 }
}

In this example:

  • We create a new LMDB environment at the specified path.
  • We open a database within a transaction, inserting the key-value pair ("hello", "world").
  • We commit the transaction to save the changes.
  • We then start a read-only transaction to retrieve and display the value associated with the key "hello".

Handling Multiple Values for the Same Key

LMDB supports storing multiple values for a single key when the database is configured with the Dupsort flag. Here's how you can work with duplicate keys and use the cursor's NextDuplicate function:

using System;
using System.Text;
using LightningDB;

class Program
{
 static void Main()
 {
 using var env = new LightningEnvironment("path_to_your_database");
 env.Open();

 // Configure the database to support duplicate keys
 var dbConfig = new DatabaseConfiguration { Flags = DatabaseOpenFlags.Create | DatabaseOpenFlags.DuplicatesSort };

 // Begin a transaction and open the database
 using (var tx = env.BeginTransaction())
 using (var db = tx.OpenDatabase(configuration: dbConfig))
 {
 var key = Encoding.UTF8.GetBytes("fruit");
 var value1 = Encoding.UTF8.GetBytes("apple");
 var value2 = Encoding.UTF8.GetBytes("cherry");
 var value3 = Encoding.UTF8.GetBytes("banana");

 // Insert multiple values for the same key
 tx.Put(db, key, value1);
 tx.Put(db, key, value2);
 tx.Put(db, key, value3);
 tx.Commit();
 }

 // Begin a read-only transaction to retrieve the values
 using (var tx = env.BeginTransaction(TransactionBeginFlags.ReadOnly))
 using (var db = tx.OpenDatabase())
 using (var cursor = tx.CreateCursor(db))
 {
 var key = Encoding.UTF8.GetBytes("fruit");

 // Position the cursor at the first occurrence of the key
 var result = cursor.Set(key);
 if(result == MDBResultCode.Success)
 {
 do
 {
 var current = cursor.GetCurrent();
 var currentKey = current.key.AsSpan();
 var currentValue = current.value.AsSpan();
 Console.WriteLine($"{UTF8.GetString(currentKey)}: {UTF8.GetString(currentValue)}");
 }
 // Move to the next duplicate value
 while (cursor.NextDuplicate().resultCode == MDBResultCode.Success);
 }
 else
 {
 Console.WriteLine("Key not found.");
 }
 
 //Or even simpler
 var values = cursor.AllValuesFor(key);
 foreach(var value in values)
 {
 Console.WriteLine($"fruit: {Encoding.UTF8.GetString(value.AsSpan())}");
 }
 }
 }
}

In this example:

  • We configure the database with the DupSort flag to allow multiple values for a single key.
  • We insert three different values ("apple", "cherry", "banana") under the same key "fruit".
  • Using a cursor, we iterate over all values associated with the key "fruit" by moving to the next duplicate entry and see the values retrieved are ordered.
  • Then we demonstrate doing the same thing with IEnumerable instead.

Custom Key Ordering

LightningDB provides built-in, allocation-free comparers for custom key sorting and duplicate ordering. Use them with CompareWith() for keys or FindDuplicatesWith() for duplicate values:

var config = new DatabaseConfiguration
{
 Flags = DatabaseOpenFlags.Create | DatabaseOpenFlags.DuplicatesSort
};

// Sort keys as signed integers (negative values sort before positive)
config.CompareWith(SignedIntegerComparer.Instance);

// Sort duplicate values in reverse order
config.FindDuplicatesWith(ReverseBitwiseComparer.Instance);

using var db = tx.OpenDatabase(configuration: config);

Available comparers in LightningDB.Comparers:

Comparer Description
BitwiseComparer Lexicographic byte comparison (default LMDB behavior)
ReverseBitwiseComparer Lexicographic descending
SignedIntegerComparer 4/8-byte signed integers with proper negative ordering
UnsignedIntegerComparer 4/8-byte unsigned integers
Utf8StringComparer Ordinal UTF-8 string comparison
LengthComparer Sort by length first, then content
LengthOnlyComparer Sort by length only
HashCodeComparer Hash-based comparison for large values

Reverse variants are available for most comparers (e.g., ReverseSignedIntegerComparer).

Additional Resources

For more detailed examples and advanced usage, refer to the unit tests in the Lightning.NET repository.

The <a href="http://lmdb.tech/doc" target="_blank">Official LMDB API documentation</a> is also a valuable resource for understanding the underlying database engine.

Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 was computed.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 is compatible.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 is compatible.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp2.0 netcoreapp2.0 was computed.  netcoreapp2.1 netcoreapp2.1 was computed.  netcoreapp2.2 netcoreapp2.2 was computed.  netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 netstandard2.0 is compatible.  netstandard2.1 netstandard2.1 was computed. 
.NET Framework net461 net461 was computed.  net462 net462 was computed.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 was computed.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen40 tizen40 was computed.  tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (11)

Showing the top 5 NuGet packages that depend on LightningDB:

Package Downloads
Akka.DistributedData.LightningDB

Replicated data using CRDT structures

LightningQueues

LightningQueues

LightningQueues.Storage.LMDB

LightningQueues.Storage.LMDB

YesSql.Storage.LightningDB

Package Description

LightningStore

LightningDb facades to easily build an embedded event stream and a document store. By default JIL serialization is build in.

GitHub repositories (4)

Showing the top 4 popular GitHub repositories that depend on LightningDB:

Repository Stars
akkadotnet/akka.net
Canonical actor model implementation for .NET with local + distributed actors in C# and F#.
bleroy/lunr-core
Lunr-core is a small, full text search library for use in small applications. It's a .NET port of LUNR.js.
LightningQueues/LightningQueues
Fast persistent queues for .NET
Bobris/BTDB
Key Value Database in .Net with Object DB Layer, RPC, dynamic IL and much more
Version Downloads Last Updated
0.21.0 11,646 12/24/2025
0.20.0 5,296 11/12/2025
0.19.1 2,130 10/20/2025
0.19.0 6,065 9/22/2025
0.18.1 13,676 5/27/2025
0.18.0 6,106 3/3/2025
0.17.1 3,878 1/15/2025
0.17.0 4,132 11/27/2024
0.16.0 1,379,402 10/11/2023
0.16.0-preview.1 71,264 4/23/2023
0.15.0 315,131 2/4/2023
0.14.1 38,875 1/4/2022
0.14.0 604,535 9/6/2021
0.13.0 187,302 7/30/2020
0.12.0 21,585 7/6/2020
0.11.0 84,925 2/20/2020
0.10.0 102,325 11/26/2017
0.9.9 45,724 5/29/2017
0.9.8 36,353 5/2/2017
0.9.7 18,562 9/22/2016
Loading failed