Skip to content

Commit

Permalink
Container: Add a database reference to the container (#1457)
Browse files Browse the repository at this point in the history
* Make database reference public

* Adding client to the database

* Updated contract
  • Loading branch information
j82w committed May 1, 2020
1 parent 45e5f91 commit 6f0d69c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Microsoft.Azure.Cosmos/src/Resource/Container/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public abstract class Container
/// </summary>
public abstract string Id { get; }

/// <summary>
/// Returns the parent Database reference
/// </summary>
public abstract Database Database { get; }

/// <summary>
/// Returns the conflicts
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ namespace Microsoft.Azure.Cosmos

internal abstract class ContainerInternal : Container
{
public abstract Database Database { get; }

internal abstract Uri LinkUri { get; }

internal abstract CosmosClientContext ClientContext { get; }
Expand Down
7 changes: 6 additions & 1 deletion Microsoft.Azure.Cosmos/src/Resource/Database/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.Azure.Cosmos
/// <summary>
/// Operations for reading or deleting an existing database.
///
/// See <see cref="CosmosClient"/> for creating new databases, and reading/querying all databases; use `client.Databases`.
/// See <see cref="Client"/> for creating new databases, and reading/querying all databases; use `client.Databases`.
/// </summary>
/// <remarks>
/// Note: all these operations make calls against a fixed budget.
Expand All @@ -27,6 +27,11 @@ public abstract class Database
/// </summary>
public abstract string Id { get; }

/// <summary>
/// The parent Cosmos client instance related the database instance
/// </summary>
public abstract CosmosClient Client { get; }

/// <summary>
/// Reads a <see cref="DatabaseProperties"/> from the Azure Cosmos service as an asynchronous operation.
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.Azure.Cosmos
/// <summary>
/// Operations for reading or deleting an existing database.
///
/// <see cref="CosmosClient"/> for or creating new databases, and reading/querying all databases; use `client.Databases`.
/// <see cref="Client"/> for or creating new databases, and reading/querying all databases; use `client.Databases`.
/// </summary>
internal class DatabaseCore : DatabaseInternal
{
Expand All @@ -34,6 +34,8 @@ protected DatabaseCore(

public override string Id { get; }

public override CosmosClient Client => this.ClientContext.Client;

internal override Uri LinkUri { get; }

internal override CosmosClientContext ClientContext { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public async Task Cleanup()
await base.TestCleanup();
}

[TestMethod]
public void ParentResourceTest()
{
Assert.AreEqual(this.database, this.Container.Database);
Assert.AreEqual(this.cosmosClient, this.Container.Database.Client);
}

[TestMethod]
public async Task CreateDropItemTest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,16 @@
"Attributes": [],
"MethodInfo": null
},
"Microsoft.Azure.Cosmos.Database Database": {
"Type": "Property",
"Attributes": [],
"MethodInfo": null
},
"Microsoft.Azure.Cosmos.Database get_Database()": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.Database get_Database()"
},
"Microsoft.Azure.Cosmos.FeedIterator GetItemQueryStreamIterator(Microsoft.Azure.Cosmos.QueryDefinition, System.String, Microsoft.Azure.Cosmos.QueryRequestOptions)": {
"Type": "Method",
"Attributes": [],
Expand Down Expand Up @@ -2015,6 +2025,16 @@
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.Container GetContainer(System.String)"
},
"Microsoft.Azure.Cosmos.CosmosClient Client": {
"Type": "Property",
"Attributes": [],
"MethodInfo": null
},
"Microsoft.Azure.Cosmos.CosmosClient get_Client()": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.CosmosClient get_Client()"
},
"Microsoft.Azure.Cosmos.FeedIterator GetContainerQueryStreamIterator(Microsoft.Azure.Cosmos.QueryDefinition, System.String, Microsoft.Azure.Cosmos.QueryRequestOptions)": {
"Type": "Method",
"Attributes": [],
Expand Down

0 comments on commit 6f0d69c

Please sign in to comment.