formatovany kod pomocou gofmt
This commit is contained in:
54
dbPrompt.go
54
dbPrompt.go
@ -34,13 +34,13 @@ type QueryRequest struct {
|
||||
|
||||
// QueryResult represents a single historical query execution
|
||||
type QueryResult struct {
|
||||
ID string `json:"id"`
|
||||
Query string `json:"query"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Columns []string `json:"columns,omitempty"`
|
||||
Rows [][]interface{} `json:"rows,omitempty"`
|
||||
RowsAffected int64 `json:"rowsAffected,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Query string `json:"query"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Columns []string `json:"columns,omitempty"`
|
||||
Rows [][]interface{} `json:"rows,omitempty"`
|
||||
RowsAffected int64 `json:"rowsAffected,omitempty"`
|
||||
}
|
||||
|
||||
var db *sql.DB
|
||||
@ -141,10 +141,10 @@ func handleQuery(w http.ResponseWriter, r *http.Request) {
|
||||
Timestamp: time.Now().UnixNano(),
|
||||
}
|
||||
|
||||
// Generate new ID if it's a new query
|
||||
if result.ID == "" {
|
||||
result.ID = strconv.FormatInt(result.Timestamp, 10)
|
||||
}
|
||||
// Generate new ID if it's a new query
|
||||
if result.ID == "" {
|
||||
result.ID = strconv.FormatInt(result.Timestamp, 10)
|
||||
}
|
||||
|
||||
if isSelect {
|
||||
// It's a query that returns rows
|
||||
@ -155,21 +155,21 @@ func handleQuery(w http.ResponseWriter, r *http.Request) {
|
||||
defer rows.Close()
|
||||
cols, _ := rows.Columns()
|
||||
result.Columns = cols
|
||||
|
||||
for rows.Next() {
|
||||
// Create a slice of interface{}'s to represent a row
|
||||
columns := make([]interface{}, len(cols))
|
||||
columnPointers := make([]interface{}, len(cols))
|
||||
for i := range columns {
|
||||
columnPointers[i] = &columns[i]
|
||||
}
|
||||
|
||||
// Scan the result into the column pointers...
|
||||
if err := rows.Scan(columnPointers...); err != nil {
|
||||
result.Error = err.Error()
|
||||
break
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
// Create a slice of interface{}'s to represent a row
|
||||
columns := make([]interface{}, len(cols))
|
||||
columnPointers := make([]interface{}, len(cols))
|
||||
for i := range columns {
|
||||
columnPointers[i] = &columns[i]
|
||||
}
|
||||
|
||||
// Scan the result into the column pointers...
|
||||
if err := rows.Scan(columnPointers...); err != nil {
|
||||
result.Error = err.Error()
|
||||
break
|
||||
}
|
||||
|
||||
// Convert byte slices to strings for better JSON representation
|
||||
for i, col := range columns {
|
||||
if b, ok := col.([]byte); ok {
|
||||
@ -177,7 +177,7 @@ func handleQuery(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
result.Rows = append(result.Rows, columns)
|
||||
result.Rows = append(result.Rows, columns)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
result.Error = err.Error()
|
||||
@ -208,4 +208,4 @@ func handleQuery(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(result)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user