Skip to content

Commit

Permalink
feat(exec): Add exec to the beginning of db client commands
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Oct 5, 2023
1 parent 83346d1 commit 8edd66b
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion internal/database/dialect/mariadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (db MariaDB) PasswordEnvNames(c config.Global) []string {
func (MariaDB) ExecCommand(conf config.Exec) *command.Builder {
cmd := command.NewBuilder(
command.NewEnv("MYSQL_PWD", conf.Password),
"mysql", "--host="+conf.Host, "--user="+conf.Username,
"exec", "mysql", "--host="+conf.Host, "--user="+conf.Username,
)
if conf.Database != "" {
cmd.Push("--database=" + conf.Database)
Expand Down
6 changes: 3 additions & 3 deletions internal/database/dialect/mariadb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,17 @@ func TestMariaDB_ExecCommand(t *testing.T) {
{
"default",
args{config.Exec{Global: config.Global{Host: "1.1.1.1", Database: "d", Username: "u"}}},
command.NewBuilder(command.Env{Key: "MYSQL_PWD"}, "mysql", "--host=1.1.1.1", "--user=u", "--database=d"),
command.NewBuilder(command.Env{Key: "MYSQL_PWD"}, "exec", "mysql", "--host=1.1.1.1", "--user=u", "--database=d"),
},
{
"disable-headers",
args{config.Exec{DisableHeaders: true, Global: config.Global{Host: "1.1.1.1", Database: "d", Username: "u"}}},
command.NewBuilder(command.Env{Key: "MYSQL_PWD"}, "mysql", "--host=1.1.1.1", "--user=u", "--database=d", "--skip-column-names"),
command.NewBuilder(command.Env{Key: "MYSQL_PWD"}, "exec", "mysql", "--host=1.1.1.1", "--user=u", "--database=d", "--skip-column-names"),
},
{
"command",
args{config.Exec{Command: "show databases", Global: config.Global{Host: "1.1.1.1", Database: "d", Username: "u"}}},
command.NewBuilder(command.Env{Key: "MYSQL_PWD"}, "mysql", "--host=1.1.1.1", "--user=u", "--database=d", "--execute=show databases"),
command.NewBuilder(command.Env{Key: "MYSQL_PWD"}, "exec", "mysql", "--host=1.1.1.1", "--user=u", "--database=d", "--execute=show databases"),
},
}
for _, tt := range tests {
Expand Down
2 changes: 1 addition & 1 deletion internal/database/dialect/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (db MongoDB) AuthenticationDatabase(c config.Global) string {

func (db MongoDB) ExecCommand(conf config.Exec) *command.Builder {
cmd := command.NewBuilder(
command.Raw(`"$(which mongosh || which mongo)"`),
"exec", command.Raw(`"$(which mongosh || which mongo)"`),
"--host="+conf.Host,
"--username="+conf.Username,
"--password="+conf.Password,
Expand Down
6 changes: 3 additions & 3 deletions internal/database/dialect/mongodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,17 @@ func TestMongoDB_ExecCommand(t *testing.T) {
{
"default",
args{config.Exec{Global: config.Global{Host: "1.1.1.1", Database: "d", Username: "u", Password: "p"}}},
command.NewBuilder(command.Raw(`"$(which mongosh || which mongo)"`), "--host=1.1.1.1", "--username=u", "--password=p", "--authenticationDatabase=d", "d"),
command.NewBuilder("exec", command.Raw(`"$(which mongosh || which mongo)"`), "--host=1.1.1.1", "--username=u", "--password=p", "--authenticationDatabase=d", "d"),
},
{
"disable-headers",
args{config.Exec{DisableHeaders: true, Global: config.Global{Host: "1.1.1.1", Database: "d", Username: "u", Password: "p"}}},
command.NewBuilder(command.Raw(`"$(which mongosh || which mongo)"`), "--host=1.1.1.1", "--username=u", "--password=p", "--authenticationDatabase=d", "--quiet", "d"),
command.NewBuilder("exec", command.Raw(`"$(which mongosh || which mongo)"`), "--host=1.1.1.1", "--username=u", "--password=p", "--authenticationDatabase=d", "--quiet", "d"),
},
{
"command",
args{config.Exec{Command: "show databases", Global: config.Global{Host: "1.1.1.1", Database: "d", Username: "u", Password: "p"}}},
command.NewBuilder(command.Raw(`"$(which mongosh || which mongo)"`), "--host=1.1.1.1", "--username=u", "--password=p", "--authenticationDatabase=d", "--eval=show databases", "d"),
command.NewBuilder("exec", command.Raw(`"$(which mongosh || which mongo)"`), "--host=1.1.1.1", "--username=u", "--password=p", "--authenticationDatabase=d", "--eval=show databases", "d"),
},
}
for _, tt := range tests {
Expand Down
2 changes: 1 addition & 1 deletion internal/database/dialect/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (db Postgres) PasswordEnvNames(c config.Global) []string {
func (Postgres) ExecCommand(conf config.Exec) *command.Builder {
cmd := command.NewBuilder(
command.NewEnv("PGPASSWORD", conf.Password),
"psql", "--host="+conf.Host, "--username="+conf.Username,
"exec", "psql", "--host="+conf.Host, "--username="+conf.Username,
)
if conf.Database != "" {
cmd.Push("--dbname=" + conf.Database)
Expand Down
6 changes: 3 additions & 3 deletions internal/database/dialect/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,17 @@ func TestPostgres_ExecCommand(t *testing.T) {
{
"default",
args{config.Exec{Global: config.Global{Host: "1.1.1.1", Database: "d", Username: "u"}}},
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "psql", "--host=1.1.1.1", "--username=u", "--dbname=d"),
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "exec", "psql", "--host=1.1.1.1", "--username=u", "--dbname=d"),
},
{
"disable-headers",
args{config.Exec{DisableHeaders: true, Global: config.Global{Host: "1.1.1.1", Database: "d", Username: "u"}}},
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "psql", "--host=1.1.1.1", "--username=u", "--dbname=d", "--tuples-only"),
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "exec", "psql", "--host=1.1.1.1", "--username=u", "--dbname=d", "--tuples-only"),
},
{
"command",
args{config.Exec{Command: "select true", Global: config.Global{Host: "1.1.1.1", Database: "d", Username: "u"}}},
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "psql", "--host=1.1.1.1", "--username=u", "--dbname=d", "--command=select true"),
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "exec", "psql", "--host=1.1.1.1", "--username=u", "--dbname=d", "--command=select true"),
},
}
for _, tt := range tests {
Expand Down

0 comments on commit 8edd66b

Please sign in to comment.