Firestore.ORM
1.1.7
dotnet add package Firestore.ORM --version 1.1.7
NuGet\Install-Package Firestore.ORM -Version 1.1.7
<PackageReference Include="Firestore.ORM" Version="1.1.7" />
<PackageVersion Include="Firestore.ORM" Version="1.1.7" />
<PackageReference Include="Firestore.ORM" />
paket add Firestore.ORM --version 1.1.7
#r "nuget: Firestore.ORM, 1.1.7"
#:package Firestore.ORM@1.1.7
#addin nuget:?package=Firestore.ORM&version=1.1.7
#tool nuget:?package=Firestore.ORM&version=1.1.7
Firestore.ORM 🔥
Firestore.ORM is a lightweight object-relational mapping (ORM) product for Firebase.Firestore : It provides an additional layer of abstraction on top of the existing Firestore SDK
One of the main advantages of this library is to provide a solid model structure base in order to ensure the integrity of the data present in Firestore. It also provides utility methods encapsulating the SDK functions in order to simplify writing and reading, serialization and synchronization. It sits on top of the official Firebase SDK, it's not intended to replace it. The ORM exposes the parts of the SDK it uses in a way that it remains usable within the project.
Model
- All class from the model must derive from the type
Firestore.ORM.FirestoreDocument. This abstract class is wrapping data provided by the SDK (such asGoogle.Cloud.Firestore.DocumentReference) and additional data provided by the ORM, such as a list of corruption errors if the data obtained from Firebase does not match the structure expected.
public class User : FirestoreDocument
{
public User(DocumentReference reference) : base(reference)
{
}
[Field("email")]
public string Email
{
get;
set;
}
[Field("firstname")]
public string Firstname
{
get;
set;
}
[Field("phone", FieldNullability.Nullable)]
public string Phone
{
get;
set;
}
[Field("role")]
public int Role
{
get;
set;
} = 1;
[Field("claims")]
public List<DocumentReference> Claims
{
get;
set;
}
}
Connecting to Firebase
The initialization function establishes the connection with Firebase and introspects the code to discover the model.
Initialize(string projectId, FirestoreClient client, Assembly assembly,
MappingBehavior mappingBehavior = MappingBehavior.Strict)
The assembly parameter indicates the assembly where the model is located. mappingBehavior corresponds to the level of tolerance that the ORM adopts when remote data structure is not valid compared to the model. In the case of strict tolerance, the ORM throws if any data is corrupted.
var client = new FirestoreClientBuilder
{
CredentialsPath = "credentials.json"
}.Build();
FirestoreManager.Instance.Initialize("my-project", client, Assembly.GetExecutingAssembly());
Manipulating data
Basic fetch
IEnumerable<User> userCollection = await FirestoreManager.Instance.Collection("users").GetAsync<User>();
Listeners
CollectionReference collection = FirestoreManager.Instance.Collection("users");
SnapshotListener<User> userListener = new SnapshotListener<User>();
userListener.OnItemChange += ...
userListener.OnItemsUpdated += ...
/*
First fetch the collection and start to listen to the changes
*/
await userListener.FetchAndListen();
/*
Provide a snapshot of the collection,
internal collection inside the listener is still in real time
*/
List<User> users = userListener.GetItems().ToList();
Writing
User? user = users.Find(x=> x.Firstname == "John");
user.Firstname = "Peter";
user.Update();
if (user.Phone.Contains("+33"))
{
user.Delete();
}
User newUser = new User(collection.Document());
newUser.Name = "Maria";
newUser.Insert();
Data sanitize, incident report
Incident management allows you to verify that the data present in Firebase respects the structure expected by the model. It ensures the structuring of data. This feature is only available with mappingBehavior : 'MappingBehavior.Souple'.
IncidentManager.OnIncident += OnIncident;
static void OnIncident(Incident incident)
{
switch (incident)
{
case MissingFieldIncident missingFieldIncident:
// Solve missing field on document
break;
case InvalidFieldTypeIncident invalidFieldTypeIncident:
// Solve wrong field type on document
break;
}
}
Contributors
| Name |
|---|
| Marius Lumbroso Author (https://github.com/Skinz3) |
| Product | Versions 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. net9.0 was computed. 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. |
-
net6.0
- Google.Cloud.Firestore (>= 3.5.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.7 | 322 | 10/10/2024 |
| 1.1.6 | 389 | 5/21/2024 |
| 1.1.5 | 183 | 5/20/2024 |
| 1.1.4 | 181 | 4/10/2024 |
| 1.1.3 | 281 | 4/10/2024 |
| 1.1.2 | 192 | 4/4/2024 |
| 1.1.1 | 175 | 4/4/2024 |
| 1.1.0 | 165 | 4/4/2024 |
| 1.0.8 | 265 | 3/27/2024 |
| 1.0.7 | 177 | 3/26/2024 |
| 1.0.6 | 169 | 3/26/2024 |
| 1.0.5 | 175 | 3/26/2024 |
| 1.0.4 | 182 | 3/22/2024 |
| 1.0.3 | 193 | 3/22/2024 |
| 1.0.2 | 186 | 3/22/2024 |
| 1.0.1 | 177 | 3/22/2024 |
| 1.0.0 | 189 | 3/22/2024 |