-
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
35 changed files
with
1,963 additions
and
88 deletions.
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
Binary file not shown.
20 changes: 20 additions & 0 deletions
20
examples/EdgeDB.Examples.GenerationExample/EdgeDB.Examples.GenerationExample.csproj
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,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> |
34 changes: 34 additions & 0 deletions
34
examples/EdgeDB.Examples.GenerationExample/EdgeDB.Generated/CreateUser.g.cs
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,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 |
29 changes: 29 additions & 0 deletions
29
examples/EdgeDB.Examples.GenerationExample/EdgeDB.Generated/DeleteUser.g.cs
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,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 |
13 changes: 13 additions & 0 deletions
13
examples/EdgeDB.Examples.GenerationExample/EdgeDB.Generated/EdgeDB.Generated.csproj
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,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> |
38 changes: 38 additions & 0 deletions
38
examples/EdgeDB.Examples.GenerationExample/EdgeDB.Generated/GetUser.g.cs
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,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 |
29 changes: 29 additions & 0 deletions
29
examples/EdgeDB.Examples.GenerationExample/EdgeDB.Generated/UpdateUser.g.cs
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,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 |
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,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]"); |
6 changes: 6 additions & 0 deletions
6
examples/EdgeDB.Examples.GenerationExample/Scrips/CreateUser.edgeql
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,6 @@ | ||
INSERT Person { | ||
name := <str>$name, | ||
email := <str>$email | ||
} | ||
UNLESS CONFLICT ON .email | ||
ELSE (SELECT Person) |
1 change: 1 addition & 0 deletions
1
examples/EdgeDB.Examples.GenerationExample/Scrips/DeleteUser.edgeql
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 @@ | ||
delete Person filter .email = <str>$email |
4 changes: 4 additions & 0 deletions
4
examples/EdgeDB.Examples.GenerationExample/Scrips/GetUser.edgeql
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,4 @@ | ||
select Person { | ||
name, email | ||
} | ||
filter .email = <str>$email |
1 change: 1 addition & 0 deletions
1
examples/EdgeDB.Examples.GenerationExample/Scrips/UpdateUser.edgeql
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 @@ | ||
update Person filter .id = <uuid>$id set { name := <str>$name, email := <str>$email } |
Binary file not shown.
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,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; | ||
} | ||
} | ||
} |
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,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; | ||
} | ||
} |
Oops, something went wrong.