feat: Add delete, drop, insert, truncate, update

This commit is contained in:
Björn Benouarets
2025-11-06 00:54:41 +01:00
parent e884c77c31
commit cd757c80f5
17 changed files with 600 additions and 31 deletions

31
utils/sql.go Normal file
View 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)
}