feat(validation): Add check for necessary keys in field json

This commit is contained in:
Björn Benouarets
2025-11-06 01:01:15 +01:00
parent cd757c80f5
commit 1f5f07e624
3 changed files with 29 additions and 10 deletions

View File

@@ -8,7 +8,7 @@ import (
"git.secnex.io/secnex/pgson/utils"
)
func InsertManySQL(s *schema.Table, data []map[string]any) (string, error) {
func InsertManySQL(s *schema.Table, data []map[string]any, returning bool) (string, error) {
// Keep unquoted column names for data access
columnNames := make([]string, 0, len(data[0]))
for column := range data[0] {
@@ -48,9 +48,13 @@ func InsertManySQL(s *schema.Table, data []map[string]any) (string, error) {
}
query := fmt.Sprintf("INSERT INTO %s (%s) VALUES %s", utils.SQLQuoteIdent(s.Name), strings.Join(columns, ", "), strings.Join(values, ", "))
if returning {
// RETURNING the primary key
query += " RETURNING " + utils.SQLQuoteIdent(s.PrimaryKey)
}
return query, nil
}
func InsertSQL(s *schema.Table, data map[string]any) (string, error) {
return InsertManySQL(s, []map[string]any{data})
func InsertSQL(s *schema.Table, data map[string]any, returning bool) (string, error) {
return InsertManySQL(s, []map[string]any{data}, returning)
}