georgysavva / scany

Library for scanning data from a database into Go structs and more
MIT License
1.29k stars 68 forks source link

pgxscan for pgx QueryRow (pgx.Row) support #44

Closed benedictjohannes closed 2 years ago

benedictjohannes commented 3 years ago

I've read the source for pgxscan, and I haven't found the package supporting scanning pgx.Row (one returned from (p *pgx.Pool) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row).

Do you plan to add this into the library?

As for now, I've only used the Scan or ScanRow functions as opposed to the "higher level" function Select or Get. Reading further into the dbscan package, it seems to me that the various checks (like checking for no multiple rows) would make adding this implementation non trivial. However, having the single return pgx.Row and needing only to check only one error code can save a lot of coding.

Thank you in advanced.

georgysavva commented 3 years ago

Hello. You can use ScanOne or Get to scan a single row. Scany doesn't work with pgx.Row type because id doesn't expose all needed information to do the mapping. See this comment https://github.com/georgysavva/scany/issues/28#issuecomment-800717637

georgysavva commented 3 years ago

I added a corresponding doc section https://github.com/georgysavva/scany/blob/d28f8d85a1bd4b5684e80d79dd3cbab5dce153af/dbscan/doc.go#L195-L199