pub struct CosmosClient { /* private fields */ }
Expand description
Client for Azure Cosmos DB.
Implementations§
Source§impl CosmosClient
impl CosmosClient
Sourcepub fn new(
endpoint: &str,
credential: Arc<dyn TokenCredential>,
options: Option<CosmosClientOptions>,
) -> Result<Self>
pub fn new( endpoint: &str, credential: Arc<dyn TokenCredential>, options: Option<CosmosClientOptions>, ) -> Result<Self>
Creates a new CosmosClient, using Entra ID authentication.
§Arguments
endpoint
- The full URL of the Cosmos DB account, for examplehttps://myaccount.documents.azure.com/
.credential
- An implementation ofTokenCredential
that can provide an Entra ID token to use when authenticating.options
- Optional configuration for the client.
§Examples
use azure_data_cosmos::CosmosClient;
let credential = azure_identity::DefaultAzureCredential::new().unwrap();
let client = CosmosClient::new("https://myaccount.documents.azure.com/", credential, None).unwrap();
Sourcepub fn with_key(
endpoint: &str,
key: Secret,
options: Option<CosmosClientOptions>,
) -> Result<Self>
Available on crate feature key_auth
only.
pub fn with_key( endpoint: &str, key: Secret, options: Option<CosmosClientOptions>, ) -> Result<Self>
key_auth
only.Creates a new CosmosClient, using key authentication.
§Arguments
endpoint
- The full URL of the Cosmos DB account, for examplehttps://myaccount.documents.azure.com/
.key
- The key to use when authenticating.options
- Optional configuration for the client.
§Examples
use azure_data_cosmos::CosmosClient;
use azure_core::credentials::Secret;
let client = CosmosClient::with_key("https://myaccount.documents.azure.com/", Secret::from("my_key"), None).unwrap();
Sourcepub fn with_connection_string(
connection_string: Secret,
options: Option<CosmosClientOptions>,
) -> Result<Self, Error>
Available on crate feature key_auth
only.
pub fn with_connection_string( connection_string: Secret, options: Option<CosmosClientOptions>, ) -> Result<Self, Error>
key_auth
only.Creates a new CosmosClient, using a connection string.
§Arguments
connection_string
- the connection string to use for the client, e.g.AccountEndpoint=https://accountname.documents.azure.com:443/;AccountKey=accountkey
options
- Optional configuration for the client.
§Examples
use azure_data_cosmos::CosmosClient;
use azure_core::credentials::Secret;
let client = CosmosClient::with_connection_string(
"AccountEndpoint=https://accountname.documents.azure.com:443/;AccountKey=accountkey",
None)
.unwrap();
Sourcepub fn database_client(&self, id: &str) -> DatabaseClient
pub fn database_client(&self, id: &str) -> DatabaseClient
Gets a DatabaseClient
that can be used to access the database with the specified ID.
§Arguments
id
- The ID of the database.
Sourcepub fn endpoint(&self) -> &Url
pub fn endpoint(&self) -> &Url
Gets the endpoint of the database account this client is connected to.
Sourcepub fn query_databases(
&self,
query: impl Into<Query>,
options: Option<QueryDatabasesOptions<'_>>,
) -> Result<FeedPager<DatabaseProperties>>
pub fn query_databases( &self, query: impl Into<Query>, options: Option<QueryDatabasesOptions<'_>>, ) -> Result<FeedPager<DatabaseProperties>>
Executes a query against databases in the account.
§Arguments
query
- The query to execute.options
- Optional parameters for the request.
§Examples
The query
parameter accepts anything that can be transformed Into
a Query
.
This allows simple queries without parameters to be expressed easily:
let dbs = client.query_databases(
"SELECT * FROM dbs",
None)?;
See Query
for more information on how to specify a query.
Sourcepub async fn create_database(
&self,
id: &str,
options: Option<CreateDatabaseOptions<'_>>,
) -> Result<Response<DatabaseProperties>>
pub async fn create_database( &self, id: &str, options: Option<CreateDatabaseOptions<'_>>, ) -> Result<Response<DatabaseProperties>>
Creates a new database.
This is a control-plane API and requires that you authenticate using a key. To use Entra ID to perform this operation, you must use the Azure Resource Manager APIs.
§Arguments
id
- The ID of the new database.options
- Optional parameters for the request.
Trait Implementations§
Source§impl Clone for CosmosClient
impl Clone for CosmosClient
Source§fn clone(&self) -> CosmosClient
fn clone(&self) -> CosmosClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more