Skip to content

Commit

Permalink
Add XML docs and other minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
arthrp committed Apr 30, 2022
1 parent 8906d8f commit 0269944
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
30 changes: 27 additions & 3 deletions RqliteDotnet/RqliteClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@ public RqliteClient(string uri, HttpClient? client = null)
{
_httpClient = client ?? new HttpClient(){ BaseAddress = new Uri(uri) };
}


/// <summary>
/// Ping Rqlite instance
/// </summary>
/// <returns>String containining Rqlite version</returns>
public async Task<string> Ping()
{
var x = await _httpClient.GetAsync("/status");

return x.Headers.GetValues("X-Rqlite-Version").FirstOrDefault()!;
}


/// <summary>
/// Query DB and return result
/// </summary>
/// <param name="query"></param>
public async Task<QueryResults> Query(string query)
{
var data = "&q="+Uri.EscapeDataString(query);
Expand All @@ -33,7 +41,10 @@ public async Task<QueryResults> Query(string query)
var result = JsonSerializer.Deserialize<QueryResults>(str, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true });
return result;
}


/// <summary>
/// Execute command and return result
/// </summary>
public async Task<ExecuteResults> Execute(string command)
{
var request = new HttpRequestMessage(HttpMethod.Post, "/db/execute?timings");
Expand All @@ -43,6 +54,12 @@ public async Task<ExecuteResults> Execute(string command)
return result;
}

/// <summary>
/// Execute one or several commands and return result
/// </summary>
/// <param name="commands">Commands to execute</param>
/// <param name="flags">Command flags, e.g. whether to use transaction</param>
/// <returns></returns>
public async Task<ExecuteResults> Execute(IEnumerable<string> commands, DbFlag? flags)
{
var parameters = GetParameters(flags);
Expand All @@ -55,6 +72,13 @@ public async Task<ExecuteResults> Execute(IEnumerable<string> commands, DbFlag?
return result;
}

/// <summary>
/// Query DB using parametrized statement
/// </summary>
/// <param name="query"></param>
/// <param name="qps"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public async Task<QueryResults> QueryParams<T>(string query, params T[] qps) where T: QueryParameter
{
var request = new HttpRequestMessage(HttpMethod.Post, "/db/query?timings");
Expand Down
2 changes: 1 addition & 1 deletion RqliteDotnet/RqliteDotnet.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>RqliteDotnet</id>
<version>1.0.1</version>
<version>1.0.2</version>
<authors>arthrp, otoolep et al.</authors>
<description>Client for Rqlite - lightweight distributed database</description>
<language>en-US</language>
Expand Down
6 changes: 3 additions & 3 deletions RqliteDotnet/RqliteOrmClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class RqliteOrmClient : RqliteClient
public RqliteOrmClient(string uri, HttpClient? client = null) : base(uri, client) {}

/// <summary>
/// Query Rqlite and return result as an instance of T
/// Query Rqlite DB and return result as an instance of T
/// </summary>
/// <param name="query">Query to execute</param>
/// <typeparam name="T">Type of result object</typeparam>
Expand All @@ -30,9 +30,9 @@ public RqliteOrmClient(string uri, HttpClient? client = null) : base(uri, client
foreach (var prop in typeof(T).GetProperties())
{
var index = res.Columns.FindIndex(c => c.ToLower() == prop.Name.ToLower());
var x = GetValue(res.Types[index], res.Values[i][index]);
var val = GetValue(res.Types[index], res.Values[i][index]);

prop.SetValue(dto, x);
prop.SetValue(dto, val);
}

list.Add(dto);
Expand Down

0 comments on commit 0269944

Please sign in to comment.