feat: Add delete, drop, insert, truncate, update
This commit is contained in:
31
utils/sql.go
Normal file
31
utils/sql.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func SQLQuoteIdent(id string) string {
|
||||
return `"` + strings.ReplaceAll(id, `"`, `""`) + `"`
|
||||
}
|
||||
|
||||
func SQLQuoteValue(value any) string {
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
// Escape single quotes by doubling them (PostgreSQL standard)
|
||||
escaped := strings.ReplaceAll(v, "'", "''")
|
||||
return fmt.Sprintf("'%s'", escaped)
|
||||
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
|
||||
return fmt.Sprintf("%v", value)
|
||||
case float32, float64:
|
||||
return fmt.Sprintf("%v", value)
|
||||
case bool:
|
||||
return fmt.Sprintf("%v", value)
|
||||
case nil:
|
||||
return "NULL"
|
||||
}
|
||||
// For unknown types, convert to string and escape
|
||||
str := fmt.Sprintf("%v", value)
|
||||
escaped := strings.ReplaceAll(str, "'", "''")
|
||||
return fmt.Sprintf("'%s'", escaped)
|
||||
}
|
||||
Reference in New Issue
Block a user