嵌套嵌入资源

Nested embedded resources

我是 postgREST 新手。我已经设置好了,它在我的数据库中运行良好。我正在浏览文档,我想我可以使用 Resource Embedding,但我不知道如何让它以嵌套方式工作。

我的架构包含类似于以下的表:

create table ta (
    a_id integer primary key,
    a_desc varchar(50)
);

create table tb (
    b_id integer primary key,
    a_id integer not null,
    b_desc varchar(50),
    constraint tb_fk1 foreign key (a_id) references ta(a_id)
);

create table tc (
    c_id integer primary key,
    b_id integer not null,
    c_desc varchar(50),
    constraint tc_fk1 foreign key (b_id) references tb(b_id)
);

insert into ta values (1, 'a1');

insert into tb values (1, 1, 'b1');
insert into tb values (2, 1, 'b2');

insert into tc values (1, 1, 'c1');
insert into tc values (2, 1, 'c2');
insert into tc values (3, 2, 'c3');
insert into tc values (4, 2, 'c4');

资源嵌入在我 select ta 和 tb:

时有效
localhost:3000/ta?select=*,tb(*)

[
    {
        "a_id": 1,
        "a_desc": "a1",
        "tb": [
            {
                "b_id": 1,
                "a_id": 1,
                "b_desc": "b1"
            },
            {
                "b_id": 2,
                "a_id": 1,
                "b_desc": "b2"
            }
        ]
    }
]

它也适用于 tb 和 tc:

localhost:3000/tb?select=*,tc(*)
[
    {
        "b_id": 1,
        "a_id": 1,
        "b_desc": "b1",
        "tc": [
            {
                "c_id": 1,
                "b_id": 1,
                "c_desc": "c1"
            },
            {
                "c_id": 2,
                "b_id": 1,
                "c_desc": "c2"
            }
        ]
    },
    {
        "b_id": 2,
        "a_id": 1,
        "b_desc": "b2",
        "tc": [
            {
                "c_id": 3,
                "b_id": 2,
                "c_desc": "c3"
            },
            {
                "c_id": 4,
                "b_id": 2,
                "c_desc": "c4"
            }
        ]
    }
]

但我不知道如何让它从 ta 到 tc 工作,有点结合这两个查询。

有谁知道我怎样才能做到这一点?最好使用查询字符串,但也可以使用视图或存储过程。

提前感谢您对此提供的任何帮助。

PS:使用 Potstgres 12 和 postgREST 7

对于嵌套资源嵌入,你可以这样做:

GET localhost:3000/ta?select=*,tb(*,tc(*))