remove ctx, db stuff and use callbacks instead

This commit is contained in:
2026-07-08 01:34:52 +01:00
parent 6e8fdbba1e
commit 86468a85c9
4 changed files with 57 additions and 45 deletions
+9 -10
View File
@@ -1,7 +1,6 @@
package sqimple
import (
"context"
"database/sql"
"slices"
"strings"
@@ -9,8 +8,7 @@ import (
// https://www.sqlite.org/lang_update.html
type UpdateStatement struct {
Ctx context.Context
DB *sql.DB
execFunc func(Query) (sql.Result, error)
table UpdateTable
or string
@@ -37,15 +35,16 @@ func (s *UpdateStatement) Args() []any {
}
func (s *UpdateStatement) Exec() (sql.Result, error) {
if s.DB != nil {
if s.Ctx != nil {
return s.DB.ExecContext(s.Ctx, s.String(), s.Args()...)
}
return s.DB.Exec(s.String(), s.Args()...)
if s.execFunc != nil {
return s.execFunc(s)
}
return nil, ErrNoDatabase
return nil, nil
}
func (s *UpdateStatement) ExecFunc(f func(Query) (sql.Result, error)) *UpdateStatement {
s.execFunc = f
return s
}
func (s *UpdateStatement) IsValid() bool {