Skip to content

Commit

Permalink
Add delete row
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgerojas26 committed Oct 23, 2023
1 parent a6f1a44 commit 55c5d33
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
17 changes: 15 additions & 2 deletions components/ResultsTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,18 +336,31 @@ func (table *ResultsTable) tableInputCapture(event *tcell.EventKey) *tcell.Event
go table.Select(1, selectedColumnIndex)
} else if event.Rune() == 71 { // G Key
go table.Select(rowCount-1, selectedColumnIndex)
} else if event.Rune() == 100 { // d Key
} else if event.Rune() == 4 { // Ctrl + D
if selectedRowIndex+7 > rowCount-1 {
go table.Select(rowCount-1, selectedColumnIndex)
} else {
go table.Select(selectedRowIndex+7, selectedColumnIndex)
}
} else if event.Rune() == 117 { // u Key
} else if event.Rune() == 21 { // Ctrl + U
if selectedRowIndex-7 < 1 {
go table.Select(1, selectedColumnIndex)
} else {
go table.Select(selectedRowIndex-7, selectedColumnIndex)
}
} else if event.Rune() == 'd' {
id := table.GetCell(selectedRowIndex, 0).Text
error := drivers.MySQL.DeleteRecord(table.GetDBReference(), id)

if error != nil {
table.SetError(error.Error(), nil)
} else {
records := table.GetRecords()

newRecords := append(records[:selectedRowIndex], records[selectedRowIndex+1:]...)

table.SetRecords(newRecords)
}
}

if len(table.GetRecords()) > 0 {
Expand Down
17 changes: 7 additions & 10 deletions drivers/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ func (db *MySql) Connect() error {
return nil
}

func (db *MySql) Disconnect() error {
return db.conn.Close()
}

func (db *MySql) SetConnectionString(connectionString string) {
db.connectionString = connectionString
}
Expand All @@ -75,10 +71,6 @@ func (db *MySql) GetConnectionString() string {
return db.connectionString
}

func (db *MySql) GetConnection() *sql.DB {
return db.conn
}

func (db *MySql) GetDatabases() ([]string, error) {
var databases []string

Expand Down Expand Up @@ -297,9 +289,7 @@ func (db *MySql) GetPaginatedRecords(table string, where string, sort string, of
}

func (db *MySql) QueryPaginatedRecords(query string) (results [][]string, err error) {

rows, err := db.conn.Query(query)

if err != nil {
return results, err
}
Expand Down Expand Up @@ -337,6 +327,13 @@ func (db *MySql) UpdateRecord(table string, column string, value string, id stri
return err
}

func (db *MySql) DeleteRecord(table string, id string) error {
query := fmt.Sprintf("DELETE FROM %s WHERE id = \"%s\"", table, id)
_, err := db.conn.Exec(query)

return err
}

func (db *MySql) GetLastExecutedQuery() string {
return db.lastExecutedQuery
}
Expand Down

0 comments on commit 55c5d33

Please sign in to comment.