something like: https://godoc.org/github.com/jmoiron/sqlx#StructScan
And struct tags like this:
type TenantModule struct {
Id string `db:"id"`
Name string `db:"type"`
Channels Channel `json:"channels"`
}
type Channel struct {
Channels []string
}
Or this:
type TenantModule struct {
Id string `sql:"id"`
Name string `sql:"type"`
}
I didn't find any information on https://github.com/jackc/pgx/blob/master/query_test.go file and documentation.
There are only examples which scan into the basic data type like int, float
Please give an example of how to scan rows into a struct. Thanks
pgx does not have anything like sqlx. But you can use sqlx with pgx when pgx is used as a database/sql driver.
Also the sqlc in next version will do what you need albeit in a bit different way that you expect.
pgx does not have anything like sqlx. But you can use sqlx with pgx when pgx is used as a database/sql driver.
While this works, it is a somewhat annoying to have to drop down from sqlx.DB to pgx.Conn by AcquireConn() in order to use the very much faster bulk-copy (CopyFrom()). In libpq, you could feed a sqlx Prepare statement with the output of pq.CopyIn() in order do do bulk-inserts.
@mrdulin here is the library exactly for what you asked: https://github.com/georgysavva/scany
It's feature-rich and supports pgx native interface.
Disclaimer: I am the author of this library.
Most helpful comment
@mrdulin here is the library exactly for what you asked: https://github.com/georgysavva/scany
It's feature-rich and supports pgx native interface.
Disclaimer: I am the author of this library.