Skip to content

Commit 2ae33a5

Browse files
authored
Introduce C# driver without documentation and deployment (#616)
## Usage and product changes We introduce the C# driver for TypeDB. It is built using the cross-platform [.NET 6 framework](https://dotnet.microsoft.com/en-us/download/dotnet/6.0). **Usage**: Deployment and usage examples will be provided in a separate pull request. Current state of the code lets you compiling the driver + writing and running behaviour and integration tests for it. The driver is expected to be a Nuget package, which could be added as a dependency to a project and referenced via "using" statements inside the users' code for all platforms. **Architecture**: The C# driver is a thin wrapper around the TypeDB Rust driver, introducing classes for a more intuitive interface. Mostly each C# object holds a reference to the corresponding native Rust object, using an FFI ([SWIG for C#](https://www.swig.org/Doc4.2/SWIGDocumentation.html#CSharp)) for the native object wrappers generation and resource management. Any error encountered will throw a `TypeDBDriverException`. Note that methods which return an `IEnumerable` or a Promise and encounter a server-side error will only throw when the return objects are evaluated (e.g. iterate over or call a `Linq` method for an `IEnumerable` and call `Resolve()` for a `Promise`). A simple usage example: ``` // Inside a try-catch block using (ITypeDBDriver driver = TypeDB.CoreDriver(TypeDB.DEFAULT_ADDRESS)) { string dbName = "mydb"; driver.Databases.Create(dbName); IDatabase mydb = driver.Databases.Get(dbName); System.Console.WriteLine(mydb.Name); using (ITypeDBSession schemaSession = driver.Session(dbName, SessionType.SCHEMA)) { using (ITypeDBTransaction writeTransaction = schemaSession.Transaction(TransactionType.WRITE)) { string defineQuery = "...some define query..."; writeTransaction.Query.Define(defineQuery).Resolve(); writeTransaction.Commit(); } } mydb.Delete(); } ``` ## Implementation **Driver:** Introduces the C# driver, wrapping the C-native classes produced by Rust driver using SWIG. The driver aims to provide a familiar interface for C# developers, hiding data transformations and native calls under the hood. The code's architecture and build flow follow the one from Java with small C#-specific alterations. **Tests:** Integration tests use NUnit framework as a built-in framework for C# bazel test rules (more to come in another PR). Behaviour tests use Xunit.Gherkin.Quick framework and are implemented using [partial classes](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/partial-classes-and-methods) for flexible construction of tests based on different sets of step declaration files. **Build:** To fetch nuget packages, we use [Paket](https://www.nuget.org/packages/Paket) and reference this dependencies in a regular Bazel way ([example from the official Bazel repo for C# rules](https://github.com/bazelbuild/rules_dotnet/blob/master/paket.dependencies)).
1 parent 9ff4259 commit 2ae33a5

File tree

230 files changed

+21631
-257
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

230 files changed

+21631
-257
lines changed

.factory/automation.yml

Lines changed: 86 additions & 92 deletions
Large diffs are not rendered by default.

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,7 @@ venv
9898
# Cargo files
9999
Cargo.lock
100100
Cargo.toml
101+
102+
# Temporary paket files for C#
103+
paket-files/
104+
paket.lock

WORKSPACE

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,23 @@ rules_antlr_dependencies(antlr_version, JAVA)
6464
load("@vaticle_dependencies//builder/cpp:deps.bzl", cpp_deps = "deps")
6565
cpp_deps()
6666

67+
# Load //builder/csharp
68+
load("@vaticle_dependencies//builder/csharp:deps.bzl", dotnet_deps = "deps")
69+
dotnet_deps()
70+
load(
71+
"@rules_dotnet//dotnet:repositories.bzl",
72+
"dotnet_register_toolchains",
73+
"rules_dotnet_dependencies",
74+
)
75+
rules_dotnet_dependencies()
76+
dotnet_register_toolchains("dotnet", "6.0.413")
77+
load("@rules_dotnet//dotnet:paket.rules_dotnet_nuget_packages.bzl", "rules_dotnet_nuget_packages")
78+
rules_dotnet_nuget_packages()
79+
load("@rules_dotnet//dotnet:paket.paket2bazel_dependencies.bzl", "paket2bazel_dependencies")
80+
paket2bazel_dependencies()
81+
load("//csharp/nuget:paket.csharp_deps.bzl", csharp_deps = "csharp_deps")
82+
csharp_deps()
83+
6784
# Load //builder/proto_grpc
6885
load("@vaticle_dependencies//builder/proto_grpc:deps.bzl", grpc_deps = "deps")
6986
grpc_deps()

0 commit comments

Comments
 (0)