|
1 | | -using System.Linq; |
| 1 | +using System.Diagnostics; |
| 2 | +using System.Linq; |
2 | 3 | using System.Net; |
3 | 4 | using System.Net.Http; |
4 | 5 | using System.Net.Http.Headers; |
|
7 | 8 |
|
8 | 9 | namespace ArcadeDb.Client; |
9 | 10 |
|
10 | | -public enum QueryLanguage |
11 | | -{ |
12 | | - Sql, |
13 | | - Cypher |
14 | | -} |
15 | | - |
16 | 11 | public class RemoteDatabase : IDisposable |
17 | 12 | { |
18 | 13 | private readonly HttpClient httpClient; |
@@ -43,16 +38,16 @@ public async Task<DatabaseResult> Create(string? database = null) => |
43 | 38 | public async Task<DatabaseResult> Drop(string? database = null) => |
44 | 39 | await this.HttpCommand("drop", database ?? this.Database); |
45 | 40 |
|
46 | | - public async Task<DatabaseResult<T>> Command<T>(string command, object @params, QueryLanguage language = QueryLanguage.Sql) => |
| 41 | + public async Task<DatabaseResult<T>> Command<T>(string command, object? @params = null, QueryLanguage language = QueryLanguage.Sql) => |
47 | 42 | await this.HttpCommand<DatabaseResult<T>>("command", this.Database, command, @params, language).ConfigureAwait(false); |
48 | 43 |
|
49 | | - public async Task<DatabaseResult<T>> Query<T>(string command, object @params, QueryLanguage language = QueryLanguage.Sql) => |
| 44 | + public async Task<DatabaseResult<T>> Query<T>(string command, object? @params = null, QueryLanguage language = QueryLanguage.Sql) => |
50 | 45 | await this.HttpCommand<DatabaseResult<T>>("query", this.Database, command, @params, language).ConfigureAwait(false); |
51 | 46 |
|
52 | | - public async Task<DatabaseResult> Command(string command, object @params, QueryLanguage language = QueryLanguage.Sql) => |
| 47 | + public async Task<DatabaseResult> Command(string command, object? @params = null, QueryLanguage language = QueryLanguage.Sql) => |
53 | 48 | await this.HttpCommand("command", this.Database, command, @params, language).ConfigureAwait(false); |
54 | 49 |
|
55 | | - public async Task<DatabaseResult> Query(string command, object @params, QueryLanguage language = QueryLanguage.Sql) => |
| 50 | + public async Task<DatabaseResult> Query(string command, object? @params = null, QueryLanguage language = QueryLanguage.Sql) => |
56 | 51 | await this.HttpCommand("query", this.Database, command, @params, language).ConfigureAwait(false); |
57 | 52 |
|
58 | 53 | private async Task<DatabaseResult> HttpCommand(string operation, string database, string? command = null, object? @params = null, |
@@ -84,6 +79,8 @@ private async Task<T> HttpCommand<T>(string operation, string database, string? |
84 | 79 | }; |
85 | 80 | } |
86 | 81 |
|
| 82 | + Debug.WriteLine(await response.Content.ReadAsStringAsync()); |
| 83 | + |
87 | 84 | return await JsonSerializer.DeserializeAsync<T>(await response.Content.ReadAsStreamAsync(), Json.DefaultSerializerOptions) |
88 | 85 | .ConfigureAwait(false) ?? throw new ArcadeDbException($"Could not deserialize result as {nameof(T)}."); |
89 | 86 | } |
|
0 commit comments