-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using Gel; | ||
|
||
// string instance = "dnwpark/test"; | ||
string instance = "_localdev"; | ||
|
||
GelConnection connection = GelConnection.Create(new(){Instance = instance}); | ||
Console.WriteLine("Connection:"); | ||
Console.WriteLine($"host={connection.Hostname}"); | ||
Console.WriteLine($"port={connection.Port}"); | ||
Console.WriteLine($"branch={connection.Branch}"); | ||
Console.WriteLine($"database={connection.Database}"); | ||
Console.WriteLine($"user={connection.Username}"); | ||
Console.WriteLine($"password={connection.Password}"); | ||
Console.WriteLine(); | ||
|
||
GelClientPool clientPool = new GelClientPool( | ||
connection, | ||
new GelClientPoolConfig { | ||
SchemaNamingStrategy = INamingStrategy.SnakeCaseNamingStrategy}); | ||
|
||
Console.WriteLine("Results:"); | ||
var results = await clientPool.QueryAsync<Person>("select Person {*, [is User].status}"); | ||
for (int index = 0; index < results.Count; ++index) | ||
{ | ||
Console.WriteLine($"[{index}] = `{results.ElementAt(index)}`"); | ||
} | ||
|
||
var txResult = await clientPool.TransactionAsync(async tx => | ||
{ | ||
await tx.ExecuteAsync("insert Ghost { name := 'Casper' };"); | ||
return await tx.QueryAsync<Person>("select Person {*, [is User].status}"); | ||
}); | ||
if (txResult is not null) | ||
{ | ||
Console.WriteLine("Tx Result:"); | ||
for (int index = 0; index < txResult.Count; ++index) | ||
{ | ||
Console.WriteLine($"[{index}] = `{txResult.ElementAt(index)}`"); | ||
} | ||
} | ||
|
||
internal abstract class Person | ||
{ | ||
public string Name { get; set; } = string.Empty; | ||
|
||
public override string ToString() | ||
{ | ||
return $"{GetType().Name} {{ Name = \"{Name}\" }}"; | ||
} | ||
}; | ||
|
||
internal class User : Person | ||
{ | ||
public string? Status { get; set; } = null; | ||
|
||
public override string ToString() | ||
{ | ||
string statusString = Status is not null ? '\"' + Status + '\"' : "null" ; | ||
return $"{GetType().Name} {{ Name = \"{Name}\", Status = {statusString} }}"; | ||
} | ||
}; | ||
|
||
internal class Admin : Person | ||
{ | ||
}; | ||
|
||
internal class Ghost : Person | ||
{ | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Gel.Net.Driver\Gel.Net.Driver.csproj"/> | ||
</ItemGroup> | ||
|
||
</Project> |