-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Use a struct for named args #2406
Copy link
Copy link
Open
Description
Is your feature request related to a problem? Please describe.
When querying data with pgx, I can quite easily load the data into structs using the various RowTo functions.
However, when inserting data, I have to repeat field names a lot:
_, err := c.db.Exec(ctx, `
INSERT INTO foo (col)
VALUES (@col)
`, pgx.StrictNamedArgs{
"col": m.Col,
})
Describe the solution you'd like
A feature similar to (Strict)NamedArgs, but instead of passing a map, passing a struct with the appropriate struct tags:
type Foo struct {
Col string `db:"col"`
}
_, err := c.db.Exec(ctx, `
INSERT INTO foo (col)
VALUES (@col)
`, pgx.StructArgs(m))
Describe alternatives you've considered
None.
Additional context
None.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels