28 lines
564 B
Go
28 lines
564 B
Go
package build
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.secnex.io/secnex/pgson/schema"
|
|
"git.secnex.io/secnex/pgson/sql"
|
|
)
|
|
|
|
func Delete(s *schema.Table, where map[string]any) (*string, error) {
|
|
if err := sql.ValidateIdent(s.Name); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if len(where) == 0 {
|
|
return nil, fmt.Errorf("WHERE clause is required for DELETE to prevent accidental deletion of all rows")
|
|
}
|
|
|
|
whereClause, err := sql.BuildWhereClause(where)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ddl := fmt.Sprintf(sql.DML_DELETE, sql.QuoteIdent(s.Name), whereClause)
|
|
|
|
return &ddl, nil
|
|
}
|