Fireflies.Atlas.Core 1.8.3

dotnet add package Fireflies.Atlas.Core --version 1.8.3
                    
NuGet\Install-Package Fireflies.Atlas.Core -Version 1.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="Fireflies.Atlas.Core" Version="1.8.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fireflies.Atlas.Core" Version="1.8.3" />
                    
Directory.Packages.props
<PackageReference Include="Fireflies.Atlas.Core" />
                    
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 Fireflies.Atlas.Core --version 1.8.3
                    
#r "nuget: Fireflies.Atlas.Core, 1.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 Fireflies.Atlas.Core@1.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=Fireflies.Atlas.Core&version=1.8.3
                    
Install as a Cake Addin
#tool nuget:?package=Fireflies.Atlas.Core&version=1.8.3
                    
Install as a Cake Tool

Fireflies Atlas Core

Fireflies Atlas is a database agnostic caching layer that can be used with miscellaneous data sources such as Redis and Sql Server.

Before the example

Atlas is all about documents, below is the document descriptors used in the example below.

public class BookshelfDocument {
    [AtlasField]
    [AtlasKey]
    public virtual int BookshelfId { get; set; }

    [AtlasField]
    public virtual string Name { get; set; }

    public virtual IEnumerable<ShelfDocument> Shelfs { get; set; }
}

public class ShelfDocument {
    [AtlasField]
    [AtlasKey]
    public virtual int ShelfId { get; set; }

    [AtlasField]
    public virtual int BookshelfId { get; set; }

    [AtlasField]
    public virtual int Index { get; set; }

    public virtual IEnumerable<BookDocument> Books { get; set; }
}

public class BookDocument {
    [AtlasField]
    [AtlasKey]
    public virtual int BookId { get; set; }

    [AtlasField]
    public virtual string Name { get; set; }

    [AtlasField]
    public virtual string Author { get; set; }

    public virtual LendingStateDocument LendingState { get; set; }
}

public class LendingStateDocument {
    [AtlasKey]
    public virtual int BookId { get; set; }

    public virtual string State { get; set; }
    public virtual DateTimeOffset At { get; set; }
}

Example

Everything starts with the AtlasBuilder.

var builder = new AtlasBuilder();

Then we need to add some sources

var sqlServerSource = builder.Create(a => new SqlServerSource(a, "server=.; Database=my_database; user=sa; password=my_password;Trust Server Certificate=true"));
var redisSource = builder.Create(a => new RedisSource(a, "localhost"));

From here we can start to describe our documents and their relationships.

In this example the hierarchy is like this:

  • Bookshelf (SQL), "root" document
    • Shelfs (SQL), a bookshelf has a list of shelfs
      • Book (SQL), a book on a shelf
        • Lending state (Redis), whats the lending state of the book?

Above you can see that we mix SQL and redis sources but the resulting document will be agnostic to this.

Below is how we would describe this in code.

builder.AddDocument<BookshelfDocument>()
    .SqlServerSource(sqlServerSource, "dbo", "bookshelf")
    .PreloadDocuments()
    .AddRelation<ShelfDocument>(x => x.Shelfs, (document, foreign) => document.BookshelfId == foreign.BookshelfId)
    .AddIndex(x => x.BookshelfId);

builder.AddDocument<ShelfDocument>()
    .SqlServerSource(sqlServerSource, "dbo", "shelfs")
    .PreloadDocuments()
    .AddRelation<BookDocument>(x => x.Books, (document, foreign) => document.ShelfId == foreign.ShelfId)
    .AddIndex(x => x.ShelfId)
    .AddIndex(x => x.BookshelfId);

builder.AddDocument<BookDocument>()
    .SqlServerSource(sqlServerSource, "dbo", "book")
    .PreloadDocuments()
    .AddRelation<LendingStateDocument>(x => x.LendingState, (document, foreign) => document.BookId == foreign.BookId)
    .AddIndex(x => x.BookId)
    .AddIndex(x => x.ShelfId);

builder.AddDocument<LendingStateDocument>()
    .RedisHashSource(redisSource, 1, "books:lendingstate");

Now we are ready to build the atlas.

var atlas = await builder.Build();

Lets query atlas.

var document = await atlas.GetDocument<BookshelfDocument>(f => f.Name.Contains("Bruks"));
Console.WriteLine($"{document.Name} has {document.Shelfs.Count()} shelfs");

Linq provider

A simple LINQ provider would be implemented like this

public class AtlasQuery : AtlasContext {
    public AtlasQuery(Core.Atlas atlas) : base(atlas) {
    }

    public IQueryable<BookshelfDocument> Bookshelfs => CreateQueryable<BookshelfDocument>();
}

We can then use it like any other LINQ IQueryable-object.

var bookshelf = atlasQuery.Bookshelfs
    .First(y => y.Name.Contains("Bruks"));
Console.WriteLine(bookshelf.Name);

Logo by freepik

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

Showing the top 2 NuGet packages that depend on Fireflies.Atlas.Core:

Package Downloads
Fireflies.Atlas.Source.Redis

Fireflies Atlas Redis Source

Fireflies.Atlas.Sources.SqlServer

Fireflies Atlas Sql Server Source

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.8.3 243 2/13/2025
1.8.2 228 12/20/2024
1.8.1 194 12/17/2024
1.8.0 263 2/14/2024
1.7.2 244 2/10/2024
1.7.1 319 12/18/2023
1.7.0 203 12/18/2023
1.6.0 232 11/15/2023
1.4.1 317 8/25/2023
1.4.0 279 8/23/2023
1.3.8 306 8/16/2023
1.3.7 270 8/16/2023
1.3.6 323 7/13/2023
1.3.5 308 7/12/2023
1.3.4 318 7/12/2023
1.3.3 316 7/12/2023
1.3.2 300 7/12/2023
1.3.0 309 7/12/2023
1.2.11 278 7/11/2023
1.2.10 311 7/11/2023
Loading failed