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

Commit b749267

Browse files
authored
Merge pull request #88 from Surreal-Net/multiple_result_sets
2 parents 34831ae + 56dae29 commit b749267

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1257
-1055
lines changed

src/Abstractions/Database.cs

Lines changed: 16 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,9 @@
11
using SurrealDB.Configuration;
22
using SurrealDB.Models;
33

4-
namespace SurrealDB.Abstractions;
5-
6-
/// <summary>
7-
/// Shared interface for interacting with a Surreal database instance
8-
/// </summary>
9-
public interface IDatabase<TResponse>
10-
: IDisposable
11-
where TResponse : IResponse {
12-
13-
/// <summary>
14-
/// Retrieves the current session information.
15-
/// </summary>
16-
/// <param name="ct"> </param>
17-
public new Task<TResponse> Info(CancellationToken ct = default);
18-
19-
/// <summary>
20-
/// Switch to a specific namespace and database.
21-
/// </summary>
22-
/// <param name="db"> Switches to a specific namespace. </param>
23-
/// <param name="ns"> Switches to a specific database. </param>
24-
public new Task<TResponse> Use(string db, string ns, CancellationToken ct = default);
25-
26-
/// <summary>
27-
/// Signs up to a specific authentication scope.
28-
/// </summary>
29-
/// <param name="auth"> Variables used in a signin query. </param>
30-
public new Task<TResponse> Signup<TRequest>(TRequest auth, CancellationToken ct = default) where TRequest : IAuth;
31-
32-
/// <summary>
33-
/// Signs in to a specific authentication scope.
34-
/// </summary>
35-
/// <param name="auth"> Variables used in a signin query. </param>
36-
/// <remarks>
37-
/// This updates the internal <see cref="Config" />.
38-
/// </remarks>
39-
public new Task<TResponse> Signin<TRequest>(TRequest auth, CancellationToken ct = default) where TRequest : IAuth;
40-
41-
/// <summary>
42-
/// Invalidates the authentication for the current connection.
43-
/// </summary>
44-
/// <remarks>
45-
/// This updates the internal <see cref="Config" />.
46-
/// </remarks>
47-
public new Task<TResponse> Invalidate(CancellationToken ct = default);
48-
49-
/// <summary>
50-
/// Authenticates the current connection with a JWT token.
51-
/// </summary>
52-
/// <param name="token"> The JWT authentication token. </param>
53-
/// <remarks>
54-
/// This updates the internal <see cref="Config" />.
55-
/// </remarks>
56-
public new Task<TResponse> Authenticate(string token, CancellationToken ct = default);
57-
58-
/// <summary>
59-
/// Assigns a value as a parameter for this connection.
60-
/// </summary>
61-
/// <param name="key"> Specifies the name of the variable. </param>
62-
/// <param name="value"> Assigns the value to the variable name. </param>
63-
public new Task<TResponse> Let(string key, object? value, CancellationToken ct = default);
64-
65-
/// <summary>
66-
/// Runs a set of SurrealQL statements against the database.
67-
/// </summary>
68-
/// #
69-
/// <param name="sql"> Specifies the SurrealQL statements. </param>
70-
/// <param name="vars"> Assigns variables which can be used in the query. </param>
71-
public new Task<TResponse> Query(string sql, IReadOnlyDictionary<string, object?>? vars, CancellationToken ct = default);
72-
73-
/// <summary>
74-
/// Selects all records in a table, or a specific record, from the database.
75-
/// </summary>
76-
/// <param name="thing"> The table name or a record id to select. </param>
77-
/// <remarks>
78-
/// This function will run the following query in the database:
79-
/// <code>SELECT * FROM $thing;</code>
80-
/// </remarks>
81-
public new Task<TResponse> Select(Thing thing, CancellationToken ct = default);
82-
83-
/// <summary>
84-
/// Creates a record in the database.
85-
/// </summary>
86-
/// <param name="thing"> The table name or the specific record id to create. </param>
87-
/// <param name="data"> The document / record data to insert. </param>
88-
/// <remarks>
89-
/// This function will run the following query in the database:
90-
/// <code>CREATE $thing CONTENT $data;</code>
91-
/// </remarks>
92-
public new Task<TResponse> Create(Thing thing, object data, CancellationToken ct = default);
4+
using DriverResponse = SurrealDB.Models.Result.DriverResponse;
935

94-
/// <summary>
95-
/// Updates all records in a table, or a specific record, in the database.
96-
/// </summary>
97-
/// <param name="thing"> The table name or the specific record id to update. </param>
98-
/// <param name="data"> The document / record data to insert. </param>
99-
/// <remarks>
100-
/// This function replaces the current document / record data with the specified data.
101-
/// This function will run the following query in the database:
102-
/// <code>UPDATE $thing CONTENT $data;</code>
103-
/// </remarks>
104-
public new Task<TResponse> Update(Thing thing, object data, CancellationToken ct = default);
105-
106-
/// <summary>
107-
/// Modifies all records in a table, or a specific record, in the database.
108-
/// </summary>
109-
/// <param name="thing"> The table name or the specific record id to update. </param>
110-
/// <param name="data"> The document / record data to insert. </param>
111-
/// <remarks>
112-
/// This function merges the current document / record data with the specified data.
113-
/// This function will run the following query in the database:
114-
/// <code>UPDATE $thing MERGE $data;</code>
115-
/// </remarks>
116-
public new Task<TResponse> Change(Thing thing, object data, CancellationToken ct = default);
117-
118-
/// <summary>
119-
/// Applies <see href="https://jsonpatch.com/"> JSON Patch </see> changes to all records, or a specific record, in the database.
120-
/// </summary>
121-
/// <param name="thing"> The table name or the specific record id to update. </param>
122-
/// <param name="patches"> The JSON Patch data with which to modify the records. </param>
123-
/// <remarks>
124-
/// This function patches the current document / record data with the specified JSON Patch data.
125-
/// This function will run the following query in the database:
126-
/// <code>UPDATE $thing PATCH $data;</code>
127-
/// </remarks>
128-
public new Task<TResponse> Modify(Thing thing, Patch[] patches, CancellationToken ct = default);
129-
130-
/// <summary>
131-
/// Deletes all records in a table, or a specific record, from the database.
132-
/// </summary>
133-
/// <param name="thing"> The table name or a record id to select. </param>
134-
/// <remarks>
135-
/// This function will run the following query in the database:
136-
/// <code>DELETE * FROM $thing;</code>
137-
/// </remarks>
138-
public new Task<TResponse> Delete(Thing thing, CancellationToken ct = default);
139-
}
6+
namespace SurrealDB.Abstractions;
1407

1418
/// <summary>
1429
/// Shared interface for interacting with a Surreal database instance
@@ -168,20 +35,20 @@ public interface IDatabase
16835
/// <summary>
16936
/// Retrieves the current session information.
17037
/// </summary>
171-
public Task<IResponse> Info(CancellationToken ct = default);
38+
public Task<DriverResponse> Info(CancellationToken ct = default);
17239

17340
/// <summary>
17441
/// Switch to a specific namespace and database.
17542
/// </summary>
17643
/// <param name="db"> Switches to a specific namespace. </param>
17744
/// <param name="ns"> Switches to a specific database. </param>
178-
public Task<IResponse> Use(string db, string ns, CancellationToken ct = default);
45+
public Task<DriverResponse> Use(string db, string ns, CancellationToken ct = default);
17946

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

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

19562
/// <summary>
19663
/// Invalidates the authentication for the current connection.
19764
/// </summary>
19865
/// <remarks>
19966
/// This updates the internal <see cref="Config" />.
20067
/// </remarks>
201-
public Task<IResponse> Invalidate(CancellationToken ct = default);
68+
public Task<DriverResponse> Invalidate(CancellationToken ct = default);
20269

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

21279
/// <summary>
21380
/// Assigns a value as a parameter for this connection.
21481
/// </summary>
21582
/// <param name="key"> Specifies the name of the variable. </param>
21683
/// <param name="value"> Assigns the value to the variable name. </param>
217-
public Task<IResponse> Let(string key, object? value, CancellationToken ct = default);
84+
public Task<DriverResponse> Let(string key, object? value, CancellationToken ct = default);
21885

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)