mirror of
https://github.com/ent/ent.git
synced 2026-05-28 09:49:08 +03:00
dialect/sql: wraps the sql.Rows with ColumnScanner interface
This commit is contained in:
committed by
Ariel Mashraki
parent
123930c362
commit
899e9f0e50
@@ -132,7 +132,7 @@ var _ dialect.Driver = (*Driver)(nil)
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
// Rows wraps the sql.Rows to avoid locks copy.
|
// Rows wraps the sql.Rows to avoid locks copy.
|
||||||
Rows struct{ *sql.Rows }
|
Rows struct{ ColumnScanner }
|
||||||
// Result is an alias to sql.Result.
|
// Result is an alias to sql.Result.
|
||||||
Result = sql.Result
|
Result = sql.Result
|
||||||
// NullBool is an alias to sql.NullBool.
|
// NullBool is an alias to sql.NullBool.
|
||||||
@@ -165,3 +165,15 @@ func (n *NullScanner) Scan(value interface{}) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ColumnScanner is the interface that wraps the standard
|
||||||
|
// sql.Rows methods used for scanning database rows.
|
||||||
|
type ColumnScanner interface {
|
||||||
|
Close() error
|
||||||
|
ColumnTypes() ([]*sql.ColumnType, error)
|
||||||
|
Columns() ([]string, error)
|
||||||
|
Err() error
|
||||||
|
Next() bool
|
||||||
|
NextResultSet() bool
|
||||||
|
Scan(dest ...interface{}) error
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,15 +12,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ColumnScanner is the interface that wraps the
|
|
||||||
// four sql.Rows methods used for scanning.
|
|
||||||
type ColumnScanner interface {
|
|
||||||
Next() bool
|
|
||||||
Scan(...interface{}) error
|
|
||||||
Columns() ([]string, error)
|
|
||||||
Err() error
|
|
||||||
}
|
|
||||||
|
|
||||||
// ScanOne scans one row to the given value. It fails if the rows holds more than 1 row.
|
// ScanOne scans one row to the given value. It fails if the rows holds more than 1 row.
|
||||||
func ScanOne(rows ColumnScanner, v interface{}) error {
|
func ScanOne(rows ColumnScanner, v interface{}) error {
|
||||||
columns, err := rows.Columns()
|
columns, err := rows.Columns()
|
||||||
|
|||||||
Reference in New Issue
Block a user