Use 'CREATE DATABASE IF NOT EXISTS' syntax

This commit is contained in:
gunnaraasen 2015-11-16 15:55:49 -08:00
parent bf8e0f4cae
commit c3b34ead49
1 changed files with 2 additions and 2 deletions

View File

@ -97,10 +97,10 @@ func (i *InfluxDB) Connect() error {
// Create Database if it doesn't exist
_, e := c.Query(client.Query{
Command: fmt.Sprintf("CREATE DATABASE %s", i.Database),
Command: fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s", i.Database),
})
if e != nil && !strings.Contains(e.Error(), "database already exists") {
if e != nil {
log.Println("Database creation failed: " + e.Error())
}