NScript.LiteDB.Utils 6.0.2.1

dotnet add package NScript.LiteDB.Utils --version 6.0.2.1
NuGet\Install-Package NScript.LiteDB.Utils -Version 6.0.2.1
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="NScript.LiteDB.Utils" Version="6.0.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NScript.LiteDB.Utils --version 6.0.2.1
#r "nuget: NScript.LiteDB.Utils, 6.0.2.1"
#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.
// Install NScript.LiteDB.Utils as a Cake Addin
#addin nuget:?package=NScript.LiteDB.Utils&version=6.0.2.1

// Install NScript.LiteDB.Utils as a Cake Tool
#tool nuget:?package=NScript.LiteDB.Utils&version=6.0.2.1

NScript.LiteDB.Utils

在 LiteDB 基础上,提供了 DataService<T> 泛型类,方便进行操作:

[LiteDBSet(FileName = "books.db", Indexer = typeof(BookIndexer))]
public class Book
{
    public class BookIndexer : Indexer<Book>
    {
        public override void EnsureIndex(ILiteCollection<Book> col)
        {
            col.EnsureIndex(x => x.Name);
        }
    }

    public String Name { get; set; }
}

public class DefaultBook
{
    public String Name { get; set; }
}

var service1 = new DataService<Book>();
var service2 = new DataService<DefaultBook>();
var service3 = new DataService<Book>("bucketA");
service1.Insert(new Book() { Name = "book1" });
service2.Insert(new DefaultBook() { Name = "book2" });
service3.Insert(new Book() { Name = "book3" });
Console.WriteLine(service1.Count());
Console.WriteLine(service2.Count());
Console.WriteLine(service3.Count());

提供了接口 IFileStorageService,在 LiteDB 基础上,提供了 FileStorageService,可以根据日期,将文件分片存储。

IFileStorageService 接口定义为:

public interface IFileStorageService
{
    /// <summary>
    /// 生成下一个文件的 Id。文件名称为 8字符日期+UUID+扩展名
    /// </summary>
    /// <param name="fileExtention"></param>
    /// <returns></returns>
    public string NextFileId(String fileExtention = "");

    /// <summary>
    /// 删除文件
    /// </summary>
    /// <param name="fileId"></param>
    /// <returns></returns>
    public bool Delete(String fileId);

    /// <summary>
    /// 保存文件,返回文件 fileId
    /// </summary>
    /// <param name="data"></param>
    /// <param name="fileExtention"></param>
    /// <returns></returns>
    public String Save(Byte[] data, String fileExtention);

    /// <summary>
    /// 保存文件到指定 fileId
    /// </summary>
    /// <param name="fileId"></param>
    /// <param name="data"></param>
    /// <returns></returns>
    public bool Save(String fileId, Byte[] data);

    /// <summary>
    /// 根据文件Id查找文件
    /// </summary>
    /// <param name="fileId"></param>
    /// <returns></returns>
    public byte[]? Find(String fileId);
}

相关操作:

void TestFileStorageService(String? dir = null)
{
    var storage = new FileStorageService();
    if (dir != null) storage.BaseDir = dir;

    byte[] data = new byte[10];
    var fileId = storage.Save(data, ".dat");
    Console.WriteLine(fileId);
    var item = storage.Find(fileId);
    Console.WriteLine(item.Length);
    var rtn = storage.Delete(fileId);
    Console.WriteLine(rtn);
    item = storage.Find(fileId);
    if (item == null) Console.WriteLine("Delete OK!");
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.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 NScript.LiteDB.Utils:

Package Downloads
NScript.LiteDB.RocksDBExtention

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.0.2.1 122 4/15/2024
6.0.2 93 4/15/2024
6.0.1.10 153 9/5/2023
6.0.1.8 125 7/3/2023