remove ctx, db stuff and use callbacks instead
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package sqimple
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"slices"
|
||||
@@ -10,8 +9,7 @@ import (
|
||||
|
||||
// https://www.sqlite.org/lang_delete.html
|
||||
type InsertStatement struct {
|
||||
Ctx context.Context
|
||||
DB *sql.DB
|
||||
execFunc func(Query) (sql.Result, error)
|
||||
|
||||
table InsertTable
|
||||
or string
|
||||
@@ -38,15 +36,16 @@ func (s *InsertStatement) Args() []any {
|
||||
}
|
||||
|
||||
func (s *InsertStatement) 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 *InsertStatement) ExecFunc(f func(Query) (sql.Result, error)) *InsertStatement {
|
||||
s.execFunc = f
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *InsertStatement) IsValid() bool {
|
||||
|
||||
Reference in New Issue
Block a user