Documentation ¶
Overview ¶
Package `ydbscan` allows scanning data into Go structs and other composite types, when working with `ydb` library native interface.
Essentially, `ydbscan` is a wrapper around github.com/georgysavva/scany/v2/dbscan package. ydbscan connects github.com/ydb-platform/ydb-go-sdk native interface with dbscan functionality. It contains adapters that are meant to work with result.BaseResult and proxy all calls to dbscan. ydbscan provides all capabilities available in dbscan.
Querying rows ¶
`ydbscan` can query rows and work with table.TransactionActor, table.Session directly. To support this it has two high-level functions Select & Get.
`ydbscan` only works with `github.com/ydb-platform/ydb-go-sdk/v3`. So the import path of your ydb must be: "github.com/ydb-platform/ydb-go-sdk/v3".
Index ¶
- Variables
- func NewDBScanAPI(opts ...dbscan.APIOption) (*dbscan.API, error)
- func ScanRow(dst any, result result.Result) error
- type API
- func (a *API) Get(ctx context.Context, tx *table.TransactionControl, db SessionQuerier, dst any, ...) (table.Transaction, error)
- func (a *API) GetTx(ctx context.Context, db TransactionQuerier, dst any, query string, ...) error
- func (a *API) NewRowScanner(rows result.BaseResult) *RowScanner
- func (a *API) ScanAll(dst any, result result.BaseResult) error
- func (a *API) ScanOne(dst any, result result.BaseResult) error
- func (a *API) ScanRow(dst any, rows result.BaseResult) error
- func (a *API) Select(ctx context.Context, tx *table.TransactionControl, db SessionQuerier, dst any, ...) (table.Transaction, error)
- func (a *API) SelectTx(ctx context.Context, db TransactionQuerier, dst any, query string, ...) error
- type RowScanner
- type RowsAdapter
- type SessionQuerier
- type TransactionQuerier
Constants ¶
This section is empty.
Variables ¶
var DefaultAPI = mustNewAPI(mustNewDBScanAPI())
DefaultAPI is the default instance of API with all configuration settings set to default.
var ( // ErrNoRows occurs when rows are expected but none are returned. ErrNoRows = errors.New("no rows in result set") )
Functions ¶
func NewDBScanAPI ¶
NewDBScanAPI creates a new dbscan API object with default configuration settings for pgxscan.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API is a wrapper around the dbscan.API type. See dbscan.API for details.
func (*API) Get ¶
func (a *API) Get(ctx context.Context, tx *table.TransactionControl, db SessionQuerier, dst any, query string, params *table.QueryParameters) (table.Transaction, error)
Get is a high-level function that queries rows from Querier and calls the ScanOne function. See ScanOne for details.
func (*API) GetTx ¶
func (a *API) GetTx(ctx context.Context, db TransactionQuerier, dst any, query string, params *table.QueryParameters) error
GetTx is a high-level function that queries rows from Querier and calls the ScanOne function. See ScanOne for details.
func (*API) NewRowScanner ¶
func (a *API) NewRowScanner(rows result.BaseResult) *RowScanner
NewRowScanner returns a new RowScanner instance.
func (*API) ScanAll ¶
func (a *API) ScanAll(dst any, result result.BaseResult) error
ScanAll is a wrapper around the dbscan.ScanAll function. See dbscan.ScanAll for details.
func (*API) ScanOne ¶
func (a *API) ScanOne(dst any, result result.BaseResult) error
ScanOne is a wrapper around the dbscan.ScanOne function. See dbscan.ScanOne for details. If no rows are found it returns a pgx.ErrNoRows error.
func (*API) ScanRow ¶
func (a *API) ScanRow(dst any, rows result.BaseResult) error
ScanRow is a wrapper around the dbscan.ScanRow function. See dbscan.ScanRow for details.
func (*API) Select ¶
func (a *API) Select(ctx context.Context, tx *table.TransactionControl, db SessionQuerier, dst any, query string, params *table.QueryParameters) (table.Transaction, error)
Select is a high-level function that queries rows from Querier and calls the ScanAll function. See ScanAll for details.
type RowScanner ¶
type RowScanner struct {
*dbscan.RowScanner
}
RowScanner is a wrapper around the dbscan.RowScanner type. See dbscan.RowScanner for details.
func NewRowScanner ¶
func NewRowScanner(result result.Result) *RowScanner
NewRowScanner is a package-level helper function that uses the DefaultAPI object. See API.NewRowScanner for details.
type RowsAdapter ¶
type RowsAdapter struct {
// contains filtered or unexported fields
}
RowsAdapter makes pgx.Rows compliant with the dbscan.Rows interface. See dbscan.Rows for details.
func NewRowsAdapter ¶
func NewRowsAdapter(result result.BaseResult) *RowsAdapter
NewRowsAdapter returns a new RowsAdapter instance.
func (RowsAdapter) Close ¶
func (ra RowsAdapter) Close() error
Close implements the dbscan.Rows.Close method.
func (RowsAdapter) Columns ¶
func (ra RowsAdapter) Columns() ([]string, error)
Columns implements the dbscan.Rows.Columns method.
func (RowsAdapter) Err ¶
func (ra RowsAdapter) Err() error
Err return scanner error To handle errors, do not need to check after scanning each row It is enough to check after reading all Set
func (RowsAdapter) Next ¶
func (ra RowsAdapter) Next() bool
Next selects row in the current result set. It returns false if there are no more rows in the result set.
func (RowsAdapter) Scan ¶
func (ra RowsAdapter) Scan(dest ...any) error
Scan scans row with column names defined in namedValues
type SessionQuerier ¶
type SessionQuerier interface { Execute( ctx context.Context, tx *table.TransactionControl, query string, params *table.QueryParameters, opts ...options.ExecuteDataQueryOption, ) (table.Transaction, result.Result, error) }
SessionQuerier is an interface that is implemented by table.Session.
type TransactionQuerier ¶
type TransactionQuerier interface { Execute( ctx context.Context, query string, params *table.QueryParameters, opts ...options.ExecuteDataQueryOption, ) (result.Result, error) }
TransactionQuerier is an interface that is implemented by table.TransactionActor.