mirror of
https://github.com/sosedoff/pgweb.git
synced 2024-12-14 19:21:46 +03:00
Return number of affected rows if sql query is update or delete
This commit is contained in:
parent
6edc384c05
commit
4b4f778360
@ -226,8 +226,29 @@ func (client *Client) Query(query string) (*Result, error) {
|
||||
}
|
||||
|
||||
func (client *Client) query(query string, args ...interface{}) (*Result, error) {
|
||||
rows, err := client.db.Queryx(query, args...)
|
||||
action := strings.ToLower(strings.Split(query, " ")[0])
|
||||
if action == "update" || action == "delete" {
|
||||
res, err := client.db.Exec(query, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
affected, err := res.RowsAffected()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := Result{
|
||||
Columns: []string{"Rows Affected"},
|
||||
Rows: []Row{
|
||||
Row{affected},
|
||||
},
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
rows, err := client.db.Queryx(query, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user