From f7bae81df7b2a7a4a2bfd39e924a697b7a74c56f Mon Sep 17 00:00:00 2001 From: Timon Ringwald Date: Tue, 6 Sep 2022 10:42:09 +0200 Subject: [PATCH] added Delete --- delete.go | 5 +++++ func_types.go | 2 ++ stmt.go | 59 --------------------------------------------------- 3 files changed, 7 insertions(+), 59 deletions(-) create mode 100644 delete.go delete mode 100644 stmt.go diff --git a/delete.go b/delete.go new file mode 100644 index 0000000..4f88af3 --- /dev/null +++ b/delete.go @@ -0,0 +1,5 @@ +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)) +} diff --git a/func_types.go b/func_types.go index 5f00a7d..ae2f4da 100644 --- a/func_types.go +++ b/func_types.go @@ -11,4 +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 ScanFunc = func(args ...interface{}) error diff --git a/stmt.go b/stmt.go deleted file mode 100644 index d759cc2..0000000 --- a/stmt.go +++ /dev/null @@ -1,59 +0,0 @@ -package advsql - -// import ( -// "database/sql" -// ) - -// type Stmt[M any] struct { -// stmt *sql.Stmt -// scan func(Scanner) (*M, error) -// } - -// func NewStmt[M any](db *Database, query string, scan func(s Scanner) (*M, error)) (*Stmt[M], error) { -// s, err := db.db.Prepare(query) -// if err != nil { -// return nil, err -// } - -// stmt := Stmt[M]{ -// stmt: s, -// scan: scan, -// } -// db.closefuncs = append(db.closefuncs, stmt.Close) -// return &stmt, err -// } - -// func (stmt *Stmt[M]) Close() error { -// return stmt.stmt.Close() -// } - -// func (stmt *Stmt[M]) Many(args ...interface{}) (<-chan *M, error) { -// rows, err := stmt.stmt.Query(args...) -// if err != nil { -// return nil, err -// } - -// out := make(chan *M, 10) - -// go func() { -// defer rows.Close() -// defer close(out) - -// for rows.Next() { -// if v, err := stmt.scan(rows); err == nil { -// out <- v -// } -// } -// }() - -// return out, nil -// } - -// func (stmt *Stmt[M]) Single(args ...interface{}) (*M, error) { -// rows, err := stmt.stmt.Query(args...) -// if err != nil { -// return nil, err -// } -// defer rows.Close() -// return stmt.scan(rows) -// }