This commit is contained in:
oneao committed 2026-04-24 22:37:52 +08:00
1 parent 46cbb2f50d
commit e3d765a9d4
15 files changed
+903 -190

No files matched your search

+8 -15
View File
@@ -7,32 +7,24 @@ import (
)
func (c *Client) Delete(ctx context.Context, table, keyField string, data map[string]any) error {
_, err := validateData(table, keyField, data)
keyVal, err := validateData(table, keyField, data)
if err != nil {
return err
}
where := make([]string, 0, len(data))
args := make([]any, 0, len(data))
i := 1
for k, v := range data {
where = append(where, fmt.Sprintf("%s = $%d", quoteCol(k), i))
args = append(args, v)
i++
}
sql := fmt.Sprintf(
"DELETE FROM %s WHERE %s",
"DELETE FROM %s WHERE %s = $1",
quoteTable(table),
strings.Join(where, " AND "),
quoteCol(keyField),
)
_, err = c.exec().Exec(ctx, sql, args...)
_, err = c.pool.Exec(ctx, sql, keyVal) // ⭐修复 exec
return err
}
func (c *Client) BatchDelete(ctx context.Context, table, keyField string, list []map[string]any) error {
if len(list) == 0 {
return fmt.Errorf("empty data")
}
@@ -44,6 +36,7 @@ func (c *Client) BatchDelete(ctx context.Context, table, keyField string, list [
)
for _, row := range list {
v, err := validateData(table, keyField, row)
if err != nil {
return err
@@ -61,6 +54,6 @@ func (c *Client) BatchDelete(ctx context.Context, table, keyField string, list [
strings.Join(in, ", "),
)
_, err := c.exec().Exec(ctx, sql, args...)
_, err := c.pool.Exec(ctx, sql, args...) // ⭐修复 exec
return err
}