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) -// }