Skip to content

Commit

Permalink
rebase to v1 driver
Browse files Browse the repository at this point in the history
  • Loading branch information
quinchs committed Nov 7, 2022
1 parent de3e954 commit a214b21
Show file tree
Hide file tree
Showing 35 changed files with 1,963 additions and 88 deletions.
26 changes: 25 additions & 1 deletion EdgeDB.Net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EdgeDB.BinaryDebugger", "to
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EdgeDB.Examples.ExampleTODOApi", "examples\EdgeDB.Examples.ExampleTODOApi\EdgeDB.Examples.ExampleTODOApi.csproj", "{E38429C6-53A5-4311-8189-1F78238666DC}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "EdgeDB.Examples.FSharp", "examples\EdgeDB.Examples.FSharp\EdgeDB.Examples.FSharp.fsproj", "{F25AA805-163F-46B4-942E-B1A5EBE8383C}"
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "EdgeDB.Examples.FSharp", "examples\EdgeDB.Examples.FSharp\EdgeDB.Examples.FSharp.fsproj", "{F25AA805-163F-46B4-942E-B1A5EBE8383C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EdgeDB.DocGenerator", "tools\EdgeDB.DocGenerator\EdgeDB.DocGenerator.csproj", "{776EAE34-5A30-45B0-9277-C399CC2ABA53}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EdgeDB.Net.CLI", "src\EdgeDB.Net.CLI\EdgeDB.Net.CLI.csproj", "{AC6DAA7B-5510-47BF-9759-1A16565F24A8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EdgeDB.Examples.GenerationExample", "examples\EdgeDB.Examples.GenerationExample\EdgeDB.Examples.GenerationExample.csproj", "{EAA9EF1A-0F10-4F74-B2F4-1C5BBC505866}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CodeGen", "CodeGen", "{C9B0F9DB-E508-4AC1-87E5-BD82A8AB007A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EdgeDB.Generated", "examples\EdgeDB.Examples.GenerationExample\EdgeDB.Generated\EdgeDB.Generated.csproj", "{3B1610BC-ECC6-427B-96BC-48FFB2DD1DC6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -83,6 +91,18 @@ Global
{776EAE34-5A30-45B0-9277-C399CC2ABA53}.Debug|Any CPU.Build.0 = Debug|Any CPU
{776EAE34-5A30-45B0-9277-C399CC2ABA53}.Release|Any CPU.ActiveCfg = Release|Any CPU
{776EAE34-5A30-45B0-9277-C399CC2ABA53}.Release|Any CPU.Build.0 = Release|Any CPU
{AC6DAA7B-5510-47BF-9759-1A16565F24A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AC6DAA7B-5510-47BF-9759-1A16565F24A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC6DAA7B-5510-47BF-9759-1A16565F24A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC6DAA7B-5510-47BF-9759-1A16565F24A8}.Release|Any CPU.Build.0 = Release|Any CPU
{EAA9EF1A-0F10-4F74-B2F4-1C5BBC505866}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EAA9EF1A-0F10-4F74-B2F4-1C5BBC505866}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EAA9EF1A-0F10-4F74-B2F4-1C5BBC505866}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EAA9EF1A-0F10-4F74-B2F4-1C5BBC505866}.Release|Any CPU.Build.0 = Release|Any CPU
{3B1610BC-ECC6-427B-96BC-48FFB2DD1DC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B1610BC-ECC6-427B-96BC-48FFB2DD1DC6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B1610BC-ECC6-427B-96BC-48FFB2DD1DC6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B1610BC-ECC6-427B-96BC-48FFB2DD1DC6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -99,6 +119,10 @@ Global
{E38429C6-53A5-4311-8189-1F78238666DC} = {6FC214F5-C912-4D99-91B1-3E9F52A4E11B}
{F25AA805-163F-46B4-942E-B1A5EBE8383C} = {6FC214F5-C912-4D99-91B1-3E9F52A4E11B}
{776EAE34-5A30-45B0-9277-C399CC2ABA53} = {67ED9EF0-7828-44C0-8CB0-DEBD69EC94CA}
{AC6DAA7B-5510-47BF-9759-1A16565F24A8} = {025AAADF-16AF-4367-9C3D-9E60EDED832F}
{EAA9EF1A-0F10-4F74-B2F4-1C5BBC505866} = {C9B0F9DB-E508-4AC1-87E5-BD82A8AB007A}
{C9B0F9DB-E508-4AC1-87E5-BD82A8AB007A} = {6FC214F5-C912-4D99-91B1-3E9F52A4E11B}
{3B1610BC-ECC6-427B-96BC-48FFB2DD1DC6} = {C9B0F9DB-E508-4AC1-87E5-BD82A8AB007A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4E90C94F-D693-4411-82F3-2051DE1BE052}
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Compile Remove="EdgeDB.Generated\**" />
<EmbeddedResource Remove="EdgeDB.Generated\**" />
<None Remove="EdgeDB.Generated\**" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="EdgeDB.Generated\EdgeDB.Generated.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// AUTOGENERATED: DO NOT MODIFY
// edgeql:B9692A5CA0A9992246361197BEACBDE398A5A30C5DCCC83BCACD8C80D5842FEB
// Generated on 2022-08-26T11:55:03.5378711Z
#nullable enable
using EdgeDB;

namespace EdgeDB.Generated;

#region Types
[EdgeDBType]
public sealed class CreateUserResult
{
[EdgeDBProperty("id")]
public Guid Id { get; set; }
}

#endregion

public static class CreateUser
{
public static readonly string Query = @"INSERT Person {
name := <str>$name,
email := <str>$email
}
UNLESS CONFLICT ON .email
ELSE (SELECT Person)";

public static Task<CreateUserResult?> ExecuteAsync(IEdgeDBQueryable client, String? name, String? email, CancellationToken token = default)
=> client.QuerySingleAsync<CreateUserResult>(Query, new Dictionary<string, object?>() { { "name", name }, { "email", email } }, capabilities: (Capabilities)1ul, token: token);

public static Task<CreateUserResult?> CreateUserAsync(this IEdgeDBQueryable client, String? name, String? email, CancellationToken token = default)
=> ExecuteAsync(client, name, email, token: token);
}
#nullable restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// AUTOGENERATED: DO NOT MODIFY
// edgeql:28E22B161B70DB5DE661AC86709BEADD3F9DC475559DE90F194CBAF24A5A880C
// Generated on 2022-08-28T12:51:13.6300794Z
#nullable enable
using EdgeDB;

namespace EdgeDB.Generated;

#region Types
[EdgeDBType]
public sealed class DeleteUserResult
{
[EdgeDBProperty("id")]
public Guid Id { get; set; }
}

#endregion

public static class DeleteUser
{
public static readonly string Query = @"delete Person filter .email = <str>$email";

public static Task<DeleteUserResult?> ExecuteAsync(IEdgeDBQueryable client, String? email, CancellationToken token = default)
=> client.QuerySingleAsync<DeleteUserResult>(Query, new Dictionary<string, object?>() { { "email", email } }, capabilities: (Capabilities)1ul, token: token);

public static Task<DeleteUserResult?> DeleteUserAsync(this IEdgeDBQueryable client, String? email, CancellationToken token = default)
=> ExecuteAsync(client, email, token: token);
}
#nullable restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\EdgeDB.Net.Driver\EdgeDB.Net.Driver.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// AUTOGENERATED: DO NOT MODIFY
// edgeql:E116C5881529C70BFC6A9D0350075968AD967D391FEE0F74033FA870A1FE56DD
// Generated on 2022-08-26T11:52:03.5962767Z
#nullable enable
using EdgeDB;

namespace EdgeDB.Generated;

#region Types
[EdgeDBType]
public sealed class GetUserResult
{
[EdgeDBProperty("id")]
public Guid Id { get; set; }

[EdgeDBProperty("name")]
public String? Name { get; set; }

[EdgeDBProperty("email")]
public String? Email { get; set; }
}

#endregion

public static class GetUser
{
public static readonly string Query = @"select Person {
name, email
}
filter .email = <str>$email";

public static Task<GetUserResult?> ExecuteAsync(IEdgeDBQueryable client, String? email, CancellationToken token = default)
=> client.QuerySingleAsync<GetUserResult>(Query, new Dictionary<string, object?>() { { "email", email } }, capabilities: (Capabilities)0ul, token: token);

public static Task<GetUserResult?> GetUserAsync(this IEdgeDBQueryable client, String? email, CancellationToken token = default)
=> ExecuteAsync(client, email, token: token);
}
#nullable restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// AUTOGENERATED: DO NOT MODIFY
// edgeql:A1C5568E24B561F8D8CE4109C9E8E604C801BF104AFA3A4C07A0F2EDB720AC27
// Generated on 2022-08-26T15:33:42.9431602Z
#nullable enable
using EdgeDB;

namespace EdgeDB.Generated;

#region Types
[EdgeDBType]
public sealed class UpdateUserResult
{
[EdgeDBProperty("id")]
public Guid Id { get; set; }
}

#endregion

public static class UpdateUser
{
public static readonly string Query = @"update Person filter .id = <uuid>$id set { name := <str>$name, email := <str>$email }";

public static Task<UpdateUserResult?> ExecuteAsync(IEdgeDBQueryable client, Guid id, String? name, String? email, CancellationToken token = default)
=> client.QuerySingleAsync<UpdateUserResult>(Query, new Dictionary<string, object?>() { { "id", id }, { "name", name }, { "email", email } }, capabilities: (Capabilities)1ul, token: token);

public static Task<UpdateUserResult?> UpdateUserAsync(this IEdgeDBQueryable client, Guid id, String? name, String? email, CancellationToken token = default)
=> ExecuteAsync(client, id, name, email, token: token);
}
#nullable restore
11 changes: 11 additions & 0 deletions examples/EdgeDB.Examples.GenerationExample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using EdgeDB;
using EdgeDB.Generated;

// create a client
var client = new EdgeDBClient();

// create a user
await client.CreateUserAsync(name: "example", email: "[email protected]");

// Get a user based on email
var user = await client.GetUserAsync(email: "[email protected]");
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
INSERT Person {
name := <str>$name,
email := <str>$email
}
UNLESS CONFLICT ON .email
ELSE (SELECT Person)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
delete Person filter .email = <str>$email
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
select Person {
name, email
}
filter .email = <str>$email
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
update Person filter .id = <uuid>$id set { name := <str>$name, email := <str>$email }
Binary file added src/.DS_Store
Binary file not shown.
94 changes: 94 additions & 0 deletions src/EdgeDB.Net.CLI/Arguments/ConnectionArguments.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using CommandLine;
using EdgeDB.CLI.Utils;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EdgeDB.CLI.Arguments
{
public class ConnectionArguments : LogArgs
{
[Option("dsn", HelpText = "DSN for EdgeDB to connect to (overrides all other options except password)")]
public string? DSN { get; set; }

[Option("credentials-file", HelpText = "Path to JSON file to read credentials from")]
public string? CredentialsFile { get; set; }

[Option('I', "instance", HelpText = "Local instance name created with edgedb instance create to connect to (overrides host and port)")]
public string? Instance { get; set; }

[Option('H', "host", HelpText = "Host of the EdgeDB instance")]
public string? Host { get; set; }

[Option('P', "port", HelpText = "Port to connect to EdgeDB")]
public int? Port { get; set; }

[Option('d', "database", HelpText = "Database name to connect to")]
public string? Database { get; set; }

[Option('u', "user", HelpText = "User name of the EdgeDB user")]
public string? User { get; set; }

[Option("password", HelpText = "Ask for password on the terminal (TTY)")]
public bool Password { get; set; }

[Option("password-from-stdin", HelpText = "Read the password from stdin rather than TTY (useful for scripts)")]
public bool PasswordFromSTDIN { get; set; }

[Option("tls-ca-file", HelpText = "Certificate to match server against\n\nThis might either be full self-signed server certificate or certificate authority (CA) certificate that server certificate is signed with.")]
public string? TLSCAFile { get; set; }

[Option("tls-security", HelpText = "Specify the client-side TLS security mode.")]
public TLSSecurityMode? TLSSecurity { get; set; }

public EdgeDBConnection GetConnection()
{
if (DSN is not null)
return EdgeDBConnection.FromDSN(DSN);

if (Instance is not null)
return EdgeDBConnection.FromInstanceName(Instance);

if (CredentialsFile is not null)
return JsonConvert.DeserializeObject<EdgeDBConnection>(File.ReadAllText(CredentialsFile))
?? throw new NullReferenceException($"The file '{CredentialsFile}' didn't contain a valid credential definition");

// create the resolved connection
var resolved = EdgeDBConnection.ResolveEdgeDBTOML();

if (Host is not null)
resolved.Hostname = Host;

if (Port.HasValue)
resolved.Port = Port.Value;

if (Database is not null)
resolved.Database = Database;

if (User is not null)
resolved.Username = User;

if (Password)
{
// read password from console
Console.Write($"Password for '{resolved.Database}': ");

resolved.Password = ConsoleUtils.ReadSecretInput();
}

if (PasswordFromSTDIN)
resolved.Password = Console.ReadLine();

if (TLSCAFile is not null)
resolved.TLSCertificateAuthority = TLSCAFile;

if (TLSSecurity.HasValue)
resolved.TLSSecurity = TLSSecurity.Value;

return resolved;
}
}
}
23 changes: 23 additions & 0 deletions src/EdgeDB.Net.CLI/Arguments/LogArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using CommandLine;
using Microsoft.Extensions.Logging;
using Serilog.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EdgeDB.CLI.Arguments
{
/// <summary>
/// A class containing logger arguments.
/// </summary>
public class LogArgs
{
/// <summary>
/// Gets or sets the log level for the default logger.
/// </summary>
[Option("loglevel", HelpText = "Configure the log level")]
public LogEventLevel LogLevel { get; set; } = LogEventLevel.Information;
}
}
Loading

0 comments on commit a214b21

Please sign in to comment.