Skip to content

Commit

Permalink
fix(pkg): address ccoVeille comments
Browse files Browse the repository at this point in the history
  • Loading branch information
danvergara committed Nov 17, 2024
1 parent dcb4c84 commit 2f01c7e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
33 changes: 26 additions & 7 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,22 @@ func (c *Client) Query(q string, args ...interface{}) ([][]string, []string, err
var (
resultSet = [][]string{}
db *sqlx.DB
ok bool
)

db = c.db

if c.activeDatabase != "" {
switch c.driver {
case drivers.Postgres, drivers.PostgreSQL, drivers.MySQL:
db = c.dbs[c.activeDatabase]
db, ok = c.dbs[c.activeDatabase]
if !ok {
return nil, nil, fmt.Errorf(
"connection with %s database not found",
c.activeDatabase,
)
}
}
} else {
db = c.db
}

// Runs the query extracting the content of the view calling the Buffer method.
Expand Down Expand Up @@ -194,6 +201,9 @@ func (c *Client) Query(q string, args ...interface{}) ([][]string, []string, err

resultSet = append(resultSet, s)
}
if err := rows.Err(); err != nil {
return nil, nil, err
}

return resultSet, columnNames, nil
}
Expand Down Expand Up @@ -301,6 +311,9 @@ func (c *Client) ShowTablesPerDB(database string) ([]string, error) {

tables = append(tables, table)
}
if err := rows.Err(); err != nil {
return nil, err
}

return tables, nil
}
Expand Down Expand Up @@ -333,6 +346,9 @@ func (c *Client) ShowTables() ([]string, error) {

tables = append(tables, table)
}
if err := rows.Err(); err != nil {
return nil, err
}

return tables, nil
}
Expand Down Expand Up @@ -365,6 +381,9 @@ func (c *Client) ShowDatabases() ([]string, error) {

databases = append(databases, database)
}
if err := rows.Err(); err != nil {
return nil, err
}

return databases, nil
}
Expand Down Expand Up @@ -446,9 +465,10 @@ func (c *Client) indexes(tableName string) ([][]string, []string, error) {
func getDB(driver, connString, database string) (*sqlx.DB, error) {
var newConnString string

if driver == drivers.MySQL {
switch driver {
case drivers.MySQL:
newConnString = strings.Replace(connString, "/", fmt.Sprintf("/%s", database), 1)
} else {
default:
u, err := url.Parse(connString)
if err != nil {
return nil, err
Expand All @@ -460,8 +480,7 @@ func getDB(driver, connString, database string) (*sqlx.DB, error) {

db, err := sqlx.Open(driver, newConnString)
if err != nil {

panic(err)
return nil, err
}

return db, nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ func TestConstraints(t *testing.T) {
t.Logf("constraints content %v", r)

assert.NoError(t, err)
assert.Greater(t, len(r), 0)
assert.Greater(t, len(co), 0)
assert.NotEmpty(t, r)
assert.NotEmpty(t, co)
}

func TestIndexes(t *testing.T) {
Expand All @@ -311,8 +311,8 @@ func TestIndexes(t *testing.T) {
r, co, err := c.indexes("products")

assert.NoError(t, err)
assert.Greater(t, len(r), 0)
assert.Greater(t, len(co), 0)
assert.NotEmpty(t, r)
assert.NotEmpty(t, co)
}

func TestMetadata(t *testing.T) {
Expand Down
4 changes: 0 additions & 4 deletions pkg/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,6 @@ func (t *Tui) updateTableMetadataOnChange(tableName string) {

for i, sr := range m.TableContent.Rows {
for j, sc := range sr {
// if i == 0 {
// t.aw.content.SetCell(i+1, j, &tview.TableCell{Text: sc, Color: tcell.ColorRed})
// } else {
// }
t.aw.content.SetCellSimple(i+1, j, sc)
}
}
Expand Down

0 comments on commit 2f01c7e

Please sign in to comment.