mirror of
https://github.com/alm494/sql_proxy.git
synced 2025-10-08 22:01:51 +02:00
func ExecuteQuery
This commit is contained in:
@@ -8,3 +8,8 @@ type ResponseEnvelope struct {
|
||||
ExceedsMaxRows bool `json:"exceeds_max_rows"`
|
||||
Rows []map[string]interface{}
|
||||
}
|
||||
|
||||
type ExecuteQueryEnvelope struct {
|
||||
SQL string `json:"sql"`
|
||||
Conn string `json:"connection_id"`
|
||||
}
|
||||
|
@@ -62,7 +62,21 @@ func GetQuery(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func ExecuteQuery(w http.ResponseWriter, r *http.Request) {
|
||||
// to do
|
||||
var payload ExecuteQueryEnvelope
|
||||
err := json.NewDecoder(r.Body).Decode(&payload)
|
||||
if err != nil {
|
||||
http.Error(w, "Invalid JSON payload", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
conn, ok := db.DbHandler.GetById(payload.Conn, true)
|
||||
if !ok {
|
||||
http.Error(w, "Invalid connection id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
_, err = conn.Exec(payload.SQL)
|
||||
if err != nil {
|
||||
http.Error(w, "Invalid SQL query", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
// Converts SQL query result to json
|
||||
|
Reference in New Issue
Block a user