georgysavva / scany

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

NewApi doesn't support pgxscan #139

Closed sv-22 closed 3 weeks ago

sv-22 commented 3 weeks ago

NewApi and its options do not appear to work with pgxscan, only dbscan which would be ok if dbscan accepted pgx rows, but it doesn't. Which means we can't use any of the NewApi options like WithAllowUnknownColumns.

We are using pgx V5 and scany V2

Please confirm if it's intended behaviour, is it just lacking implementation or is it a bug?

Thanks.

sv-22 commented 3 weeks ago

Nevermind, I've figured out that it can be done like this

         dbScanApi, err := pgxscan.NewDBScanAPI(dbscan.WithAllowUnknownColumns(true))

    if err != nil {
        return err
    }

    api, err := pgxscan.NewAPI(dbScanApi)

    if err != nil {
        return err
    }

    err = api.Select(t.context, querier, dest, sqlString, args...)

I thought pgxscan would accept dbscan options directly, instead it expects a dbscan API.