Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #88 from Surreal-Net/multiple_result_sets
Browse files Browse the repository at this point in the history
  • Loading branch information
ProphetLamb authored Oct 8, 2022
2 parents 34831ae + 56dae29 commit b749267
Show file tree
Hide file tree
Showing 44 changed files with 1,257 additions and 1,055 deletions.
165 changes: 16 additions & 149 deletions src/Abstractions/Database.cs
Original file line number Diff line number Diff line change
@@ -1,142 +1,9 @@
using SurrealDB.Configuration;
using SurrealDB.Models;

namespace SurrealDB.Abstractions;

/// <summary>
/// Shared interface for interacting with a Surreal database instance
/// </summary>
public interface IDatabase<TResponse>
: IDisposable
where TResponse : IResponse {

/// <summary>
/// Retrieves the current session information.
/// </summary>
/// <param name="ct"> </param>
public new Task<TResponse> Info(CancellationToken ct = default);

/// <summary>
/// Switch to a specific namespace and database.
/// </summary>
/// <param name="db"> Switches to a specific namespace. </param>
/// <param name="ns"> Switches to a specific database. </param>
public new Task<TResponse> Use(string db, string ns, CancellationToken ct = default);

/// <summary>
/// Signs up to a specific authentication scope.
/// </summary>
/// <param name="auth"> Variables used in a signin query. </param>
public new Task<TResponse> Signup<TRequest>(TRequest auth, CancellationToken ct = default) where TRequest : IAuth;

/// <summary>
/// Signs in to a specific authentication scope.
/// </summary>
/// <param name="auth"> Variables used in a signin query. </param>
/// <remarks>
/// This updates the internal <see cref="Config" />.
/// </remarks>
public new Task<TResponse> Signin<TRequest>(TRequest auth, CancellationToken ct = default) where TRequest : IAuth;

/// <summary>
/// Invalidates the authentication for the current connection.
/// </summary>
/// <remarks>
/// This updates the internal <see cref="Config" />.
/// </remarks>
public new Task<TResponse> Invalidate(CancellationToken ct = default);

/// <summary>
/// Authenticates the current connection with a JWT token.
/// </summary>
/// <param name="token"> The JWT authentication token. </param>
/// <remarks>
/// This updates the internal <see cref="Config" />.
/// </remarks>
public new Task<TResponse> Authenticate(string token, CancellationToken ct = default);

/// <summary>
/// Assigns a value as a parameter for this connection.
/// </summary>
/// <param name="key"> Specifies the name of the variable. </param>
/// <param name="value"> Assigns the value to the variable name. </param>
public new Task<TResponse> Let(string key, object? value, CancellationToken ct = default);

/// <summary>
/// Runs a set of SurrealQL statements against the database.
/// </summary>
/// #
/// <param name="sql"> Specifies the SurrealQL statements. </param>
/// <param name="vars"> Assigns variables which can be used in the query. </param>
public new Task<TResponse> Query(string sql, IReadOnlyDictionary<string, object?>? vars, CancellationToken ct = default);

/// <summary>
/// Selects all records in a table, or a specific record, from the database.
/// </summary>
/// <param name="thing"> The table name or a record id to select. </param>
/// <remarks>
/// This function will run the following query in the database:
/// <code>SELECT * FROM $thing;</code>
/// </remarks>
public new Task<TResponse> Select(Thing thing, CancellationToken ct = default);

/// <summary>
/// Creates a record in the database.
/// </summary>
/// <param name="thing"> The table name or the specific record id to create. </param>
/// <param name="data"> The document / record data to insert. </param>
/// <remarks>
/// This function will run the following query in the database:
/// <code>CREATE $thing CONTENT $data;</code>
/// </remarks>
public new Task<TResponse> Create(Thing thing, object data, CancellationToken ct = default);
using DriverResponse = SurrealDB.Models.Result.DriverResponse;

/// <summary>
/// Updates all records in a table, or a specific record, in the database.
/// </summary>
/// <param name="thing"> The table name or the specific record id to update. </param>
/// <param name="data"> The document / record data to insert. </param>
/// <remarks>
/// This function replaces the current document / record data with the specified data.
/// This function will run the following query in the database:
/// <code>UPDATE $thing CONTENT $data;</code>
/// </remarks>
public new Task<TResponse> Update(Thing thing, object data, CancellationToken ct = default);

/// <summary>
/// Modifies all records in a table, or a specific record, in the database.
/// </summary>
/// <param name="thing"> The table name or the specific record id to update. </param>
/// <param name="data"> The document / record data to insert. </param>
/// <remarks>
/// This function merges the current document / record data with the specified data.
/// This function will run the following query in the database:
/// <code>UPDATE $thing MERGE $data;</code>
/// </remarks>
public new Task<TResponse> Change(Thing thing, object data, CancellationToken ct = default);

/// <summary>
/// Applies <see href="https://jsonpatch.com/"> JSON Patch </see> changes to all records, or a specific record, in the database.
/// </summary>
/// <param name="thing"> The table name or the specific record id to update. </param>
/// <param name="patches"> The JSON Patch data with which to modify the records. </param>
/// <remarks>
/// This function patches the current document / record data with the specified JSON Patch data.
/// This function will run the following query in the database:
/// <code>UPDATE $thing PATCH $data;</code>
/// </remarks>
public new Task<TResponse> Modify(Thing thing, Patch[] patches, CancellationToken ct = default);

/// <summary>
/// Deletes all records in a table, or a specific record, from the database.
/// </summary>
/// <param name="thing"> The table name or a record id to select. </param>
/// <remarks>
/// This function will run the following query in the database:
/// <code>DELETE * FROM $thing;</code>
/// </remarks>
public new Task<TResponse> Delete(Thing thing, CancellationToken ct = default);
}
namespace SurrealDB.Abstractions;

/// <summary>
/// Shared interface for interacting with a Surreal database instance
Expand Down Expand Up @@ -168,20 +35,20 @@ public interface IDatabase
/// <summary>
/// Retrieves the current session information.
/// </summary>
public Task<IResponse> Info(CancellationToken ct = default);
public Task<DriverResponse> Info(CancellationToken ct = default);

/// <summary>
/// Switch to a specific namespace and database.
/// </summary>
/// <param name="db"> Switches to a specific namespace. </param>
/// <param name="ns"> Switches to a specific database. </param>
public Task<IResponse> Use(string db, string ns, CancellationToken ct = default);
public Task<DriverResponse> Use(string db, string ns, CancellationToken ct = default);

/// <summary>
/// Signs up to a specific authentication scope.
/// </summary>
/// <param name="auth"> Variables used in a signin query. </param>
public Task<IResponse> Signup<TRequest>(TRequest auth, CancellationToken ct = default) where TRequest : IAuth;
public Task<DriverResponse> Signup<TRequest>(TRequest auth, CancellationToken ct = default) where TRequest : IAuth;

/// <summary>
/// Signs in to a specific authentication scope.
Expand All @@ -190,15 +57,15 @@ public interface IDatabase
/// <remarks>
/// This updates the internal <see cref="Config" />.
/// </remarks>
public Task<IResponse> Signin<TRequest>(TRequest auth, CancellationToken ct = default) where TRequest : IAuth;
public Task<DriverResponse> Signin<TRequest>(TRequest auth, CancellationToken ct = default) where TRequest : IAuth;

/// <summary>
/// Invalidates the authentication for the current connection.
/// </summary>
/// <remarks>
/// This updates the internal <see cref="Config" />.
/// </remarks>
public Task<IResponse> Invalidate(CancellationToken ct = default);
public Task<DriverResponse> Invalidate(CancellationToken ct = default);

/// <summary>
/// Authenticates the current connection with a JWT token.
Expand All @@ -207,14 +74,14 @@ public interface IDatabase
/// <remarks>
/// This updates the internal <see cref="Config" />.
/// </remarks>
public Task<IResponse> Authenticate(string token, CancellationToken ct = default);
public Task<DriverResponse> Authenticate(string token, CancellationToken ct = default);

/// <summary>
/// Assigns a value as a parameter for this connection.
/// </summary>
/// <param name="key"> Specifies the name of the variable. </param>
/// <param name="value"> Assigns the value to the variable name. </param>
public Task<IResponse> Let(string key, object? value, CancellationToken ct = default);
public Task<DriverResponse> Let(string key, object? value, CancellationToken ct = default);

/// <summary>
/// Runs a set of SurrealQL statements against the database.
Expand All @@ -223,7 +90,7 @@ public interface IDatabase
/// <param name="sql"> Specifies the SurrealQL statements. </param>
/// <param name="vars"> Assigns variables which can be used in the query. </param>
/// <param name="ct"> </param>
public Task<IResponse> Query(string sql, IReadOnlyDictionary<string, object?>? vars = null, CancellationToken ct = default);
public Task<DriverResponse> Query(string sql, IReadOnlyDictionary<string, object?>? vars = null, CancellationToken ct = default);

/// <summary>
/// Selects all records in a table, or a specific record, from the database.
Expand All @@ -233,7 +100,7 @@ public interface IDatabase
/// This function will run the following query in the database:
/// <code>SELECT * FROM $thing;</code>
/// </remarks>
public Task<IResponse> Select(Thing thing, CancellationToken ct = default);
public Task<DriverResponse> Select(Thing thing, CancellationToken ct = default);

/// <summary>
/// Creates a record in the database.
Expand All @@ -244,7 +111,7 @@ public interface IDatabase
/// This function will run the following query in the database:
/// <code>CREATE $thing CONTENT $data;</code>
/// </remarks>
public Task<IResponse> Create(Thing thing, object data, CancellationToken ct = default);
public Task<DriverResponse> Create(Thing thing, object data, CancellationToken ct = default);

/// <summary>
/// Updates all records in a table, or a specific record, in the database.
Expand All @@ -256,7 +123,7 @@ public interface IDatabase
/// This function will run the following query in the database:
/// <code>UPDATE $thing CONTENT $data;</code>
/// </remarks>
public Task<IResponse> Update(Thing thing, object data, CancellationToken ct = default);
public Task<DriverResponse> Update(Thing thing, object data, CancellationToken ct = default);

/// <summary>
/// Modifies all records in a table, or a specific record, in the database.
Expand All @@ -268,7 +135,7 @@ public interface IDatabase
/// This function will run the following query in the database:
/// <code>UPDATE $thing MERGE $data;</code>
/// </remarks>
public Task<IResponse> Change(Thing thing, object data, CancellationToken ct = default);
public Task<DriverResponse> Change(Thing thing, object data, CancellationToken ct = default);

/// <summary>
/// Applies <see href="https://jsonpatch.com/"> JSON Patch </see> changes to all records, or a specific record, in the database.
Expand All @@ -280,7 +147,7 @@ public interface IDatabase
/// This function will run the following query in the database:
/// <code>UPDATE $thing PATCH $data;</code>
/// </remarks>
public Task<IResponse> Modify(Thing thing, Patch[] data, CancellationToken ct = default);
public Task<DriverResponse> Modify(Thing thing, Patch[] data, CancellationToken ct = default);

/// <summary>
/// Deletes all records in a table, or a specific record, from the database.
Expand All @@ -290,5 +157,5 @@ public interface IDatabase
/// This function will run the following query in the database:
/// <code>DELETE * FROM $thing;</code>
/// </remarks>
public Task<IResponse> Delete(Thing thing, CancellationToken ct = default);
public Task<DriverResponse> Delete(Thing thing, CancellationToken ct = default);
}
Loading

0 comments on commit b749267

Please sign in to comment.