use crate::client::Client;
use reqwest::Method;
use serde_json::json;
use std::collections::HashMap;
#[derive(Debug, Clone)]
pub struct Mysql {
client: Client,
}
impl Mysql {
pub fn new(client: &Client) -> Self {
Self {
client: client.clone(),
}
}
pub fn client(&self) -> &Client {
&self.client
}
pub async fn list(
&self,
queries: Option<Vec<String>>,
) -> crate::error::Result<crate::models::DedicatedDatabaseList> {
let mut params = HashMap::new();
if let Some(value) = queries {
params.insert(
"queries".to_string(),
json!(value.into_iter().map(|s| s.into()).collect::<Vec<String>>()),
);
}
let mut api_headers = HashMap::new();
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql".to_string();
self.client
.call(Method::GET, &path, Some(api_headers), Some(params))
.await
}
#[allow(clippy::too_many_arguments)]
pub async fn create(
&self,
database_id: impl Into<String>,
name: impl Into<String>,
version: Option<&str>,
specification: Option<&str>,
replicas: Option<i64>,
sync_mode: Option<&str>,
network_idle_timeout_seconds: Option<i64>,
network_ip_allowlist: Option<Vec<String>>,
idle_timeout_minutes: Option<i64>,
pitr: Option<bool>,
pitr_retention_days: Option<i64>,
storage_autoscaling: Option<bool>,
storage_autoscaling_threshold_percent: Option<i64>,
storage_autoscaling_max_gb: Option<i64>,
) -> crate::error::Result<crate::models::DedicatedDatabase> {
let mut params = HashMap::new();
params.insert("databaseId".to_string(), json!(database_id.into()));
params.insert("name".to_string(), json!(name.into()));
if let Some(value) = version {
params.insert("version".to_string(), json!(value));
}
if let Some(value) = specification {
params.insert("specification".to_string(), json!(value));
}
if let Some(value) = replicas {
params.insert("replicas".to_string(), json!(value));
}
if let Some(value) = sync_mode {
params.insert("syncMode".to_string(), json!(value));
}
if let Some(value) = network_idle_timeout_seconds {
params.insert("networkIdleTimeoutSeconds".to_string(), json!(value));
}
if let Some(value) = network_ip_allowlist {
params.insert(
"networkIPAllowlist".to_string(),
json!(value.into_iter().map(|s| s.into()).collect::<Vec<String>>()),
);
}
if let Some(value) = idle_timeout_minutes {
params.insert("idleTimeoutMinutes".to_string(), json!(value));
}
if let Some(value) = pitr {
params.insert("pitr".to_string(), json!(value));
}
if let Some(value) = pitr_retention_days {
params.insert("pitrRetentionDays".to_string(), json!(value));
}
if let Some(value) = storage_autoscaling {
params.insert("storageAutoscaling".to_string(), json!(value));
}
if let Some(value) = storage_autoscaling_threshold_percent {
params.insert(
"storageAutoscalingThresholdPercent".to_string(),
json!(value),
);
}
if let Some(value) = storage_autoscaling_max_gb {
params.insert("storageAutoscalingMaxGb".to_string(), json!(value));
}
let mut api_headers = HashMap::new();
api_headers.insert("content-type".to_string(), "application/json".to_string());
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql".to_string();
self.client
.call(Method::POST, &path, Some(api_headers), Some(params))
.await
}
pub async fn list_specifications(
&self,
) -> crate::error::Result<crate::models::DedicatedDatabaseSpecificationList> {
let params = HashMap::new();
let mut api_headers = HashMap::new();
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/specifications".to_string();
self.client
.call(Method::GET, &path, Some(api_headers), Some(params))
.await
}
pub async fn get(
&self,
database_id: impl Into<String>,
) -> crate::error::Result<crate::models::DedicatedDatabase> {
let params = HashMap::new();
let mut api_headers = HashMap::new();
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::GET, &path, Some(api_headers), Some(params))
.await
}
#[allow(clippy::too_many_arguments)]
pub async fn update(
&self,
database_id: impl Into<String>,
name: Option<&str>,
status: Option<&str>,
specification: Option<&str>,
replicas: Option<i64>,
sync_mode: Option<&str>,
network_idle_timeout_seconds: Option<i64>,
network_ip_allowlist: Option<Vec<String>>,
idle_timeout_minutes: Option<i64>,
pitr: Option<bool>,
pitr_retention_days: Option<i64>,
storage_autoscaling: Option<bool>,
storage_autoscaling_threshold_percent: Option<i64>,
storage_autoscaling_max_gb: Option<i64>,
metrics_trace_sample_rate: Option<f64>,
metrics_slow_query_log_threshold_ms: Option<i64>,
sql_api_enabled: Option<bool>,
sql_api_allowed_statements: Option<Vec<String>>,
sql_api_max_rows: Option<i64>,
sql_api_max_bytes: Option<i64>,
sql_api_timeout_seconds: Option<i64>,
) -> crate::error::Result<crate::models::DedicatedDatabase> {
let mut params = HashMap::new();
if let Some(value) = name {
params.insert("name".to_string(), json!(value));
}
if let Some(value) = status {
params.insert("status".to_string(), json!(value));
}
if let Some(value) = specification {
params.insert("specification".to_string(), json!(value));
}
if let Some(value) = replicas {
params.insert("replicas".to_string(), json!(value));
}
if let Some(value) = sync_mode {
params.insert("syncMode".to_string(), json!(value));
}
if let Some(value) = network_idle_timeout_seconds {
params.insert("networkIdleTimeoutSeconds".to_string(), json!(value));
}
if let Some(value) = network_ip_allowlist {
params.insert(
"networkIPAllowlist".to_string(),
json!(value.into_iter().map(|s| s.into()).collect::<Vec<String>>()),
);
}
if let Some(value) = idle_timeout_minutes {
params.insert("idleTimeoutMinutes".to_string(), json!(value));
}
if let Some(value) = pitr {
params.insert("pitr".to_string(), json!(value));
}
if let Some(value) = pitr_retention_days {
params.insert("pitrRetentionDays".to_string(), json!(value));
}
if let Some(value) = storage_autoscaling {
params.insert("storageAutoscaling".to_string(), json!(value));
}
if let Some(value) = storage_autoscaling_threshold_percent {
params.insert(
"storageAutoscalingThresholdPercent".to_string(),
json!(value),
);
}
if let Some(value) = storage_autoscaling_max_gb {
params.insert("storageAutoscalingMaxGb".to_string(), json!(value));
}
if let Some(value) = metrics_trace_sample_rate {
params.insert("metricsTraceSampleRate".to_string(), json!(value));
}
if let Some(value) = metrics_slow_query_log_threshold_ms {
params.insert("metricsSlowQueryLogThresholdMs".to_string(), json!(value));
}
if let Some(value) = sql_api_enabled {
params.insert("sqlApiEnabled".to_string(), json!(value));
}
if let Some(value) = sql_api_allowed_statements {
params.insert(
"sqlApiAllowedStatements".to_string(),
json!(value.into_iter().map(|s| s.into()).collect::<Vec<String>>()),
);
}
if let Some(value) = sql_api_max_rows {
params.insert("sqlApiMaxRows".to_string(), json!(value));
}
if let Some(value) = sql_api_max_bytes {
params.insert("sqlApiMaxBytes".to_string(), json!(value));
}
if let Some(value) = sql_api_timeout_seconds {
params.insert("sqlApiTimeoutSeconds".to_string(), json!(value));
}
let mut api_headers = HashMap::new();
api_headers.insert("content-type".to_string(), "application/json".to_string());
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::PATCH, &path, Some(api_headers), Some(params))
.await
}
pub async fn delete(
&self,
database_id: impl Into<String>,
) -> crate::error::Result<serde_json::Value> {
let params = HashMap::new();
let mut api_headers = HashMap::new();
api_headers.insert("content-type".to_string(), "application/json".to_string());
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::DELETE, &path, Some(api_headers), Some(params))
.await
}
pub async fn list_backups(
&self,
database_id: impl Into<String>,
queries: Option<Vec<String>>,
) -> crate::error::Result<crate::models::DedicatedDatabaseBackupList> {
let mut params = HashMap::new();
if let Some(value) = queries {
params.insert(
"queries".to_string(),
json!(value.into_iter().map(|s| s.into()).collect::<Vec<String>>()),
);
}
let mut api_headers = HashMap::new();
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/backups"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::GET, &path, Some(api_headers), Some(params))
.await
}
pub async fn create_backup(
&self,
database_id: impl Into<String>,
r#type: Option<&str>,
) -> crate::error::Result<crate::models::DedicatedDatabaseBackup> {
let mut params = HashMap::new();
if let Some(value) = r#type {
params.insert("type".to_string(), json!(value));
}
let mut api_headers = HashMap::new();
api_headers.insert("content-type".to_string(), "application/json".to_string());
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/backups"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::POST, &path, Some(api_headers), Some(params))
.await
}
pub async fn list_backup_policies(
&self,
database_id: impl Into<String>,
queries: Option<Vec<String>>,
) -> crate::error::Result<crate::models::BackupPolicyList> {
let mut params = HashMap::new();
if let Some(value) = queries {
params.insert(
"queries".to_string(),
json!(value.into_iter().map(|s| s.into()).collect::<Vec<String>>()),
);
}
let mut api_headers = HashMap::new();
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/backups/policies"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::GET, &path, Some(api_headers), Some(params))
.await
}
#[allow(clippy::too_many_arguments)]
pub async fn create_backup_policy(
&self,
database_id: impl Into<String>,
policy_id: impl Into<String>,
name: impl Into<String>,
schedule: impl Into<String>,
retention: i64,
r#type: Option<&str>,
enabled: Option<bool>,
) -> crate::error::Result<crate::models::BackupPolicy> {
let mut params = HashMap::new();
params.insert("policyId".to_string(), json!(policy_id.into()));
params.insert("name".to_string(), json!(name.into()));
params.insert("schedule".to_string(), json!(schedule.into()));
params.insert("retention".to_string(), json!(retention));
if let Some(value) = r#type {
params.insert("type".to_string(), json!(value));
}
if let Some(value) = enabled {
params.insert("enabled".to_string(), json!(value));
}
let mut api_headers = HashMap::new();
api_headers.insert("content-type".to_string(), "application/json".to_string());
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/backups/policies"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::POST, &path, Some(api_headers), Some(params))
.await
}
pub async fn get_backup_policy(
&self,
database_id: impl Into<String>,
policy_id: impl Into<String>,
) -> crate::error::Result<crate::models::BackupPolicy> {
let params = HashMap::new();
let mut api_headers = HashMap::new();
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/backups/policies/{policyId}"
.to_string()
.replace("{databaseId}", &database_id.into().to_string())
.replace("{policyId}", &policy_id.into().to_string());
self.client
.call(Method::GET, &path, Some(api_headers), Some(params))
.await
}
pub async fn update_backup_policy(
&self,
database_id: impl Into<String>,
policy_id: impl Into<String>,
name: Option<&str>,
schedule: Option<&str>,
retention: Option<i64>,
enabled: Option<bool>,
) -> crate::error::Result<crate::models::BackupPolicy> {
let mut params = HashMap::new();
if let Some(value) = name {
params.insert("name".to_string(), json!(value));
}
if let Some(value) = schedule {
params.insert("schedule".to_string(), json!(value));
}
if let Some(value) = retention {
params.insert("retention".to_string(), json!(value));
}
if let Some(value) = enabled {
params.insert("enabled".to_string(), json!(value));
}
let mut api_headers = HashMap::new();
api_headers.insert("content-type".to_string(), "application/json".to_string());
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/backups/policies/{policyId}"
.to_string()
.replace("{databaseId}", &database_id.into().to_string())
.replace("{policyId}", &policy_id.into().to_string());
self.client
.call(Method::PATCH, &path, Some(api_headers), Some(params))
.await
}
pub async fn delete_backup_policy(
&self,
database_id: impl Into<String>,
policy_id: impl Into<String>,
) -> crate::error::Result<serde_json::Value> {
let params = HashMap::new();
let mut api_headers = HashMap::new();
api_headers.insert("content-type".to_string(), "application/json".to_string());
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/backups/policies/{policyId}"
.to_string()
.replace("{databaseId}", &database_id.into().to_string())
.replace("{policyId}", &policy_id.into().to_string());
self.client
.call(Method::DELETE, &path, Some(api_headers), Some(params))
.await
}
#[allow(clippy::too_many_arguments)]
pub async fn update_backup_storage(
&self,
database_id: impl Into<String>,
provider: impl Into<String>,
bucket: impl Into<String>,
access_key: impl Into<String>,
secret_key: impl Into<String>,
region: Option<&str>,
prefix: Option<&str>,
endpoint: Option<&str>,
) -> crate::error::Result<crate::models::DedicatedDatabaseBackupStorage> {
let mut params = HashMap::new();
params.insert("provider".to_string(), json!(provider.into()));
params.insert("bucket".to_string(), json!(bucket.into()));
if let Some(value) = region {
params.insert("region".to_string(), json!(value));
}
if let Some(value) = prefix {
params.insert("prefix".to_string(), json!(value));
}
if let Some(value) = endpoint {
params.insert("endpoint".to_string(), json!(value));
}
params.insert("accessKey".to_string(), json!(access_key.into()));
params.insert("secretKey".to_string(), json!(secret_key.into()));
let mut api_headers = HashMap::new();
api_headers.insert("content-type".to_string(), "application/json".to_string());
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/backups/storage"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::PUT, &path, Some(api_headers), Some(params))
.await
}
pub async fn get_backup(
&self,
database_id: impl Into<String>,
backup_id: impl Into<String>,
) -> crate::error::Result<crate::models::DedicatedDatabaseBackup> {
let params = HashMap::new();
let mut api_headers = HashMap::new();
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/backups/{backupId}"
.to_string()
.replace("{databaseId}", &database_id.into().to_string())
.replace("{backupId}", &backup_id.into().to_string());
self.client
.call(Method::GET, &path, Some(api_headers), Some(params))
.await
}
pub async fn delete_backup(
&self,
database_id: impl Into<String>,
backup_id: impl Into<String>,
) -> crate::error::Result<serde_json::Value> {
let params = HashMap::new();
let mut api_headers = HashMap::new();
api_headers.insert("content-type".to_string(), "application/json".to_string());
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/backups/{backupId}"
.to_string()
.replace("{databaseId}", &database_id.into().to_string())
.replace("{backupId}", &backup_id.into().to_string());
self.client
.call(Method::DELETE, &path, Some(api_headers), Some(params))
.await
}
pub async fn list_branches(
&self,
database_id: impl Into<String>,
) -> crate::error::Result<crate::models::DedicatedDatabaseBranchList> {
let params = HashMap::new();
let mut api_headers = HashMap::new();
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/branches"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::GET, &path, Some(api_headers), Some(params))
.await
}
pub async fn create_branch(
&self,
database_id: impl Into<String>,
branch_id: Option<&str>,
ttl: Option<i64>,
) -> crate::error::Result<crate::models::DedicatedDatabase> {
let mut params = HashMap::new();
if let Some(value) = branch_id {
params.insert("branchId".to_string(), json!(value));
}
if let Some(value) = ttl {
params.insert("ttl".to_string(), json!(value));
}
let mut api_headers = HashMap::new();
api_headers.insert("content-type".to_string(), "application/json".to_string());
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/branches"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::POST, &path, Some(api_headers), Some(params))
.await
}
pub async fn delete_branch(
&self,
database_id: impl Into<String>,
branch_id: impl Into<String>,
) -> crate::error::Result<crate::models::DedicatedDatabase> {
let params = HashMap::new();
let mut api_headers = HashMap::new();
api_headers.insert("content-type".to_string(), "application/json".to_string());
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/branches/{branchId}"
.to_string()
.replace("{databaseId}", &database_id.into().to_string())
.replace("{branchId}", &branch_id.into().to_string());
self.client
.call(Method::DELETE, &path, Some(api_headers), Some(params))
.await
}
pub async fn update_credentials(
&self,
database_id: impl Into<String>,
) -> crate::error::Result<crate::models::DedicatedDatabase> {
let params = HashMap::new();
let mut api_headers = HashMap::new();
api_headers.insert("content-type".to_string(), "application/json".to_string());
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/credentials"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::PATCH, &path, Some(api_headers), Some(params))
.await
}
pub async fn create_execution(
&self,
database_id: impl Into<String>,
sql: impl Into<String>,
bindings: Option<serde_json::Value>,
timeout_seconds: Option<i64>,
) -> crate::error::Result<crate::models::DedicatedDatabaseExecution> {
let mut params = HashMap::new();
params.insert("sql".to_string(), json!(sql.into()));
if let Some(value) = bindings {
params.insert("bindings".to_string(), json!(value));
}
if let Some(value) = timeout_seconds {
params.insert("timeoutSeconds".to_string(), json!(value));
}
let mut api_headers = HashMap::new();
api_headers.insert("content-type".to_string(), "application/json".to_string());
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/executions"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::POST, &path, Some(api_headers), Some(params))
.await
}
pub async fn create_failover(
&self,
database_id: impl Into<String>,
target_replica_id: Option<&str>,
) -> crate::error::Result<crate::models::DedicatedDatabase> {
let mut params = HashMap::new();
if let Some(value) = target_replica_id {
params.insert("targetReplicaId".to_string(), json!(value));
}
let mut api_headers = HashMap::new();
api_headers.insert("content-type".to_string(), "application/json".to_string());
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/failovers"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::POST, &path, Some(api_headers), Some(params))
.await
}
pub async fn update_maintenance(
&self,
database_id: impl Into<String>,
day: impl Into<String>,
hour_utc: i64,
) -> crate::error::Result<crate::models::DedicatedDatabase> {
let mut params = HashMap::new();
params.insert("day".to_string(), json!(day.into()));
params.insert("hourUtc".to_string(), json!(hour_utc));
let mut api_headers = HashMap::new();
api_headers.insert("content-type".to_string(), "application/json".to_string());
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/maintenance"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::PATCH, &path, Some(api_headers), Some(params))
.await
}
pub async fn create_migration(
&self,
database_id: impl Into<String>,
target_type: impl Into<String>,
specification: Option<&str>,
) -> crate::error::Result<crate::models::DedicatedDatabase> {
let mut params = HashMap::new();
params.insert("targetType".to_string(), json!(target_type.into()));
if let Some(value) = specification {
params.insert("specification".to_string(), json!(value));
}
let mut api_headers = HashMap::new();
api_headers.insert("content-type".to_string(), "application/json".to_string());
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/migrations"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::POST, &path, Some(api_headers), Some(params))
.await
}
pub async fn list_operations(
&self,
database_id: impl Into<String>,
status: Option<&str>,
limit: Option<i64>,
offset: Option<i64>,
) -> crate::error::Result<crate::models::DedicatedDatabaseOperationList> {
let mut params = HashMap::new();
if let Some(value) = status {
params.insert("status".to_string(), json!(value));
}
if let Some(value) = limit {
params.insert("limit".to_string(), json!(value));
}
if let Some(value) = offset {
params.insert("offset".to_string(), json!(value));
}
let mut api_headers = HashMap::new();
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/operations"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::GET, &path, Some(api_headers), Some(params))
.await
}
pub async fn get_pitr(
&self,
database_id: impl Into<String>,
) -> crate::error::Result<crate::models::DedicatedDatabasePITRWindows> {
let params = HashMap::new();
let mut api_headers = HashMap::new();
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/pitr"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::GET, &path, Some(api_headers), Some(params))
.await
}
pub async fn get_pooler(
&self,
database_id: impl Into<String>,
) -> crate::error::Result<crate::models::DedicatedDatabasePooler> {
let params = HashMap::new();
let mut api_headers = HashMap::new();
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/pooler"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::GET, &path, Some(api_headers), Some(params))
.await
}
#[allow(clippy::too_many_arguments)]
pub async fn update_pooler(
&self,
database_id: impl Into<String>,
mode: Option<&str>,
max_connections: Option<i64>,
default_pool_size: Option<i64>,
read_write_splitting: Option<bool>,
pooler_cpu_request: Option<&str>,
pooler_cpu_limit: Option<&str>,
pooler_memory_request: Option<&str>,
pooler_memory_limit: Option<&str>,
) -> crate::error::Result<crate::models::DedicatedDatabasePooler> {
let mut params = HashMap::new();
if let Some(value) = mode {
params.insert("mode".to_string(), json!(value));
}
if let Some(value) = max_connections {
params.insert("maxConnections".to_string(), json!(value));
}
if let Some(value) = default_pool_size {
params.insert("defaultPoolSize".to_string(), json!(value));
}
if let Some(value) = read_write_splitting {
params.insert("readWriteSplitting".to_string(), json!(value));
}
if let Some(value) = pooler_cpu_request {
params.insert("poolerCpuRequest".to_string(), json!(value));
}
if let Some(value) = pooler_cpu_limit {
params.insert("poolerCpuLimit".to_string(), json!(value));
}
if let Some(value) = pooler_memory_request {
params.insert("poolerMemoryRequest".to_string(), json!(value));
}
if let Some(value) = pooler_memory_limit {
params.insert("poolerMemoryLimit".to_string(), json!(value));
}
let mut api_headers = HashMap::new();
api_headers.insert("content-type".to_string(), "application/json".to_string());
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/pooler"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::PATCH, &path, Some(api_headers), Some(params))
.await
}
pub async fn get_replicas(
&self,
database_id: impl Into<String>,
) -> crate::error::Result<crate::models::DedicatedDatabaseReplicas> {
let params = HashMap::new();
let mut api_headers = HashMap::new();
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/replicas"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::GET, &path, Some(api_headers), Some(params))
.await
}
pub async fn list_restorations(
&self,
database_id: impl Into<String>,
status: Option<&str>,
r#type: Option<&str>,
limit: Option<i64>,
offset: Option<i64>,
) -> crate::error::Result<crate::models::DedicatedDatabaseRestorationList> {
let mut params = HashMap::new();
if let Some(value) = status {
params.insert("status".to_string(), json!(value));
}
if let Some(value) = r#type {
params.insert("type".to_string(), json!(value));
}
if let Some(value) = limit {
params.insert("limit".to_string(), json!(value));
}
if let Some(value) = offset {
params.insert("offset".to_string(), json!(value));
}
let mut api_headers = HashMap::new();
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/restorations"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::GET, &path, Some(api_headers), Some(params))
.await
}
pub async fn create_restoration(
&self,
database_id: impl Into<String>,
r#type: Option<&str>,
backup_id: Option<&str>,
target_database_id: Option<&str>,
target_time: Option<&str>,
) -> crate::error::Result<crate::models::DedicatedDatabaseRestoration> {
let mut params = HashMap::new();
if let Some(value) = r#type {
params.insert("type".to_string(), json!(value));
}
if let Some(value) = backup_id {
params.insert("backupId".to_string(), json!(value));
}
if let Some(value) = target_database_id {
params.insert("targetDatabaseId".to_string(), json!(value));
}
if let Some(value) = target_time {
params.insert("targetTime".to_string(), json!(value));
}
let mut api_headers = HashMap::new();
api_headers.insert("content-type".to_string(), "application/json".to_string());
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/restorations"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::POST, &path, Some(api_headers), Some(params))
.await
}
pub async fn get_restoration(
&self,
database_id: impl Into<String>,
restoration_id: impl Into<String>,
) -> crate::error::Result<crate::models::DedicatedDatabaseRestoration> {
let params = HashMap::new();
let mut api_headers = HashMap::new();
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/restorations/{restorationId}"
.to_string()
.replace("{databaseId}", &database_id.into().to_string())
.replace("{restorationId}", &restoration_id.into().to_string());
self.client
.call(Method::GET, &path, Some(api_headers), Some(params))
.await
}
pub async fn get_status(
&self,
database_id: impl Into<String>,
) -> crate::error::Result<crate::models::DatabaseStatus> {
let params = HashMap::new();
let mut api_headers = HashMap::new();
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/status"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::GET, &path, Some(api_headers), Some(params))
.await
}
pub async fn create_upgrade(
&self,
database_id: impl Into<String>,
target_version: impl Into<String>,
) -> crate::error::Result<crate::models::DedicatedDatabase> {
let mut params = HashMap::new();
params.insert("targetVersion".to_string(), json!(target_version.into()));
let mut api_headers = HashMap::new();
api_headers.insert("content-type".to_string(), "application/json".to_string());
api_headers.insert("accept".to_string(), "application/json".to_string());
let path = "/mysql/{databaseId}/upgrades"
.to_string()
.replace("{databaseId}", &database_id.into().to_string());
self.client
.call(Method::POST, &path, Some(api_headers), Some(params))
.await
}
}
impl crate::services::Service for Mysql {
fn client(&self) -> &Client {
&self.client
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_mysql_creation() {
let client = Client::new();
let service = Mysql::new(&client);
assert!(service.client().endpoint().contains("cloud.appwrite.io/v1"));
}
}