Skip to content

Commit

Permalink
add new methods for DB to return Row or Rows
Browse files Browse the repository at this point in the history
  • Loading branch information
xgfone committed May 29, 2024
1 parent 102a0ce commit e1d9026
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
14 changes: 14 additions & 0 deletions dml_select_bind_row.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ import (
"time"
)

// QueryRowx executes the row query sql statement and returns Row instead of *sql.Row.
func (db *DB) QueryRowx(query string, args ...interface{}) Row {
return db.QueryRowxContext(context.Background(), query, args...)
}

// QueryRowxContext executes the row query sql statement and returns Row instead of *sql.Row.
func (db *DB) QueryRowxContext(ctx context.Context, query string, args ...interface{}) Row {
query, args, err := db.Intercept(query, args)
if err != nil {
panic(err)
}
return Row{Row: getDB(db).QueryRowContext(ctx, query, args...)}
}

// BindRow is equal to b.BindRowContext(context.Background(), dest...).
func (b *SelectBuilder) BindRow(dest ...interface{}) error {
return b.BindRowContext(context.Background(), dest...)
Expand Down
15 changes: 15 additions & 0 deletions dml_select_bind_rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ import (

var DefaultSliceCap = 8

// QueryRows executes the query sql statement and returns Rows instead of *sql.Rows.
func (db *DB) QueryRows(query string, args ...interface{}) (Rows, error) {
return db.QueryRowsContext(context.Background(), query, args...)
}

// QueryRowsContext executes the query sql statement and returns Rows instead of *sql.Rows.
func (db *DB) QueryRowsContext(ctx context.Context, query string, args ...interface{}) (rows Rows, err error) {
if query, args, err = db.Intercept(query, args); err == nil {
var _rows *sql.Rows
_rows, err = getDB(db).QueryContext(ctx, query, args...)
rows.Rows = _rows
}
return
}

// Query builds the sql and executes it.
func (b *SelectBuilder) Query() (Rows, error) {
return b.QueryContext(context.Background())
Expand Down

0 comments on commit e1d9026

Please sign in to comment.