pg_graphqlPostgreSQL 的 GraphQL 支持

联合创作 · 2023-10-01 00:07

pg_graphql 支持使用 GraphQL 查询现有的 PostgreSQL 数据库,提供了 SQL 模式 -> GraphQL 模式反射引擎和关联的 GraphQL 查询 -> SQL 查询转译器,任何可以连接到 PostgreSQL 的编程语言都可以通过 GraphQL 查询数据库,而无需额外的服务器、进程或库。

SQL 架构

create table account(
    id serial primary key,
    email varchar(255) not null,
    encrypted_password varchar(255) not null,
    created_at timestamp not null,
    updated_at timestamp not null
);

create table blog(
    id serial primary key,
    owner_id integer not null references account(id),
    name varchar(255) not null,
    description varchar(255),
    created_at timestamp not null,
    updated_at timestamp not null
);

create type blog_post_status as enum ('PENDING', 'RELEASED');

create table blog_post(
    id uuid not null default uuid_generate_v4() primary key,
    blog_id integer not null references blog(id),
    title varchar(255) not null,
    body varchar(10000),
    status blog_post_status not null,
    created_at timestamp not null,
    updated_at timestamp not null
);

转换为 GraphQL 模式,将每个表公开为一个可分页的集合,其关系由外键定义。

浏览 5
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报