feat(sql): Add new DML (DELETE, UPDATE)
This commit is contained in:
28
build/delete.go
Normal file
28
build/delete.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"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)
|
||||
log.Printf("DDL: %s", ddl)
|
||||
return &ddl, nil
|
||||
}
|
||||
Reference in New Issue
Block a user