public PSKustoDatabase CreateOrUpdateDatabase(string resourceGroupName,
                                                      string clusterName,
                                                      string databaseName,
                                                      int hotCachePeriodInDays,
                                                      int softDeletePeriodInDays,
                                                      string location,
                                                      PSKustoDatabase existingDatbase = null)
        {
            if (string.IsNullOrEmpty(resourceGroupName))
            {
                resourceGroupName = GetResourceGroupByCluster(clusterName);
            }

            Database newOrUpdatedDatabase;

            if (existingDatbase != null)
            {
                var updateParameters = new DatabaseUpdate()
                {
                    SoftDeletePeriodInDays = softDeletePeriodInDays, HotCachePeriodInDays = hotCachePeriodInDays
                };
                newOrUpdatedDatabase = _client.Databases.Update(resourceGroupName, clusterName, databaseName, updateParameters);
            }
            else
            {
                newOrUpdatedDatabase = _client.Databases.CreateOrUpdate(
                    resourceGroupName,
                    clusterName,
                    databaseName,
                    new Database()
                {
                    HotCachePeriodInDays   = hotCachePeriodInDays,
                    SoftDeletePeriodInDays = softDeletePeriodInDays,
                    Location = location
                });
            }

            return(new PSKustoDatabase(newOrUpdatedDatabase));
        }
        public bool CheckIfDatabaseExists(string resourceGroupName, string clusterName, string databaseName, out PSKustoDatabase database)
        {
            try
            {
                database = GetDatabase(resourceGroupName, clusterName, databaseName);
                return(true);
            }
            catch (CloudException ex)
            {
                if ((ex.Response != null && ex.Response.StatusCode == HttpStatusCode.NotFound) || ex.Message.Contains(string.Format(Properties.Resources.FailedToDiscoverResourceGroup, clusterName,
                                                                                                                                    _subscriptionId)))
                {
                    database = null;
                    return(false);
                }

                throw;
            }
        }