1
0
mirror of https://github.com/alm494/sql_proxy.git synced 2026-04-05 11:51:03 +02:00

interface{} to any

This commit is contained in:
Almaz Sharipov
2025-03-31 08:08:57 +03:00
parent c416a2f90a
commit 57541d2995
4 changed files with 21 additions and 19 deletions

View File

@@ -9,6 +9,8 @@ import (
"time"
"slices"
"github.com/google/uuid"
"github.com/sirupsen/logrus"
)
@@ -42,7 +44,7 @@ func (o *DbList) GetByParams(connInfo *DbConnInfo) (string, bool) {
// Step 1. Search existing connection by hash to reuse
guid := ""
o.items.Range(
func(key, value interface{}) bool {
func(key, value any) bool {
if bytes.Equal(value.(*DbConn).Hash[:], hash[:]) {
guid = key.(string)
app.Log.Debugf("DB connection with id %s found in the pool", guid)
@@ -191,10 +193,10 @@ func (o *DbList) ClosePreparedStatement(conn_id, stmt_id string) bool {
return false
}
res := val.(*DbConn)
for i := 0; i < len(res.Stmt); i++ {
for i := range res.Stmt {
if res.Stmt[i].Id == stmt_id {
res.Stmt[i].Stmt.Close()
res.Stmt = append(res.Stmt[:i], res.Stmt[i+1:]...)
res.Stmt = slices.Delete(res.Stmt, i, i+1)
break
}
}
@@ -216,7 +218,7 @@ func (o *DbList) RunMaintenance() {
var countConn, countDeadConn, countStmt int
o.items.Range(
func(key, value interface{}) bool {
func(key, value any) bool {
var lostStmts []string
countConn++
dbConn := value.(*DbConn)
@@ -245,7 +247,7 @@ func (o *DbList) RunMaintenance() {
for i := 0; i < len(dbConn.Stmt); i++ {
if dbConn.Stmt[i].Id == lost {
dbConn.Stmt[i].Stmt.Close()
dbConn.Stmt = append(dbConn.Stmt[:i], dbConn.Stmt[i+1:]...)
dbConn.Stmt = slices.Delete(dbConn.Stmt, i, i+1)
break
}
}

View File

@@ -6,12 +6,12 @@ import (
)
// Converts SQL query result to json
func convertRows(rows *sql.Rows, columns *[]string) (*[]map[string]interface{}, uint32, bool) {
func convertRows(rows *sql.Rows, columns *[]string) (*[]map[string]any, uint32, bool) {
var rowsCount uint32 = 0
colsCount := len(*columns)
tableData := make([]map[string]interface{}, 0)
values := make([]interface{}, colsCount)
valuePtrs := make([]interface{}, colsCount)
tableData := make([]map[string]any, 0)
values := make([]any, colsCount)
valuePtrs := make([]any, colsCount)
exceedsMaxRows := false
for rows.Next() {
@@ -19,9 +19,9 @@ func convertRows(rows *sql.Rows, columns *[]string) (*[]map[string]interface{},
valuePtrs[i] = &values[i]
}
rows.Scan(valuePtrs...)
entry := make(map[string]interface{})
entry := make(map[string]any)
for i, col := range *columns {
var v interface{}
var v any
val := values[i]
b, ok := val.([]byte)
if ok {

View File

@@ -1,10 +1,10 @@
package handlers
type ResponseEnvelope struct {
ApiVersion uint8 `json:"api_version"`
ConnectionId string `json:"connection_id"`
Info string `json:"info"`
RowsCount uint32 `json:"rows_count"`
ExceedsMaxRows bool `json:"exceeds_max_rows"`
Rows []map[string]interface{} `json:"rows"`
ApiVersion uint8 `json:"api_version"`
ConnectionId string `json:"connection_id"`
Info string `json:"info"`
RowsCount uint32 `json:"rows_count"`
ExceedsMaxRows bool `json:"exceeds_max_rows"`
Rows []map[string]any `json:"rows"`
}

View File

@@ -7,7 +7,7 @@ import (
)
func PrepareStatement(w http.ResponseWriter, r *http.Request) {
var requestBody map[string]interface{}
var requestBody map[string]any
err := json.NewDecoder(r.Body).Decode(&requestBody)
if err != nil {
http.Error(w, "Error decoding JSON", http.StatusBadRequest)
@@ -38,7 +38,7 @@ func PrepareStatement(w http.ResponseWriter, r *http.Request) {
}
func PreparedSelect(w http.ResponseWriter, r *http.Request) {
var requestBody map[string]interface{}
var requestBody map[string]any
err := json.NewDecoder(r.Body).Decode(&requestBody)
if err != nil {
http.Error(w, "Error decoding JSON", http.StatusBadRequest)