add ctx/db to all query types
This commit is contained in:
@@ -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"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user