1
0
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:
Almaz Sharipov
2025-02-16 14:07:41 +03:00
parent 9dce8f6b6a
commit f2a81d46bf
2 changed files with 20 additions and 1 deletions

View File

@@ -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"`
}

View File

@@ -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