Skip to content

Commit

Permalink
Code refactoring (#17)
Browse files Browse the repository at this point in the history
* Code cleanup and fixing compilation warnings related to nullability

* Remove unused imports
  • Loading branch information
arthrp authored Nov 9, 2024
1 parent b96415c commit b22b2fc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 29 deletions.
2 changes: 1 addition & 1 deletion RqliteDotnet/IRqliteClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface IRqliteClient
/// <param name="level"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<QueryResults> Query(string query, ReadLevel level, CancellationToken cancellationToken);
Task<QueryResults?> Query(string query, ReadLevel level, CancellationToken cancellationToken);

/// <summary>
/// Execute command and return result
Expand Down
18 changes: 18 additions & 0 deletions RqliteDotnet/IRqliteOrmClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using RqliteDotnet.Dto;

namespace RqliteDotnet;

public interface IRqliteOrmClient : IRqliteClient
{
/// <summary>
/// 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>
/// <returns></returns>
Task<List<T>> Query<T>(string query) where T: new();

Task<List<U>> QueryParams<T, U>(string query, CancellationToken cancellationToken, params T[] qps)
where T: QueryParameter
where U : new();
}
8 changes: 1 addition & 7 deletions RqliteDotnet/RqliteClient.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
using RqliteDotnet.Dto;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace RqliteDotnet;

Expand All @@ -33,7 +27,7 @@ public async Task<string> Ping(CancellationToken cancellationToken = default)
}

/// <inheritdoc />
public async Task<QueryResults> Query(string query, ReadLevel level = ReadLevel.Default, CancellationToken cancellationToken = default)
public async Task<QueryResults?> Query(string query, ReadLevel level = ReadLevel.Default, CancellationToken cancellationToken = default)
{
var url = UrlBuilder.Build("/db/query?timings", query, level);

Expand Down
22 changes: 1 addition & 21 deletions RqliteDotnet/RqliteOrmClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,13 @@

namespace RqliteDotnet;

public interface IRqliteOrmClient : IRqliteClient
{
/// <summary>
/// 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>
/// <returns></returns>
Task<List<T>> Query<T>(string query) where T: new();

Task<List<U>> QueryParams<T, U>(string query, CancellationToken cancellationToken, params T[] qps)
where T: QueryParameter
where U : new();
}

public class RqliteOrmClient : RqliteClient, IRqliteOrmClient
{
public RqliteOrmClient(HttpClient client) : base(client) { }

public RqliteOrmClient(string uri, HttpClient? client = null) : base(uri, client) {}

/// <summary>
/// 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>
/// <returns></returns>
/// <inheritdoc />
public async Task<List<T>> Query<T>(string query) where T : new()
{
var response = await Query(query);
Expand Down

0 comments on commit b22b2fc

Please sign in to comment.