diff --git a/docs/contract.md b/docs/contract.md index 57dd7b6..b56530b 100644 --- a/docs/contract.md +++ b/docs/contract.md @@ -34,6 +34,9 @@ 所有 SELECT **必须显式列出列名**。原因:react 版库(TypeORM `synchronize`)只有 entity 里的列, 官方 DDL 有 30~60 列。显式投影让本仓后端**能开 react 建出来的库**,且响应 JSON 与 react 逐字相同。 +🔴 **每列还要显式 `AS `**(camelCase,见 §4)——`row_to_json` 用**列的输出名**当 JSON 键。 +写成 `AS creator_time` 会得到 `"creator_time"`,react 是 `"creatorTime"` ⇒ 前端读不到字段。 + ### R1.5 numeric 列必须序列化成 JSON 字符串 `f_price` 回显 `"9.90"`,不是 `9.9`。手段:**在 SQL 投影里就 cast 成 text**(`f_price::text AS price`)。 `int` 列(`f_delete_mark` / `f_stock` / `f_is_administrator`)**保持数字**。 @@ -221,9 +224,13 @@ pub fn valid_column(name: &str) -> Option; **写入一律 UTC 朴素时间**;**读出投影成 JS ISO 串**: ```sql -to_char(f_creator_time, 'YYYY-MM-DD"T"HH24:MI:SS') || 'Z' AS creator_time +to_char(f_creator_time, 'YYYY-MM-DD"T"HH24:MI:SS') || 'Z' AS creatorTime ``` +🔴 **投影的 `AS` 别名必须就是 §4 的 JSON 键(camelCase)** —— +`row_to_json` 用的是**列的输出名**当 JSON 键。别名写成 `AS creator_time` 会得到 `"creator_time"`, +与 react 的 `"creatorTime"` **对不上** ⇒ 前端所有字段读不到。**每一列**都要显式 `AS `。 + ### 5.3 精确列清单(**投影真源**) 🔴 **SELECT 的列必须逐字取自下表** —— 这是 react 版 entity 的**精确列集**(`~/Desktop/workspace/skills/ssw-jnpf-lite-react/src/backend/src/**/*.entity.ts`), @@ -232,6 +239,12 @@ to_char(f_creator_time, 'YYYY-MM-DD"T"HH24:MI:SS') || 'Z' AS creator_time 格式:`列名 → JSON 键`。列顺序 = react entity 的声明顺序。 +🔴 **投影写法**:每列都写成 `f_xxx AS `(**别名 = 右边的 JSON 键,camelCase**)。 +`row_to_json` 用的就是别名当 JSON 键 —— 别名写错 ⇒ 响应键名对不上 react。 +例:`f_real_name AS realName`、`f_is_administrator AS isAdministrator`、 +`f_creator_time` ⇒ `to_char(f_creator_time, 'YYYY-MM-DD"T"HH24:MI:SS') || 'Z' AS creatorTime`、 +`f_price` ⇒ `f_price::text AS price`(numeric 必须是字符串)。 + **base_authorize**(9 列) ``` f_id → id f_tenant_id → tenantId f_object_type → objectType