georgysavva / scany

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

Question: Scan all - missing a field from struct #137

Closed marko995 closed 1 month ago

marko995 commented 1 month ago

Hey, I have a question, I am adding jsonb field to a table, but I also want not to change DAO to support that field everywhere. Is it possible not to panic if SELECT returns one field that is missing from a struct?

for example, I have two structs:

type UserWithJson struct {
    id int
   ....
    specificUserData jsonb
}

type User struct {
    id int
   ....
}

and table:

CREATE TABLE users(
  id int primary key,
   ....
  specific_user_data jsonb
);

When I use User struct in pgxscan.Select, panic happens, is it possible to avoid this except by using UserWithJson?