I have three following tables:
create table A (
a_id varchar(256) not null unique,
a_name varchar(256)
);
create table B (
b_id varchar(256) not null,
b_a_id varchar(256) not null,
b_name varchar(256),
FOREIGN KEY (b_a_id) REFERENCES a (a_id)
);
create table C (
c_id varchar(256) not null,
c_a_id varchar(256) not null,
c_name varchar(256),
FOREIGN KEY (c_a_id) REFERENCES a (a_id)
);
insert into A(a_id, a_name) values('1234', 'a_name_1');
insert into B(b_id, b_a_id, b_name) values('B1','1234', 'b_name_1');
insert into B(b_id, b_a_id, b_name) values('B2','1234', 'b_name_2');
insert into C(c_id, c_a_id, c_name) values('C1','1234', 'c_name_1');
insert into C(c_id, c_a_id, c_name) values('C2','1234', 'c_name_2');
insert into C(c_id, c_a_id, c_name) values('C3','1234', 'c_name_3');
I have the following Structs in golang:
type A struct {
a_id string `db:"a_id"`
a_name string `db:"a_name"`
b *B `db:"b"`
c *C `db:"c"`
}
type B struct {
b_id string `db:"b_id"`
b_name string `db:"b_name"`
b_a_id string `db:"b_a_id"`
}
type C struct {
c_id string `db:"c_id"`
c_name string `db:"c_name"`
c_a_id string `db:"c_a_id"`
}
I want to scan the rows I get from executing the join query:
SELECT * from A INNER JOIN B ON a_id=b_a_id inner join C on c_a_id=a_id;
Into Struct A using rows.StructScan() in Golang but I am not able to do that. How Do I scan a join query result into a nested struct and I don't want to individually scan each column as there are a lot of columns as a result of the join query going forward.