diff --git a/Dockerfile b/Dockerfile index 8d1c23f..c03600f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,5 @@ FROM golang:1.11 -RUN apt-get update && apt-get install -y --no-install-recommends mysql-client && rm -rf /var/lib/apt/lists/* - -RUN apt-get update && apt-get install -y postgresql-client +RUN apt-get update && apt-get install -y --no-install-recommends mysql-client postgresql-client && rm -rf /var/lib/apt/lists/* ENTRYPOINT [ "go", "test", "-v", "." ] diff --git a/README.md b/README.md index 7108fe1..b45421f 100644 --- a/README.md +++ b/README.md @@ -64,8 +64,7 @@ sql all "SELECT * FROM users WHERE name = 'John'" ## Dependencies -- mysql -- psql +- mysql-client and/or postgresql-client - ssh (only if you configure an "appServer") ## Contribute diff --git a/config.go b/config.go index 6ca017c..2b05f02 100644 --- a/config.go +++ b/config.go @@ -16,7 +16,6 @@ type database struct { User string Pass string SQLType string - _sqlType sqlType } func mustReadDatabasesConfigFile() map[string]database { @@ -68,17 +67,5 @@ func mustReadDatabasesConfigFile() map[string]database { usage("Couldn't find any database configurations on .databases.json. Looked like this:\n\n%v\n", string(byts)) } - for dbName, db := range databases { - typeStr := db.SQLType - if typeStr == "" { - typeStr = "mysql" - } - if _, ok := validSQLTypes[typeStr]; !ok { - usage("Unknown sql type %v for %v", typeStr, dbName) - } - db._sqlType = validSQLTypes[typeStr] - databases[dbName] = db - } - return databases } diff --git a/main.go b/main.go index b74aa02..710be69 100644 --- a/main.go +++ b/main.go @@ -78,7 +78,12 @@ func _main(databases map[string]database, databasesArgs []string, query string, sqlTypes := map[sqlType]exists{} var sqlType sqlType for _, db := range targetDatabases { - sqlType = databases[db]._sqlType + database := databases[db] + typ, ok := validSQLTypes[database.SQLType] + if !ok { + usage("Unknown sql type %v for %v", database.SQLType, db) + } + sqlType = typ sqlTypes[sqlType] = exists{} if len(sqlTypes) > 1 { usage("More than one sql types specified in target databases.") diff --git a/main_test.go b/main_test.go index e3cfe19..b23ad29 100644 --- a/main_test.go +++ b/main_test.go @@ -28,9 +28,9 @@ func Test_MySQL(t *testing.T) { var ( testConfig = map[string]database{ - "db1": database{DbServer: "test-mysql", DbName: "db1", User: "root", Pass: "", _sqlType: mySQL}, - "db2": database{DbServer: "test-mysql", DbName: "db2", User: "root", Pass: "", _sqlType: mySQL}, - "db3": database{DbServer: "test-mysql", DbName: "db3", User: "root", Pass: "", _sqlType: mySQL}, + "db1": database{DbServer: "test-mysql", DbName: "db1", User: "root", Pass: "", SQLType: "mysql"}, + "db2": database{DbServer: "test-mysql", DbName: "db2", User: "root", Pass: "", SQLType: ""}, + "db3": database{DbServer: "test-mysql", DbName: "db3", User: "root", Pass: "", SQLType: ""}, } ts = []struct { name string @@ -129,9 +129,9 @@ func Test_PostgreSQL(t *testing.T) { var ( testConfig = map[string]database{ - "db1": database{DbServer: "test-postgres", DbName: "db1", User: "root", Pass: "", _sqlType: postgreSQL}, - "db2": database{DbServer: "test-postgres", DbName: "db2", User: "root", Pass: "", _sqlType: postgreSQL}, - "db3": database{DbServer: "test-postgres", DbName: "db3", User: "root", Pass: "", _sqlType: postgreSQL}, + "db1": database{DbServer: "test-postgres", DbName: "db1", User: "root", Pass: "", SQLType: "postgres"}, + "db2": database{DbServer: "test-postgres", DbName: "db2", User: "root", Pass: "", SQLType: "postgres"}, + "db3": database{DbServer: "test-postgres", DbName: "db3", User: "root", Pass: "", SQLType: "postgres"}, } ts = []struct { name string diff --git a/sql_runner.go b/sql_runner.go index df3e52c..a43c5b9 100644 --- a/sql_runner.go +++ b/sql_runner.go @@ -29,6 +29,7 @@ type sqlOptions struct { } var validSQLTypes = map[string]sqlType{ + "": mySQL, "mysql": mySQL, "postgres": postgreSQL, }