![]() |
VOOZH | about |
dotnet add package LiteDB.Async --version 0.1.8
NuGet\Install-Package LiteDB.Async -Version 0.1.8
<PackageReference Include="LiteDB.Async" Version="0.1.8" />
<PackageVersion Include="LiteDB.Async" Version="0.1.8" />Directory.Packages.props
<PackageReference Include="LiteDB.Async" />Project file
paket add LiteDB.Async --version 0.1.8
#r "nuget: LiteDB.Async, 0.1.8"
#:package LiteDB.Async@0.1.8
#addin nuget:?package=LiteDB.Async&version=0.1.8Install as a Cake Addin
#tool nuget:?package=LiteDB.Async&version=0.1.8Install as a Cake Tool
This library allows the use of asynchronous programming techniques with the LiteDb library. It is intended for Xamarin and WPF applications that require or would benefit a lightweight NoSQL database but also don't want to open and manage lots of threads or block the UI while database operations are occuring.
We manage the thread for you.
Available on nuget. https://www.nuget.org/packages/LiteDB.Async/
Include the nuget package in your project in the usual way
Install-Package LiteDB.Async
or
dotnet add package LiteDB.Async
Open a LiteDbAsync instance by calling the constructor in the standard way.
var db = new LiteDatabaseAsync("Filename=mydatabase.db;Connection=shared;Password=hunter2");
Collections are the equivalent of tables
var collection = _db.GetCollection<SimplePerson>();
This will give us an instance of the collection we can read and write.
We can upsert just like in the regular LiteDb
var collection = _db.GetCollection<SimplePerson>();
var person = new SimplePerson()
{
Id = Guid.NewGuid(),
FirstName = "John",
LastName = "Smith"
};
var upsertResult = await collection.UpsertAsync(person);
When we want to read from the database we should use a query.
To read all SimplePerson's in the database
var collection = _db.GetCollection<SimplePerson>();
var listResult = await collection.Query().ToListAsync();
You can use Linq
var theSmiths = await collection.Query().Where(x => x.Lastname == "Smith").ToListAsync();
Use the BeginTransaction method to start a transaction
using var asyncDb1 = new LiteDatabaseAsync(connectionString);
using var asyncDb2 = await asyncDb1.BeginTransactionAsync();
Operations run on asyncDb2 are now isolated from asyncDb1. They can also be rolled back, or if your program exits without call CommitAsync they are lost.
From version 5.0.16 of LiteDb we started to have problems with transactions on Shared connections. Therefore will be recommending Direct connections from LiteDb.Async version 0.1.6 goind forward.
To commit
await asyncDb2.CommitAsync();
Almost all functions from LiteDb have an async replacement
From Collections
Query, CountAsync, LongCountAsync, ExistsAsync, MinAsync, MaxAsync, DeleteAsync, DeleteManyAsync, FindAsync, FindByIdAsync, FindOneAsync, FindAllAsync, Include, EnsureIndexAsync, InsertAsync, UpdateAsync, UpdateManyAsync, UpsertAsync
From Query
Include, Where, OrderBy, OrderByDescending, GroupBy, Select, Limit, Skip, Offset, ForUpdate, ToDocumentsAsync, ToEnumerableAsync, ToListAsync, ToArrayAsync, FirstAsync, FirstOrDefaultAsync, SingleAsync, SingleOrDefaultAsync, CountAsync, LongCountAsync, ExistsAsync
From Database
UtcDate, CheckpointSize, UserVersion, Timeout, Collation, LimitSize, BeginTransAsync, CommitAsync, RollbackAsync, PragmaAsync, GetCollectionNamesAsync, CollectionExistsAsync, DropCollectionAsync, RenameCollectionAsync, CheckpointAsync, RebuildAsync
From Storage
The constructor LiteDatabaseAsync opens and wraps a LiteDB instant. It also starts a background thread which all actions are performed in.
When a function that causes an evaluation is called it sends a message to the background thread, where the required action is performed by the LiteDb instance. The result is then return to the calling thread when the function in the background completes. If the function in the background thread causes an exception it is caught and a LiteAsyncException is raised. The original exception is preserved as the InnerException.
Each class or interface in the LiteDb library has an equivalent in the LiteDb.Async library. Each function that returns a task is named with the async suffix. You can then call LiteDb.ASync methods using similar syntax to calling async functions in EF Core.
A new database object is created and connects to the same source, the new database object also creates a new background worker thread for itself. It then calls the underlying LiteDb.BeginTrans function to use LiteDb's transaction functionality.
To build the solution
dotnet build
To run the unit tests
dotnet test
To run a single specific unit test
dotnet test --filter DisplayName=LiteDB.Async.Test.SimpleDatabaseTest.TestCanUpsertAndGetList
To build for nuget
dotnet pack --configuration Release
Don't forget to bump the version number in the litedbasync.csproj project file
It will build a nupkg file.
Next log in to nuget.org and upload the nupkg file which was just built.
Done the package will be available to the world within a few minutes.
https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package-using-the-dotnet-cli
https://docs.microsoft.com/en-us/nuget/nuget-org/publish-a-package
When checking out for the first time copy the .vscode/launch.json.default and .vscode/tasks.json.default to .vscode/launch.json and .vscode/tasks.json.
The repo https://github.com/mlockett42/mvvm-cross-litedb-async gives an example of how to use this library in Xamarin Forms and MVVM.
| 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 was computed. 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 was computed. 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 was computed. 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. |
Showing the top 5 NuGet packages that depend on LiteDB.Async:
| Package | Downloads |
|---|---|
|
Serilog.Sinks.LiteDb.Async
Serilog event sink that writes to LiteDb database |
|
|
UnifiedBlazor.Shared.DataAccess
UnifiedBlazor框架的DataAccess共享库 |
|
|
UnifiedBlazor.Shared.Core
UnifiedBlazor框架的Core共享库 |
|
|
Fluxera.Repository.LiteDB
A LiteDB repository implementation. |
|
|
LiteDB.Queryable
An IQueryable wrapper implementation for LiteDB with additional async extensions. |
Showing the top 2 popular GitHub repositories that depend on LiteDB.Async:
| Repository | Stars |
|---|---|
|
LykosAI/StabilityMatrix
Multi-Platform Package Manager for Stable Diffusion
|
|
|
anton-martyniuk/Modern
.NET modern tools for fast and efficient development
|
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.8 | 131,668 | 6/26/2024 |
| 0.1.7 | 47,031 | 8/5/2023 |
| 0.1.6 | 13,939 | 3/17/2023 |
| 0.1.5 | 25,458 | 1/21/2023 |
| 0.1.4 | 2,322 | 1/16/2023 |
| 0.1.3 | 2,340 | 1/10/2023 |
| 0.1.2 | 6,478 | 12/20/2022 |
| 0.1.1 | 33,228 | 8/18/2022 |
| 0.1.0 | 21,837 | 3/19/2022 |
| 0.0.11 | 32,771 | 9/7/2021 |
| 0.0.10 | 3,049 | 8/22/2021 |
| 0.0.9 | 3,271 | 7/24/2021 |
| 0.0.8 | 7,785 | 1/13/2021 |
| 0.0.7 | 3,790 | 10/28/2020 |
| 0.0.6 | 2,340 | 10/23/2020 |
| 0.0.5 | 2,178 | 10/14/2020 |
| 0.0.4 | 2,703 | 9/26/2020 |
| 0.0.3 | 2,180 | 9/24/2020 |
| 0.0.2 | 2,402 | 5/24/2020 |
| 0.0.1 | 2,432 | 5/23/2020 |