add ctx/db to all query types

This commit is contained in:
2026-07-07 22:34:02 +01:00
parent f2ebd5b53f
commit f24f15a4f6
5 changed files with 87 additions and 0 deletions
+17
View File
@@ -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