From 2ce3d755bd8bb7c5317b118a8ea8d7bf9d98c3e9 Mon Sep 17 00:00:00 2001 From: Timon Ringwald Date: Tue, 6 Sep 2022 10:49:22 +0200 Subject: [PATCH] improved Delete --- delete.go | 10 ++++++++-- func_types.go | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/delete.go b/delete.go index 4f88af3..b06df44 100644 --- a/delete.go +++ b/delete.go @@ -1,5 +1,11 @@ package advsql -func Delete[T any](db *Database, query string, encoder func(v *T, decode ScanFunc) error) DeleteFunc[T] { - return DeleteFunc[T](Insert(db, query, encoder)) +func Delete[T any](db *Database, query string) DeleteFunc[T] { + prepareGlobal(db, query) + + return func(args ...interface{}) error { + s := db.stmt(query) + _, err := s.Exec(args...) + return err + } } diff --git a/func_types.go b/func_types.go index ae2f4da..4540b42 100644 --- a/func_types.go +++ b/func_types.go @@ -11,6 +11,6 @@ type QueryOneContextFunc[T any] func(ctx context.Context, args ...interface{}) * type InsertFunc[T any] func(v *T) error type UpdateFunc[T any] func(v *T) error -type DeleteFunc[T any] func(v *T) error +type DeleteFunc[T any] func(args ...interface{}) error type ScanFunc = func(args ...interface{}) error