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
+29
View File
@@ -1,12 +1,17 @@
package sqimple
import (
"context"
"database/sql"
"fmt"
"strings"
)
// https://www.sqlite.org/lang_select.html
type SelectQuery struct {
Ctx context.Context
DB *sql.DB
distinct bool
columns []Column
@@ -106,6 +111,30 @@ func (q *SelectQuery) OrderBy(defs ...string) *SelectQuery {
return q
}
func (q *SelectQuery) Query() (*sql.Rows, error) {
if q.DB != nil {
if q.Ctx != nil {
return q.DB.QueryContext(q.Ctx, q.String(), q.Args()...)
}
return q.DB.Query(q.String(), q.Args()...)
}
return nil, ErrNoDatabase
}
func (q *SelectQuery) QueryRow() *sql.Row {
if q.DB != nil {
if q.Ctx != nil {
return q.DB.QueryRowContext(q.Ctx, q.String(), q.Args()...)
}
return q.DB.QueryRow(q.String(), q.Args()...)
}
return nil
}
func (q *SelectQuery) String() string {
strs := []string{"select"}