https://github.com/nebula-contrib/nebula-net
Nebula Graph .net Client
https://github.com/nebula-contrib/nebula-net
dotnet graphdatabase hacktoberfest nebula-graph thrift-client
Last synced: 10 months ago
JSON representation
Nebula Graph .net Client
- Host: GitHub
- URL: https://github.com/nebula-contrib/nebula-net
- Owner: nebula-contrib
- License: apache-2.0
- Created: 2021-12-13T07:55:01.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-06-03T04:19:15.000Z (about 2 years ago)
- Last Synced: 2025-05-13T15:33:34.608Z (about 1 year ago)
- Topics: dotnet, graphdatabase, hacktoberfest, nebula-graph, thrift-client
- Language: C#
- Homepage: https://www.nuget.org/packages/NebulaNet/
- Size: 986 KB
- Stars: 18
- Watchers: 5
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## NebulaNet
[](https://www.nuget.org/packages/NebulaNet/)
[](https://github.com/shyboylpf/nebula-net/actions/workflows/ci.yml)
[](https://github.com/shyboylpf/nebula-net/blob/master-matt/LICENSES/Apache-2.0.txt)
[](https://github.com/shyboylpf/nebula-net/issues)
Nebula NET client.
## Install with .NET CLI
[https://www.nuget.org/packages/NebulaNet/](https://www.nuget.org/packages/NebulaNet/)
```shell
dotnet add package NebulaNet
```
Released [versions](https://www.nuget.org/packages/NebulaNet/#versions-tab) are mapped to Nebula Graph Core as following table:
| nebula-net | NebulaGraph Core |
| ---------- | ----------------- |
| 1.0.0 | 2.6.x |
| 3.0.0 | 3.x |
## Quick Start
### Example-1:
```csharp
using NebulaNet;
using System;
using System.Text;
using System.Threading.Tasks;
NebulaConnection graphClient = new NebulaConnection();
await graphClient.OpenAsync("127.0.0.1", 9669);
var authResponse = await graphClient.AuthenticateAsync("root", "123456");
Console.WriteLine(authResponse.Session_id);
StringBuilder sb = new StringBuilder();
sb.Append("CREATE SPACE IF NOT EXISTS test(vid_type=FIXED_STRING(30));");
sb.Append("USE test;");
sb.Append("CREATE TAG IF NOT EXISTS person(name string, age int);");
sb.Append("CREATE EDGE like (likeness double);");
var executionResponse = await graphClient.ExecuteAsync(authResponse.Session_id, sb.ToString());
await Task.Delay(10000);
executionResponse = await graphClient.ExecuteAsync(authResponse.Session_id, "INSERT VERTEX person(name, age) VALUES \"Bob\":(\"Bob\", 10), \"Lily\":(\"Lily\", 9);");
await Task.Delay(5000);
executionResponse = await graphClient.ExecuteAsync(authResponse.Session_id, "INSERT EDGE like(likeness) VALUES \"Bob\"->\"Lily\":(80.0);");
await Task.Delay(5000);
executionResponse = await graphClient.ExecuteAsync(authResponse.Session_id, "FETCH PROP ON person \"Bob\" YIELD vertex as node;");
await Task.Delay(5000);
executionResponse = await graphClient.ExecuteAsync(authResponse.Session_id, "FETCH PROP ON like \"Bob\"->\"Lily\" YIELD edge as e;");
await Task.Delay(5000);
//
var testDtos = await graphClient.ExecuteAsync(authResponse.Session_id, "FETCH PROP ON person \"Bob\",\"Lily\" YIELD properties(vertex).name AS name,properties(vertex).age AS age;")
.ToListAsync();
foreach (var item in testDtos)
{
Console.WriteLine($"1.name:{item.Name},age:{item.Age}");
}
executionResponse = await graphClient.ExecuteAsync(authResponse.Session_id, "DROP SPACE test;");
await Task.Delay(5000);
await graphClient.SignOutAsync(authResponse.Session_id);
public class TestDto
{
public string Name { get; set; }
public long Age { get; set; }
}
```
### Example-2(.NetCore):
Program.cs中配置:
```csharp
builder.Services.AddNebulaGraph(config =>
{
config.Ip="49.232.18.127";
config.Port = 8669;
});
```
使用:
```csharp
public class NebulaGraphController : ControllerBase
{
private readonly NebulaPool _nebulaConnPool;
public NebulaGraphController(NebulaPool nebulaConnPool)
{
_nebulaConnPool = nebulaConnPool;
}
public async Task MatchMultipleTest(string questionId)
{
var session = await _nebulaConnPool.GetSessionAsync();
var output = await session.ExecuteAsync("FETCH PROP ON person \"Bob\",\"Lily\" YIELD properties(vertex).name AS name,properties(vertex).age AS age;")
.ToListAsync();
session.Release();
return output;
}
public class TestDto
{
public string Name { get; set; }
public long Age { get; set; }
}
}
```
## License
Nebula NET is under Apache2.0 license.