AdysTech.InfluxDB.Client.Net.InfluxDBClient.CreateDatabaseAsync C# (CSharp) Метод

CreateDatabaseAsync() публичный Метод

Creates the specified database
When Influx needs authentication, and no user name password is supplied or auth fails all other HTTP exceptions
public CreateDatabaseAsync ( string dbName ) : Task
dbName string
Результат Task
        public async Task<bool> CreateDatabaseAsync (string dbName)
        {
            var response = await GetAsync (new Dictionary<string, string> () { { "q", $"CREATE DATABASE {dbName}" } });
            if (response.StatusCode == HttpStatusCode.OK)
            {
                var content = await response.Content.ReadAsStringAsync ();
                if (content.Contains ("database already exists"))
                    throw new InvalidOperationException ("database already exists");
                return true;
            }

            return false;
        }

Usage Example

Пример #1
0
 private static async Task<InfluxDBClient> GetClientAsync (InfluxerConfigSection settings)
 {
     var client = new InfluxDBClient (settings.InfluxDB.InfluxUri, settings.InfluxDB.UserName, settings.InfluxDB.Password);
     var dbNames = await client.GetInfluxDBNamesAsync ();
     if (dbNames.Contains (settings.InfluxDB.DatabaseName))
         return client;
     else
     {
         await client.CreateDatabaseAsync (settings.InfluxDB.DatabaseName);
         return client;
     }
 }
All Usage Examples Of AdysTech.InfluxDB.Client.Net.InfluxDBClient::CreateDatabaseAsync