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,6 +1,8 @@
package sqimple
import (
"context"
"database/sql"
"fmt"
"slices"
"strings"
@@ -8,6 +10,9 @@ import (
// https://www.sqlite.org/lang_delete.html
type InsertStatement struct {
Ctx context.Context
DB *sql.DB
table InsertTable
or string
@@ -32,6 +37,18 @@ func (s *InsertStatement) Args() []any {
return args
}
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()...)
}
return nil, ErrNoDatabase
}
func (s *InsertStatement) IsValid() bool {
if !s.table.IsValid() {
return false