A .NET database
that Just Works™

An ACID document-relational database, built on SQLite.

  1. Step 1 Install SoloDB

    dotnet add package SoloDB
  2. Step 2 Profit!

    Program.cs
    using var db = new SoloDB("app.db");
    var users = db.GetCollection<User>();
    users.Insert(new User { Name = "Ada" });
    
    var since = DateTime.UtcNow.AddDays(-30);
    var names = users
        .Where(u => u.CreatedAt > since && u.Name.StartsWith("A"))
        .OrderBy(u => u.Name)
        .Select(u => u.Name)
        .ToList();
    
    // One UPDATE statement; no documents are loaded.
    users.UpdateMany(u => u.Name == "Ada",
        u => u.Email.Set("ada@example.com"));
Queries
Full LINQ, translated to SQL
Transactions
ACID, with nested savepoints
Types
decimal, BigInteger, dates, nested objects
Relations
Typed references with delete policies
Search
Ranked full-text with snippets
Files
A file system with byte-range reads
Storage
A file, memory, or streams you supply
Runs on
.NET 6 and later .NET Framework 4.6.1 and later .NET Standard 2.0 and 2.1 NativeAOT

Just ask

Whatever you need, it’s already there

You want to store users? Add them.

Any class with public properties is a document. Insert one or a thousand in a single call, read them back by Id and update them in place. SoloDB fills in the generated keys.

var users = db.GetCollection<User>();
IList<long> ids = users.InsertBatch(new[] {
    new User { Name = "Grace" },
    new User { Name = "Linus" }
});

var grace = users.GetById(ids[0]);
grace.Email = "grace@example.com";
users.Update(grace);

You want JSON? Use it.

Parse JSON straight into your own types and write them back as UTF-8 or UTF-16, without an intermediate tree. The same typed conversion stores your documents.

var ada = JsonValue.ParseInto<User>(
    """{ "Name": "Ada", "Email": "ada@example.com" }""");
users.Insert(ada);

Span<byte> utf8 = Span<byte>.Empty;
int written = JsonValue.WriteJson(ref ada, ref utf8);
// utf8[..written] is the stored user as UTF-8 JSON.

You want SQL, but better? Here you go.

Link documents with DBRef<T> and DBRefMany<T>. Related documents are saved with their owner, loaded when you read it and queryable in the same LINQ expression, while delete policies keep every link consistent.

public class Team
{
    public long Id { get; set; }
    public string Name { get; set; } = "";
    public DBRef<Member> Lead { get; set; }
    public DBRefMany<Member> Members { get; set; } = new();
}

var team = new Team {
    Name = "Core",
    Lead = DBRef<Member>.From(new Member { Name = "Ada" })
};
team.Members.Add(new Member { Name = "Bob" });
teams.Insert(team);  // members and links are saved together

var found = teams
    .Where(t => t.Lead.Value.Name == "Ada")
    .Where(t => t.Members.Any(m => m.Name == "Bob"))
    .ToList();

You work for a bank? Use decimal, seamlessly.

decimal and BigInteger keep their exact values. Queries compare, sort and sum them inside SQLite, and decimal totals keep decimal precision, with no floating point in between.

entries.Insert(new LedgerEntry { Amount = 0.1m });
entries.Insert(new LedgerEntry { Amount = 0.2m });
decimal total = entries.Sum(e => e.Amount); // exactly 0.3

entries.Insert(new LedgerEntry { Units = BigInteger.Pow(10, 40) });
var largest = entries.OrderByDescending(e => e.Units).First();

Declare which text fields matter and how much. SoloDB builds a ranked full-text index, keeps it current on every write and returns hits you filter, page and highlight with LINQ.

articles.EnsureSearchIndex(index => index
    .Field(a => a.Title, 4.0, "title")
    .Field(a => a.Body, 1.0, "body"));

var hits = articles.Search(SearchQuery.TypeAhead("sqlite pag"))
    .Take(10)
    .Select(hit => new {
        hit.Item.Title,
        Preview = hit.Snippet(a => a.Body, "[", "]", 12)
    })
    .ToArray();

You want files? Here’s a file system.

Folders, metadata, streams and byte-range reads, in the same database as your documents. Files are stored in compressed chunks, so reading the first kilobyte reads only what it needs.

var fs = db.FileSystem;
using (var pdf = File.OpenRead("q4.pdf"))
    fs.Upload("/reports/q4.pdf", pdf);

fs.SetMetadata("/reports/q4.pdf", "Author", "Finance");
byte[] head = fs.ReadAt("/reports/q4.pdf", 0, 1024); // reads one chunk

You want all or nothing? Wrap it.

WithTransaction covers documents, relations and files together. Throw anywhere inside and every change is rolled back; nest a call and it becomes a savepoint.

db.WithTransaction(tx =>
{
    var orders = tx.GetCollection<Order>();
    orders.Insert(new Order { Customer = "Ada", Total = 42.50m });
    tx.FileSystem.Upload("/invoices/ada.pdf", pdf);
}); // an exception anywhere undoes both

You want your own storage? Bring it.

Open a database over streams or any byte device you implement: a custom block store, or an encryption layer you wrote and trust. Collections, queries and transactions work as usual.

using var main = new MemoryStream();
using var journal = new MemoryStream();
using var storage = SqliteStorage.Simple(
    main, journal, leaveOpen: true,
    coordination: SqliteStorageCoordination.SingleProcessInMemory);
using var db = new SoloDB(storage);

You want multi-tenant? Give each a full nested DB.

SoloDB databases can be nested: each tenant gets a full, isolated SoloDB stored inside the main database’s built-in file storage, not as a separate file on disk. Everything remains a single OS file.

using var app = new SoloDB("app.db");

using var main = app.FileSystem.OpenOrCreateAt("/tenants/acme.main");
using var log = app.FileSystem.OpenOrCreateAt("/tenants/acme.wal");
using var storage = SqliteStorage.Wal(main, log, true,
    SqliteStorageCoordination.SingleProcessInMemory);
using var acme = new SoloDB(storage);

acme.GetCollection<Invoice>().Insert(new Invoice { Total = 42.50m });

You ship NativeAOT or write F#? Already handled.

Your build generates typed operations for your models, so NativeAOT applications run without code generation at run time. F# records, unions and options work as models, and whole queries compile from quotations.

type Note = { mutable Id: int64; Text: string }

use db = new SoloDB("notes.db")
let notes = db.GetCollection<Note>()
notes.Insert({ Id = 0L; Text = "hello" }) |> ignore
let found = notes.Where(fun n -> n.Text.StartsWith "he").ToList()

You’re in it for the greed? Keep every cent.

SoloDB costs nothing, and its license lets you ship it inside commercial, closed-source applications, NativeAOT and single-file builds included, without publishing your code. Changes to SoloDB itself stay public.

For an unmodified release, this notice is the whole invoice. Read the licensing summary.

This product uses SoloDB under the GNU LGPLv3 with
the SoloDB Distribution Exception.
Copyright (c) Radu Sologub

Source: https://github.com/Unconcurrent/SoloDB
Licenses: LICENSE.txt (LGPLv3) and LICENSE.SPECIAL.txt
(the exception) in that repository; GPLv3 at
https://www.gnu.org/licenses/gpl-3.0.html

Performance

And it’s fast

SoloDB 1.3.0, LiteDB 5.0.21 and MongoDB Community 8.3.11 ran the same workload on 200,000 documents with six common indexes and the same transactional guarantees, every result checked against an in-memory copy. SoloDB was fastest in nine of the fourteen operations.

Milliseconds for each database’s fastest verified API; lower is better. The fastest result in each row is marked.
OperationSoloDBLiteDBMongoDB
Count all documents0.20 (fastest)69.4422.40
Count one prefix2.97 (fastest)18.055.32
Count two prefixes38.56 (fastest)310.6484.22
Count unindexed tag101.11312.5669.19 (fastest)
Four workers × 50 exact prefix counts142.55 (fastest)1,194.75258.67
First page5.64129.431.72 (fastest)
Page at offset 5,00014.12 (fastest)134.1324.57
Ten sequential pages65.661,307.2931.38 (fastest)
Ten pseudorandom pages199.89 (fastest)1,310.241,060.72
1,000 individual point lookups10.30 (fastest)27.4296.44
Group by username initial61.94979.0254.34 (fastest)
Insert 200,000 documents atomically2,269.751,597.62 (fastest)1,629.71
Native complex-predicate update56.98 (fastest)122.53207.17
Build common indexes and prepare statistics722.79 (fastest)9,016.43735.02

Ryzen 9 5900HS, Linux, .NET 9, data on tmpfs; MongoDB as a single-node replica set with snapshot reads and journaled majority writes. See the code behind each figure.

Get started

Your first database

Create a console app and add the package. NuGet selects the right build for your runtime on Windows, Linux or macOS.

dotnet new console -n HelloSoloDB
cd HelloSoloDB
dotnet add package SoloDB

Paste this into Program.cs and run it:

using System;
using System.Linq;
using SoloDatabase;

using var db = new SoloDB("myapp.db");
var users = db.GetCollection<User>();

// Insert an object. SoloDB fills its Id.
var alice = new User { Name = "Alice", Email = "alice@example.com" };
users.Insert(alice);

// Query with LINQ.
var found = users.Single(user => user.Id == alice.Id);
Console.WriteLine(found.Name); // Alice

// Update and delete.
found.Email = "alice@new.example";
users.Update(found);
users.Delete(found.Id);

public class User
{
    public long Id { get; set; }
    public string Name { get; set; } = "";
    public string Email { get; set; } = "";
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
}