跳转到内容
EN

Supabase 兼容接口

(待译)

Database exposes its row API through Supabase client paths. Use a base URL ending in /supabase/<database_id>/, including the trailing slash, and a Praxis credential. Unlike Supabase, storage uses SQLite; define tables and fields through /database/v1, not SQL migrations, and do not expect Supabase Auth, RLS policies or realtime subscriptions. Auth, storage, realtime, functions and graphql service paths return 501 with x-should-retry=false. See the Database domain for supported concepts and differences.

使用官方 supabase-js 读写一个库中的表。

指南 →

基础地址

https://api.deepraxis.com/supabase/{database_id}/

部分 含义
{database_id} 建库返回的 ID;每个库使用自己的地址。
/ 保留末尾斜杠,supabase-js 才会保留库 ID 并追加 rest/v1。

API Key 用作 Authorization: Bearer 凭据;supabase-js 的第二个参数传同一 Key。以下示例在服务端运行。

import { createClient } from "@supabase/supabase-js";
const supabase = createClient(
`https://api.deepraxis.com/supabase/${process.env.DATABASE_ID}/`,
process.env.PRAXIS_API_KEY,
{ auth: { persistSession: false, autoRefreshToken: false } },
);

表端点

GET / HEAD / POST / PATCH / DELETE

/supabase/{database_id}/rest/v1/{table}

仅提供下列 PostgREST 子集。不支持的语法返回 HTTP 400,code 为 PGRST127;无效或未知参数可能返回 PGRST100。

过滤运算符

值 支持情况
eq 支持
neq 支持
gt 支持
gte 支持
lt 支持
lte 支持
like 支持
ilike 支持
in 支持
is 支持
cs 支持
cd 支持
ov 支持
fts 不支持
plfts 不支持
phfts 不支持
wfts 不支持
match 不支持
imatch 不支持
isdistinct 不支持
sl 不支持
sr 不支持
nxl 不支持
nxr 不支持
adj 不支持

Prefer

值 支持情况
return=minimal 支持
return=headers-only 支持
return=representation 支持
count=exact 支持
count=planned 部分支持
count=estimated 部分支持
resolution=merge-duplicates 支持
resolution=ignore-duplicates 支持
missing=default 部分支持
handling=strict 支持
handling=lenient 支持

Accept

值 支持情况
application/json 支持
*/* 支持
application/vnd.pgrst.object+json 支持
text/csv 不支持
application/geo+json 不支持
application/vnd.pgrst.plan* 不支持

查询语法

值 支持情况
not 支持
and/or/not.and/not.or 支持
JSON paths (->, ->>) 支持
aliases 支持
link embedding 支持
!field hint 支持
embedded filters/order/pagination 不支持
casts (::) 不支持
aggregates 不支持
spread (...) 不支持
!inner/!left 不支持
operator(any)/operator(all) 不支持

planned/estimated 当前返回精确计数;字段可以配置 default:批量插入中有的行提供、有的行缺失的列,带 missing=default 时缺失处取字段 default,否则按 PostgREST 写 null;所有行都未提供的列始终取 default(没有 default 时为 null)。cs/cd/ov 接收数组({a,b} 或 ["a"]);json 字段上的 cs/cd 还接受 JSON 对象,按 jsonb 包含判断,例如 meta=cs.{"color":"red"}(键值逐层包含);cs 还接受 JSON 标量,数组顶层含该元素即匹配,例如 meta=cs."a"。cs.{}/cd.{} 在 json 字段上是空对象,在数组字段上是空数组。一次 DELETE 删除的行之间互相引用不阻断删除,只要有引用者不在本次删除中就返回 409 23503。like/ilike 只适用于 string 字段与 ->> 文本路径,用在其他类型返回 400 42883。字符串按二进制序(区分大小写,大写在小写前)比较与排序,不支持按 lower() 排序;需要不区分大小写排序时,另存一个小写字段并按它排序。GET/HEAD 带 If-None-Match 且与当前 ETag 匹配时返回 304、无正文。不支持的 Accept 返回 406 PGRST107。upsert 仅接受 id 或单个 unique 字段。

Prefer 中的未知值默认忽略;handling=strict 时返回 400 PGRST122。单对象 Accept 恰好匹配一行时返回对象,否则返回 406 PGRST116。 其他不支持的 Accept 返回 406 PGRST107。

未开放服务

路径 HTTP code
/supabase/{database_id}/auth/v1/{+path} 501 not_implemented
/supabase/{database_id}/storage/v1/{+path} 501 not_implemented
/supabase/{database_id}/realtime/v1/{+path} 501 not_implemented
/supabase/{database_id}/functions/v1/{+path} 501 not_implemented
/supabase/{database_id}/graphql/v1/{+path} 501 not_implemented

这些服务返回 x-should-retry: false。它们的错误体与表端点不同,只有 code 和 message。

错误码表与错误体