add ctx/db to all query types
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
package sqimple
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// https://www.sqlite.org/lang_update.html
|
||||
type UpdateStatement struct {
|
||||
Ctx context.Context
|
||||
DB *sql.DB
|
||||
|
||||
table UpdateTable
|
||||
or string
|
||||
|
||||
@@ -31,6 +36,18 @@ func (s *UpdateStatement) Args() []any {
|
||||
return args
|
||||
}
|
||||
|
||||
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()...)
|
||||
}
|
||||
|
||||
return nil, ErrNoDatabase
|
||||
}
|
||||
|
||||
func (s *UpdateStatement) IsValid() bool {
|
||||
if !s.table.IsValid() {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user