added Delete
This commit is contained in:
parent
3f8e334dbb
commit
f7bae81df7
5
delete.go
Normal file
5
delete.go
Normal file
@ -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))
|
||||
}
|
@ -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
|
||||
|
59
stmt.go
59
stmt.go
@ -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)
|
||||
// }
|
Loading…
Reference in New Issue
Block a user