Skip to content
This repository was archived by the owner on Oct 6, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,6 @@ MigrationBackup/
# Fody - auto-generated XML schema
FodyWeavers.xsd
src/EdgeDB.ExampleApp/dump.db

# EdgeDB.Net CLI watcher info file
edgeql.dotnet.watcher.process
31 changes: 24 additions & 7 deletions EdgeDB.Net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{67ED9EF0
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EdgeDB.QueryBuilder.OperatorGenerator", "tools\EdgeDB.QueryBuilder.OperatorGenerator\EdgeDB.QueryBuilder.OperatorGenerator.csproj", "{1557B745-EB4F-449A-9BE7-180C8990AD47}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EdgeDB.DotnetTool", "tools\EdgeDB.DotnetTool\EdgeDB.DotnetTool.csproj", "{74DB9D5E-9BA9-4282-90EA-2F7BDC4C4FBD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EdgeDB.Tests.Integration", "tests\EdgeDB.Tests.Integration\EdgeDB.Tests.Integration.csproj", "{C189294A-4990-4A06-B120-A0AF03A798C6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EdgeDB.Tests.Benchmarks", "tests\EdgeDB.Tests.Benchmarks\EdgeDB.Tests.Benchmarks.csproj", "{5FFD1E88-614D-409B-8420-F9571AC7CA60}"
Expand All @@ -35,6 +33,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EdgeDB.Serializer.Experimen
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("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EdgeDB.Net.CLI", "src\EdgeDB.Net.CLI\EdgeDB.Net.CLI.csproj", "{77D1980E-9835-4D16-B7B4-6CB5A4BD570C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CLI Generation Example", "CLI Generation Example", "{46E94884-7A3D-4B48-9734-916ECCCB85C0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EdgeDB.Examples.GenerationExample", "examples\EdgeDB.Examples.GenerationExample\EdgeDB.Examples.GenerationExample.csproj", "{4BCAA352-8488-46A9-B3C9-D2C50E937AFC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EdgeDB.Generated", "examples\EdgeDB.Examples.GenerationExample\EdgeDB.Generated\EdgeDB.Generated.csproj", "{E03D7BD1-B093-44FF-B276-410345430523}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -61,10 +67,6 @@ Global
{1557B745-EB4F-449A-9BE7-180C8990AD47}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1557B745-EB4F-449A-9BE7-180C8990AD47}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1557B745-EB4F-449A-9BE7-180C8990AD47}.Release|Any CPU.Build.0 = Release|Any CPU
{74DB9D5E-9BA9-4282-90EA-2F7BDC4C4FBD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{74DB9D5E-9BA9-4282-90EA-2F7BDC4C4FBD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74DB9D5E-9BA9-4282-90EA-2F7BDC4C4FBD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74DB9D5E-9BA9-4282-90EA-2F7BDC4C4FBD}.Release|Any CPU.Build.0 = Release|Any CPU
{C189294A-4990-4A06-B120-A0AF03A798C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C189294A-4990-4A06-B120-A0AF03A798C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C189294A-4990-4A06-B120-A0AF03A798C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -85,6 +87,18 @@ Global
{E38429C6-53A5-4311-8189-1F78238666DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E38429C6-53A5-4311-8189-1F78238666DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E38429C6-53A5-4311-8189-1F78238666DC}.Release|Any CPU.Build.0 = Release|Any CPU
{77D1980E-9835-4D16-B7B4-6CB5A4BD570C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{77D1980E-9835-4D16-B7B4-6CB5A4BD570C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{77D1980E-9835-4D16-B7B4-6CB5A4BD570C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{77D1980E-9835-4D16-B7B4-6CB5A4BD570C}.Release|Any CPU.Build.0 = Release|Any CPU
{4BCAA352-8488-46A9-B3C9-D2C50E937AFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4BCAA352-8488-46A9-B3C9-D2C50E937AFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4BCAA352-8488-46A9-B3C9-D2C50E937AFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4BCAA352-8488-46A9-B3C9-D2C50E937AFC}.Release|Any CPU.Build.0 = Release|Any CPU
{E03D7BD1-B093-44FF-B276-410345430523}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E03D7BD1-B093-44FF-B276-410345430523}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E03D7BD1-B093-44FF-B276-410345430523}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E03D7BD1-B093-44FF-B276-410345430523}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -95,12 +109,15 @@ Global
{CD4A4B5D-4B67-4E64-A13B-3F7BF770B056} = {E6B9FABC-241B-4561-9A94-E67B6BE380E2}
{4CC2101C-D0AB-4F08-A0FD-205F96958196} = {025AAADF-16AF-4367-9C3D-9E60EDED832F}
{1557B745-EB4F-449A-9BE7-180C8990AD47} = {67ED9EF0-7828-44C0-8CB0-DEBD69EC94CA}
{74DB9D5E-9BA9-4282-90EA-2F7BDC4C4FBD} = {67ED9EF0-7828-44C0-8CB0-DEBD69EC94CA}
{C189294A-4990-4A06-B120-A0AF03A798C6} = {E6B9FABC-241B-4561-9A94-E67B6BE380E2}
{5FFD1E88-614D-409B-8420-F9571AC7CA60} = {E6B9FABC-241B-4561-9A94-E67B6BE380E2}
{3A4AAAA0-9948-43D3-B838-8EFAC130240C} = {67ED9EF0-7828-44C0-8CB0-DEBD69EC94CA}
{6FA68DEA-D398-4A5B-8025-5F15C728F04C} = {49B6FB80-A675-4ECA-802C-2337A4F37566}
{E38429C6-53A5-4311-8189-1F78238666DC} = {6FC214F5-C912-4D99-91B1-3E9F52A4E11B}
{77D1980E-9835-4D16-B7B4-6CB5A4BD570C} = {025AAADF-16AF-4367-9C3D-9E60EDED832F}
{46E94884-7A3D-4B48-9734-916ECCCB85C0} = {6FC214F5-C912-4D99-91B1-3E9F52A4E11B}
{4BCAA352-8488-46A9-B3C9-D2C50E937AFC} = {46E94884-7A3D-4B48-9734-916ECCCB85C0}
{E03D7BD1-B093-44FF-B276-410345430523} = {46E94884-7A3D-4B48-9734-916ECCCB85C0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4E90C94F-D693-4411-82F3-2051DE1BE052}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
Expand All @@ -11,7 +11,6 @@
"profiles": {
"EdgeDB.Examples.ExampleTODOApi": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7155;http://localhost:5155",
Expand All @@ -28,4 +27,4 @@
}
}
}
}
}
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: "example@example.com");

// Get a user based on email
var user = await client.GetUserAsync(email: "example@example.com");
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 }
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.ResolveConnection();

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;
}
}
}
Loading