Vitorm.ElasticSearch
2.2.2
dotnet add package Vitorm.ElasticSearch --version 2.2.2
NuGet\Install-Package Vitorm.ElasticSearch -Version 2.2.2
<PackageReference Include="Vitorm.ElasticSearch" Version="2.2.2" />
paket add Vitorm.ElasticSearch --version 2.2.2
#r "nuget: Vitorm.ElasticSearch, 2.2.2"
// Install Vitorm.ElasticSearch as a Cake Addin #addin nuget:?package=Vitorm.ElasticSearch&version=2.2.2 // Install Vitorm.ElasticSearch as a Cake Tool #tool nuget:?package=Vitorm.ElasticSearch&version=2.2.2
Vitorm.ElasticSearch
Vitorm.ElasticSearch: an simple orm for ElasticSearch
source address: https://github.com/Vit-Orm/Vitorm.ElasticSearch
Build | NuGet |
---|---|
Vitorm.ElasticSearch Documentation
This guide will walk you through the steps to set up and use Vitorm.ElasticSearch.
supported features:
feature | method | remarks | |
---|---|---|---|
create table | TryCreateTable | ||
drop table | TryDropTable | ||
--- | --- | --- | --- |
create records | Add AddRange | ||
retrieve records | Query Get | ||
update records | Update UpdateRange ExecuteUpdate | ||
delete records | Delete DeleteRange DeleteByKey DeleteByKeys ExecuteDelete | ||
--- | --- | --- | --- |
change table | ChangeTable | change mapping table from database | |
change database | ChangeDatabase | change database to be connected | |
--- | --- | --- | --- |
collection total count | TotalCount | Collection Total Count without Take and Skip | |
collection total count and list | ToListAndTotalCount | query List and TotalCount in one request | |
Installation
Before using Vitorm, install the necessary package:
dotnet add package Vitorm.ElasticSearch
Minimum viable demo
code address: Program_Min.cs
using System;
using System.Linq;
using System.Threading;
namespace App
{
public class Program_Min
{
static void Main2(string[] args)
{
// #1 Init
using var dbContext = new Vitorm.ElasticSearch.DbContext("http://localhost:9200");
dbContext.TryDropTable<User>();
dbContext.TryCreateTable<User>();
dbContext.Add(new User { id = 1, name = "lith" });
Thread.Sleep(2000);
// #2 Query
var user = dbContext.Get<User>(1);
var users = dbContext.Query<User>().Where(u => u.name.Contains("li")).ToList();
}
// Entity Definition
[System.ComponentModel.DataAnnotations.Schema.Table("User")]
public class User
{
[System.ComponentModel.DataAnnotations.Key]
public int id { get; set; }
public string name { get; set; }
public DateTime? birth { get; set; }
public int? fatherId { get; set; }
}
}
}
Full Example
This example provides a comprehensive guide to utilizing Vitorm for basic and advanced database operations while maintaining lightweight performance.
code address: Program.cs
using System;
using System.Linq;
using Vitorm;
namespace App
{
public class Program
{
static void Main(string[] args)
{
// #1 Configures Vitorm
using var dbContext = new Vitorm.ElasticSearch.DbContext("http://localhost:9200");
// #2 Create Table
dbContext.TryDropTable<User>();
dbContext.TryCreateTable<User>();
// #3 Insert Records
dbContext.Add(new User { id = 1, name = "lith" });
dbContext.AddRange(new[] {
new User { id = 2, name = "lith", fatherId = 1 },
new User { id = 3, name = "lith", fatherId = 1 }
});
// #4 Query Records
{
var user = dbContext.Get<User>(1);
var users = dbContext.Query<User>().Where(u => u.name.Contains("li")).ToList();
var sql = dbContext.Query<User>().Where(u => u.name.Contains("li")).ToExecuteString();
}
// #5 Update Records
dbContext.Update(new User { id = 1, name = "lith1" });
dbContext.UpdateRange(new[] {
new User { id = 2, name = "lith2", fatherId = 1 },
new User { id = 3, name = "lith3", fatherId = 2 }
});
//dbContext.Query<User>().Where(u => u.name.Contains("li"))
// .ExecuteUpdate(u => new User { name = "Lith" + u.id });
// #6 Delete Records
dbContext.Delete<User>(new User { id = 1 });
dbContext.DeleteRange(new[] {
new User { id = 2 },
new User { id = 3 }
});
dbContext.DeleteByKey<User>(1);
dbContext.DeleteByKeys<User, int>(new[] { 1, 2 });
//dbContext.Query<User>().Where(u => u.name.Contains("li"))
// .ExecuteDelete();
// #7 Join Queries
// #8 Transactions
// #9 Database Functions
}
// Entity Definition
[System.ComponentModel.DataAnnotations.Schema.Table("User")]
public class User
{
[System.ComponentModel.DataAnnotations.Key]
public int id { get; set; }
public string name { get; set; }
public DateTime? birth { get; set; }
public int? fatherId { get; set; }
}
}
}
Explanation
- Setup: Initializes the database and configures Vitorm.
- Create Table: Drops and recreates the
User
table. - Insert Records: Adds single and multiple user records.
- Query Records: Retrieves user records using various querying methods.
- Update Records: Updates single and multiple user records.
- Delete Records: Deletes single and multiple user records.
- Join Queries: Performs a join operation between user and father records.
- Transactions: Demonstrates nested transactions and rollback/commit operations.
- Database Functions: Uses custom database functions in queries.
Vitorm.Data Documentation
Vitorm.Data is a static class that allows you to use Vitorm without explicitly creating or disposing of a DbContext.
Installation
Before using Vitorm.Data, install the necessary package:
dotnet add package Vitorm.Data
dotnet add package Vitorm.ElasticSearch
Config settings
// appsettings.json
{
"Vitorm": {
"Data": [
{
"provider": "ElasticSearch",
"namespace": "App",
"connectionString": "http://localhost:9200"
}
]
}
}
Minimum viable demo
After configuring the
appsettings.json
file, you can directly perform queries without any additional configuration or initialization,Vitorm.Data
is that easy to use.
code address: Program_Min.cs
using Vitorm;
namespace App
{
public class Program_Min
{
static void Main2(string[] args)
{
// Query Records
var user = Data.Get<User>(1);
var users = Data.Query<User>().Where(u => u.name.Contains("li")).ToList();
}
// Entity Definition
[System.ComponentModel.DataAnnotations.Schema.Table("User")]
public class User
{
[System.ComponentModel.DataAnnotations.Key]
public int id { get; set; }
public string name { get; set; }
public DateTime? birth { get; set; }
public int? fatherId { get; set; }
}
}
}
Full Example
code address: Program.cs
using Vitorm;
namespace App
{
public class Program
{
static void Main(string[] args)
{
// #1 No need to init Vitorm.Data
// #2 Create Table
Data.TryDropTable<User>();
Data.TryCreateTable<User>();
// #3 Insert Records
Data.Add(new User { id = 1, name = "lith" });
Data.AddRange(new[] {
new User { id = 2, name = "lith", fatherId = 1 },
new User { id = 3, name = "lith", fatherId = 1 }
});
// #4 Query Records
{
var user = Data.Get<User>(1);
var users = Data.Query<User>().Where(u => u.name.Contains("li")).ToList();
var sql = Data.Query<User>().Where(u => u.name.Contains("li")).ToExecuteString();
}
// #5 Update Records
Data.Update(new User { id = 1, name = "lith1" });
Data.UpdateRange(new[] {
new User { id = 2, name = "lith2", fatherId = 1 },
new User { id = 3, name = "lith3", fatherId = 2 }
});
Data.Query<User>().Where(u => u.name.Contains("li"))
.ExecuteUpdate(u => new User { name = "Lith" + u.id });
// #6 Delete Records
Data.Delete<User>(new User { id = 1, name = "lith1" });
Data.DeleteRange(new[] {
new User { id = 2, name = "lith2", fatherId = 1 },
new User { id = 3, name = "lith3", fatherId = 2 }
});
Data.DeleteByKey<User>(1);
Data.DeleteByKeys<User, int>(new[] { 1, 2 });
Data.Query<User>().Where(u => u.name.Contains("li"))
.ExecuteDelete();
// #7 Join Queries
// #8 Transactions
}
// Entity Definition
[System.ComponentModel.DataAnnotations.Schema.Table("User")]
public class User
{
[System.ComponentModel.DataAnnotations.Key]
public int id { get; set; }
public string name { get; set; }
public DateTime? birth { get; set; }
public int? fatherId { get; set; }
}
}
}
Examples:
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Vit.Core (>= 2.3.0)
- Vitorm (>= 2.2.2 && < 2.3.0)
- Vitorm.ElasticSearch.QueryBuilder (>= 2.2.2)
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 |
---|---|---|
2.2.2 | 89 | 11/4/2024 |
2.2.1 | 87 | 11/2/2024 |
2.2.0 | 97 | 10/11/2024 |
2.2.0-preview2 | 84 | 9/22/2024 |
2.2.0-preview | 96 | 9/11/2024 |
2.1.2 | 108 | 8/31/2024 |
2.1.1 | 101 | 8/29/2024 |
2.1.0.1-preview | 101 | 8/26/2024 |
2.1.0 | 137 | 8/25/2024 |
2.0.5 | 144 | 8/22/2024 |
2.0.4 | 134 | 8/15/2024 |
2.0.3 | 127 | 8/9/2024 |
2.0.2 | 79 | 7/29/2024 |
2.0.1.1 | 108 | 7/23/2024 |
2.0.1 | 111 | 7/22/2024 |
2.0.1-preview | 109 | 7/21/2024 |
2.0.0 | 115 | 7/14/2024 |
2.0.0-preview | 91 | 7/14/2024 |
1.2.0-preview | 102 | 7/14/2024 |
1.1.0-preview | 96 | 7/7/2024 |
1.0.1 | 114 | 6/18/2024 |
1.0.0 | 123 | 6/16/2024 |