Skip to content

Commit 699ac09

Browse files
a-random-stevestephenatsembitjeffrey-elliott
authored
User defined types, bm-25, various fixes (#26)
Co-authored-by: Stephen Hewitt <stephenh@sembit.com> Co-authored-by: jeffrey-elliott <jeffrey.elliott@gmail.com> Co-authored-by: Steve Hewitt <45011981+stephenatsembit@users.noreply.github.com>
1 parent 9b4ffd1 commit 699ac09

File tree

69 files changed

+6223
-1403
lines changed

Some content is hidden

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

69 files changed

+6223
-1403
lines changed

src/DataStax.AstraDB.DataApi/Admin/AstraDatabasesAdmin.cs

Lines changed: 74 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,39 @@ public async Task<List<string>> ListDatabaseNamesAsync(CommandOptions options)
106106
}
107107

108108
/// <summary>
109-
/// Returns a list of database info objects.
109+
/// Synchronous version of <see cref="ListDatabasesAsync()"/>
110110
/// </summary>
111-
/// <returns>A list of DatabaseInfo objects.</returns>
112-
/// <example>
113-
/// <code>
114-
/// var databases = admin.ListDatabases();
115-
/// </code>
116-
/// </example>
111+
/// <inheritdoc cref="ListDatabasesAsync()"/>
117112
public List<DatabaseInfo> ListDatabases()
118113
{
119-
return ListDatabasesAsync(null, true).ResultSync();
114+
return ListDatabases(null, null);
115+
}
116+
117+
/// <summary>
118+
/// Synchronous version of <see cref="ListDatabasesAsync(CommandOptions)"/>
119+
/// </summary>
120+
/// <inheritdoc cref="ListDatabasesAsync(CommandOptions)"/>
121+
public List<DatabaseInfo> ListDatabases(CommandOptions options)
122+
{
123+
return ListDatabases(null, options);
124+
}
125+
126+
/// <summary>
127+
/// Synchronous version of <see cref="ListDatabasesAsync(ListDatabaseOptions)"/>
128+
/// </summary>
129+
/// <inheritdoc cref="ListDatabasesAsync(ListDatabaseOptions)"/>
130+
public List<DatabaseInfo> ListDatabases(ListDatabaseOptions listOptions)
131+
{
132+
return ListDatabases(listOptions, null);
133+
}
134+
135+
/// <summary>
136+
/// Synchronous version of <see cref="ListDatabasesAsync(ListDatabaseOptions, CommandOptions)"/>
137+
/// </summary>
138+
/// <inheritdoc cref="ListDatabasesAsync(ListDatabaseOptions, CommandOptions)"/>
139+
public List<DatabaseInfo> ListDatabases(ListDatabaseOptions listOptions, CommandOptions options)
140+
{
141+
return ListDatabasesAsync(null, options, true).ResultSync();
120142
}
121143

122144
/// <summary>
@@ -130,44 +152,56 @@ public List<DatabaseInfo> ListDatabases()
130152
/// </example>
131153
public Task<List<DatabaseInfo>> ListDatabasesAsync()
132154
{
133-
return ListDatabasesAsync(null, false);
155+
return ListDatabasesAsync(null, null);
134156
}
135157

136158
/// <summary>
137-
/// Returns a list of database info objects using specified command options.
159+
/// Asynchronously returns a list of database info objects using specified command options.
138160
/// </summary>
139161
/// <param name="options">The command options to use.</param>
140-
/// <returns>A list of DatabaseInfo objects.</returns>
162+
/// <returns>A task that resolves to a list of DatabaseInfo objects.</returns>
141163
/// <example>
142164
/// <code>
143-
/// var databases = admin.ListDatabases(options);
165+
/// var databases = await admin.ListDatabasesAsync(options);
144166
/// </code>
145167
/// </example>
146-
public List<DatabaseInfo> ListDatabases(CommandOptions options)
168+
public Task<List<DatabaseInfo>> ListDatabasesAsync(CommandOptions options)
147169
{
148-
return ListDatabasesAsync(options, true).ResultSync();
170+
return ListDatabasesAsync(null, options, false);
149171
}
150172

151173
/// <summary>
152-
/// Asynchronously returns a list of database info objects using specified command options.
174+
/// Asynchronously returns a list of database info objects using specified filtering options
153175
/// </summary>
154-
/// <param name="options">The command options to use.</param>
155-
/// <returns>A task that resolves to a list of DatabaseInfo objects.</returns>
156-
/// <example>
157-
/// <code>
158-
/// var databases = await admin.ListDatabasesAsync(options);
159-
/// </code>
160-
/// </example>
161-
public Task<List<DatabaseInfo>> ListDatabasesAsync(CommandOptions options)
176+
/// <param name="listOptions"></param>
177+
/// <returns></returns>
178+
public Task<List<DatabaseInfo>> ListDatabasesAsync(ListDatabaseOptions listOptions)
162179
{
163-
return ListDatabasesAsync(options, false);
180+
return ListDatabasesAsync(listOptions, null, false);
164181
}
165182

166-
internal async Task<List<DatabaseInfo>> ListDatabasesAsync(CommandOptions options, bool runSynchronously)
183+
/// <summary>
184+
/// Asynchronously returns a list of database info objects using specified command options and filtering options
185+
/// </summary>
186+
/// <param name="options"></param>
187+
/// <param name="listOptions"></param>
188+
/// <returns></returns>
189+
public Task<List<DatabaseInfo>> ListDatabasesAsync(ListDatabaseOptions listOptions, CommandOptions options)
167190
{
191+
return ListDatabasesAsync(listOptions, options, false);
192+
}
193+
194+
internal async Task<List<DatabaseInfo>> ListDatabasesAsync(ListDatabaseOptions listOptions, CommandOptions options, bool runSynchronously)
195+
{
196+
if (listOptions == null)
197+
{
198+
listOptions = new ListDatabaseOptions();
199+
}
200+
168201
var command = CreateCommand()
169202
.AddUrlPath("databases")
170203
.WithTimeoutManager(new DatabaseAdminTimeoutManager())
204+
.WithPayload(listOptions)
171205
.AddCommandOptions(options);
172206

173207
var rawResults = await command.RunAsyncRaw<List<RawDatabaseInfo>>(HttpMethod.Get, runSynchronously).ConfigureAwait(false);
@@ -349,7 +383,7 @@ internal async Task<IDatabaseAdmin> CreateDatabaseAsync(DatabaseCreationOptions
349383
var databaseName = creationOptions.Name;
350384
Guard.NotNullOrEmpty(databaseName, nameof(databaseName));
351385

352-
List<DatabaseInfo> dbList = await ListDatabasesAsync(commandOptions, runSynchronously).ConfigureAwait(false);
386+
List<DatabaseInfo> dbList = await ListDatabasesAsync(null, commandOptions, runSynchronously).ConfigureAwait(false);
353387

354388
DatabaseInfo existingDb = dbList.FirstOrDefault(item => databaseName.Equals(item.Name));
355389

@@ -568,7 +602,7 @@ public Task<bool> DropDatabaseAsync(Guid dbGuid, CommandOptions options)
568602
internal async Task<bool> DropDatabaseAsync(string databaseName, CommandOptions options, bool runSynchronously)
569603
{
570604
Guard.NotNullOrEmpty(databaseName, nameof(databaseName));
571-
var dbList = await ListDatabasesAsync(options, runSynchronously).ConfigureAwait(false);
605+
var dbList = await ListDatabasesAsync(null, options, runSynchronously).ConfigureAwait(false);
572606

573607
var dbInfo = dbList.FirstOrDefault(item => item.Name.Equals(databaseName));
574608
if (dbInfo == null)
@@ -604,6 +638,19 @@ internal async Task<bool> DropDatabaseAsync(Guid dbGuid, CommandOptions options,
604638
return false;
605639
}
606640

641+
642+
/// <summary>
643+
/// Returns an IDatabaseAdmin instance for the database at the specified URL.
644+
/// </summary>
645+
/// <param name="dbUrl"></param>
646+
/// <returns></returns>
647+
public IDatabaseAdmin GetDatabaseAdmin(string dbUrl)
648+
{
649+
var database = _client.GetDatabase(dbUrl);
650+
return new DatabaseAdminAstra(database, _client, null);
651+
}
652+
653+
607654
/// <summary>
608655
/// Retrieves database information for the specified GUID.
609656
/// </summary>

src/DataStax.AstraDB.DataApi/Admin/DatabaseAdminAstra.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ public Task DropKeyspaceAsync(string keyspace)
393393
}
394394

395395
/// <inheritdoc cref="DropKeyspaceAsync(string)"/>
396+
/// <param name="keyspace"></param>
396397
/// <param name="waitForCompletion">Whether or not to wait for the keyspace to be dropped before returning.</param>
397398
/// <example>
398399
/// <code>
@@ -405,8 +406,8 @@ public Task DropKeyspaceAsync(string keyspace, bool waitForCompletion)
405406
}
406407

407408
/// <inheritdoc cref="DropKeyspaceAsync(string)"/>
409+
/// <param name="keyspace"></param>
408410
/// <param name="options">Optional settings that influence request execution.</param>
409-
410411
/// <example>
411412
/// <code>
412413
/// await admin.DropKeyspaceAsync("myKeyspace", options);
@@ -422,7 +423,9 @@ public Task DropKeyspaceAsync(string keyspace, CommandOptions options)
422423
}
423424

424425
/// <inheritdoc cref="DropKeyspaceAsync(string, CommandOptions)"/>
426+
/// <param name="keyspace"></param>
425427
/// <param name="waitForCompletion">Whether or not to wait for the keyspace to be dropped before returning.</param>
428+
/// <param name="options"></param>
426429
/// <example>
427430
/// <code>
428431
/// await admin.DropKeyspaceAsync("myKeyspace", true, options);

src/DataStax.AstraDB.DataApi/Admin/DatabaseCreationOptions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public class DatabaseCreationOptions
3434
public string Keyspace { get; set; } = Database.DefaultKeyspace;
3535

3636
[JsonPropertyName("capacityUnits")]
37-
public int CapacityUnits { get; set; } = 1;
37+
internal int CapacityUnits { get; set; } = 1;
3838

3939
[JsonPropertyName("tier")]
40-
public string Tier { get; set; } = "serverless";
40+
internal string Tier { get; set; } = "serverless";
4141

4242
[JsonPropertyName("dbType")]
43-
public string DatabaseType { get; set; } = "vector";
43+
internal string DatabaseType { get; set; } = "vector";
4444
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright DataStax, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using DataStax.AstraDB.DataApi.Core;
18+
using System.Text.Json.Serialization;
19+
20+
namespace DataStax.AstraDB.DataApi.Admin;
21+
22+
/// <summary>
23+
/// Options used for ListDatabasesAsync.
24+
/// </summary>
25+
public class ListDatabaseOptions
26+
{
27+
/// <summary>
28+
/// Filter databases based on specific states.
29+
/// </summary>
30+
[JsonPropertyName("include")]
31+
public QueryDatabaseStates StatesToInclude { get; set; } = QueryDatabaseStates.nonterminated;
32+
33+
/// <summary>
34+
/// Filter databases based on cloud provider.
35+
/// </summary>
36+
[JsonPropertyName("cloudProvider")]
37+
public QueryCloudProvider Provider { get; set; } = QueryCloudProvider.ALL;
38+
39+
/// <summary>
40+
/// See <see cref="PageSizeLimit"/>. If getting an additional page of data, pass in the id of the last database in the previous page.
41+
/// </summary>
42+
[JsonPropertyName("starting_after")]
43+
internal string StartingAfter { get; set; }
44+
45+
/// <summary>
46+
/// Number of items to return "per page".
47+
/// </summary>
48+
[JsonPropertyName("limit")]
49+
public int PageSizeLimit = 100;
50+
}
51+
52+
public enum QueryDatabaseStates
53+
{
54+
nonterminated,
55+
all,
56+
active,
57+
pending,
58+
preparing,
59+
prepared,
60+
initializing,
61+
parked,
62+
parking,
63+
unparking,
64+
terminating,
65+
terminated,
66+
resizing,
67+
error,
68+
maintenance,
69+
suspended,
70+
suspending
71+
}
72+
73+
public enum QueryCloudProvider
74+
{
75+
ALL,
76+
AWS,
77+
GCP,
78+
AZURE
79+
}

0 commit comments

Comments
 (0)