-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
I'm wondering if it's possible to scan nested structs when the nested struct implements Scan and Value.
My database table definition is
create table test(
id serial not null constraint test_pkey primary key,
body jsonb,
insert_time timestamp with time zone default CURRENT_TIMESTAMP,
last_update_time timestamp with time zone default CURRENT_TIMESTAMP
);
My struct definitions are:
type Body struct {
One string
Two string
}
func (b Body) Scan(val interface{}) error {
return json.Unmarshal(val.([]byte), &b)
}
func (b Body) Value() (driver.Value, error) {
return json.Marshal(b)
}
type Wrapper struct {
ID int64 `db:"id"`
Body `db:"body"`
InsertTime time.Time `db:"insert_time"`
LastUpdateTime time.Time `db:"last_update_time"`
}
But the following code gives an error: non-struct dest type struct with >1 columns (4)
ws := []Wrapper{}
err = db.SelectContext(ctx, &ws, "SELECT * FROM test")
Am I trying to do something that's not possible, or do I have an error somewhere?
sfllaw, alranel, gmxu, unknwon and p12s
Metadata
Metadata
Assignees
Labels
No labels