-
Notifications
You must be signed in to change notification settings - Fork 28
/
IDatabaseApi.cs
165 lines (147 loc) · 8.54 KB
/
IDatabaseApi.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
namespace DreamFactory.Api
{
using System.Collections.Generic;
using System.Threading.Tasks;
using DreamFactory.Model;
using DreamFactory.Model.Database;
/// <summary>
/// Represents /db API.
/// </summary>
public interface IDatabaseApi
{
/// <summary>
/// List all role accessible components.
/// </summary>
/// <returns>List of accessible resource names for the user's role.</returns>
Task<IEnumerable<TableInfo>> GetAccessComponentsAsync();
/// <summary>
/// List the table names in this storage.
/// </summary>
/// <param name="includeSchemas">Also return the names of the tables where the schema is retrievable.</param>
/// <param name="refresh">Refresh any cached copy of the resource list.</param>
/// <returns>Table names.</returns>
Task<IEnumerable<TableInfo>> GetTableNamesAsync(bool includeSchemas = false, bool refresh = false);
/// <summary>
/// Creates a new table schema.
/// </summary>
/// <param name="tableSchema">Table schema.</param>
Task<bool> CreateTableAsync(TableSchema tableSchema);
/// <summary>
/// Updates the existing table schema.
/// </summary>
/// <param name="tableSchema">Table schema.</param>
Task<bool> UpdateTableAsync(TableSchema tableSchema);
/// <summary>
/// Deletes the specified table (aka drop).
/// </summary>
/// <param name="tableName">Name of the table.</param>
/// <returns>Flag indicating deletion status.</returns>
Task<bool> DeleteTableAsync(string tableName);
/// <summary>
/// Retrieve table definition for the given table.
/// </summary>
/// <param name="tableName">Name of the table.</param>
/// <param name="refresh">Refresh any cached copy of the schema.</param>
/// <returns>Table schema model.</returns>
Task<TableSchema> DescribeTableAsync(string tableName, bool refresh = false);
/// <summary>
/// Retrieve table definition for the given table.
/// </summary>
/// <param name="tableName">Name of the table.</param>
/// <param name="fieldName">Name of the field.</param>
/// <param name="refresh">Refresh any cached copy of the schema.</param>
/// <returns>Table schema model.</returns>
Task<FieldSchema> DescribeFieldAsync(string tableName, string fieldName, bool refresh = false);
/// <summary>
/// Create records in the specified table.
/// </summary>
/// <param name="tableName">Name of the table.</param>
/// <param name="records">Records to add.</param>
/// <param name="query">SQL query to return created records.</param>
/// <typeparam name="TRecord">Type of the records.</typeparam>
/// <returns>Sequence of created records and metadata if specified in query.</returns>
Task<DatabaseResourceWrapper<TRecord>> CreateRecordsAsync<TRecord>(string tableName, IEnumerable<TRecord> records, SqlQuery query);
/// <summary>
/// Update records in the specified table.
/// </summary>
/// <param name="tableName">Name of the table.</param>
/// <param name="records">Records to update.</param>
/// <param name="query">SQL query to return created records.</param>
/// <typeparam name="TRecord">Type of the records.</typeparam>
/// <returns>Sequence of updated records and metadata if specified in query.</returns>
Task<DatabaseResourceWrapper<TRecord>> UpdateRecordsAsync<TRecord>(string tableName, IEnumerable<TRecord> records, SqlQuery query);
/// <summary>
/// Get table records by filter.
/// </summary>
/// <param name="tableName">Name of the table.</param>
/// <param name="query">See <see cref="SqlQuery"/> class.</param>
/// <typeparam name="TRecord">Type of the records.</typeparam>
/// <returns>Sequence of queried records and metadata if specified in query.</returns>
Task<DatabaseResourceWrapper<TRecord>> GetRecordsAsync<TRecord>(string tableName, SqlQuery query);
/// <summary>
/// Delete one or more records.
/// </summary>
/// <param name="tableName">Name of the table.</param>
/// <param name="records">Records to delete.</param>
/// <param name="query">SQL query to return created records.</param>
/// <typeparam name="TRecord">Type of the records.</typeparam>
/// <returns>Sequence of deleted records and metadata if specified in query.</returns>
Task<DatabaseResourceWrapper<TRecord>> DeleteRecordsAsync<TRecord>(string tableName, IEnumerable<TRecord> records, SqlQuery query);
/// <summary>
/// List callable stored procedures.
/// </summary>
/// <param name="refresh">Refresh any cached copy of the resource list.</param>
/// <returns>Names of the available stored procedures on this database.</returns>
Task<IEnumerable<string>> GetStoredProcNamesAsync(bool refresh = false);
/// <summary>
/// Call a stored procedure, ignoring its output.
/// </summary>
/// <param name="procedureName">Name of the stored procedure to call.</param>
/// <param name="parameters">Optional stored procedure parameters.</param>
Task CallStoredProcAsync(string procedureName, params StoredProcParam[] parameters);
/// <summary>
/// Call a stored procedure with response of type <typeparamref name="TStoredProcResponse"/>.
/// </summary>
/// <param name="procedureName">Name of the stored procedure to call.</param>
/// <param name="parameters">Optional stored procedure parameters.</param>
/// <typeparam name="TStoredProcResponse">Type of the response.</typeparam>
/// <returns>Stored procedure response data.</returns>
Task<TStoredProcResponse> CallStoredProcAsync<TStoredProcResponse>(string procedureName, params StoredProcParam[] parameters)
where TStoredProcResponse : class, new();
/// <summary>
/// Call a stored procedure with response of type <typeparamref name="TStoredProcResponse"/>.
/// </summary>
/// <param name="procedureName">Name of the stored procedure to call.</param>
/// <param name="wrapper">Name of a field in TStoredProcResponse receiving returned dataset.</param>
/// <param name="parameters">Optional stored procedure parameters.</param>
/// <typeparam name="TStoredProcResponse">Type of the response.</typeparam>
/// <returns>Stored procedure response data.</returns>
Task<TStoredProcResponse> CallStoredProcAsync<TStoredProcResponse>(string procedureName, string wrapper, params StoredProcParam[] parameters)
where TStoredProcResponse : class, new();
/// <summary>
/// List callable stored functions.
/// </summary>
/// <param name="refresh">Refresh any cached copy of the resource list.</param>
/// <returns>Names of the available stored functions on this database.</returns>
Task<IEnumerable<string>> GetStoredFuncNamesAsync(bool refresh = false);
/// <summary>
/// Call a stored function with response of type <typeparamref name="TStoredFuncResponse"/>.
/// </summary>
/// <param name="functionName">Name of the stored function to call.</param>
/// <param name="parameters">Optional stored function parameters.</param>
/// <typeparam name="TStoredFuncResponse">Type of the response.</typeparam>
/// <returns>Stored procedure response data.</returns>
Task<TStoredFuncResponse> CallStoredFuncAsync<TStoredFuncResponse>(string functionName, params StoredProcParam[] parameters)
where TStoredFuncResponse : class, new();
/// <summary>
/// Call a stored function with response of type <typeparamref name="TStoredFuncResponse"/>.
/// </summary>
/// <param name="functionName">Name of the stored function to call.</param>
/// <param name="wrapper">Name of a field in TStoredFuncResponse receiving returned dataset.</param>
/// <param name="parameters">Optional stored function parameters.</param>
/// <typeparam name="TStoredFuncResponse">Type of the response.</typeparam>
/// <returns>Stored function response data.</returns>
Task<TStoredFuncResponse> CallStoredFuncAsync<TStoredFuncResponse>(string functionName, string wrapper, params StoredProcParam[] parameters)
where TStoredFuncResponse : class, new();
}
}