An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:memo: Add API endpoints doc for Database https://github.com/siyuan-note/siyuan/issues/11130
Daniel3c58a13a1804
diff --git a/API.ja.md b/API.ja.mdindex 2d7b5dd6a7..5e001dfd55 100644--- a/API.ja.md+++ b/API.ja.md@@ -40,6 +40,22 @@* [属性](#属性)* [ブロック属性を設定](#ブロック属性を設定)* [ブロック属性を取得](#ブロック属性を取得)+* [データベース](#データベース)+ * [レンダリング](#レンダリング)+ * [取得](#取得)+ * [主キー値を取得](#主キー値を取得)+ * [検索](#検索)+ * [セル値を設定](#セル値を設定)+ * [アイテムを追加](#アイテムを追加)+ * [アイテムを削除](#アイテムを削除)+ * [レイアウトを切り替え](#レイアウトを切り替え)+ * [グループ化を設定](#グループ化を設定)+ * [フィルターとソートを取得](#フィルターとソートを取得)+ * [フィルターとソートを設定](#フィルターとソートを設定)+ * [フィールドを追加](#フィールドを追加)+ * [フィールドを削除](#フィールドを削除)+ * [グローバルのフィールドソートを設定](#グローバルのフィールドソートを設定)+ * [ビュー内のフィールドソートを設定](#ビュー内のフィールドソートを設定)* [SQL](#SQL)* [SQLクエリを実行](#SQLクエリを実行)* [トランザクションをフラッシュ](#トランザクションをフラッシュ)@@ -1572,3 +1588,840 @@```* `data`: ミリ秒精度++## データベース++データベース(内部では「属性ビュー」)は、フィールド(列)とアイテム(行)として構造化データを格納します。各データベースは `avID` で識別され、1 つ以上のデータベースブロック(`blockID`)を通じてドキュメントに埋め込めます。1 つのデータベースは複数の異なるレイアウトタイプのビュー(`viewID`)を持てます:`table`(テーブル)、`gallery`(ギャラリー)、`kanban`(カンバン)。++フィールドタイプ(`keyType`)は以下の通りです:++| 値 | 説明 |+|-------------|------------------------|+| `block` | 主キー(紐づくブロック)|+| `text` | テキスト |+| `number` | 数値 |+| `date` | 日付 |+| `select` | 単一選択 |+| `mSelect` | 複数選択 |+| `url` | URL |+| `email` | メール |+| `phone` | 電話 |+| `mAsset` | アセット |+| `template` | テンプレート |+| `created` | 作成日時 |+| `updated` | 更新日時 |+| `checkbox` | チェックボックス |+| `relation` | 関連 |+| `rollup` | ロールアップ |+| `lineNumber`| 行番号 |++### レンダリング++* `/api/av/renderAttributeView`+* パラメータ++ ```json+ {+ "id": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "viewID": "",+ "page": 1,+ "pageSize": 50,+ "query": "",+ "groupPaging": {},+ "createIfNotExist": true+ }+ ```++ * `id`: データベース ID+ * `blockID`: このデータベースを埋め込むデータベースブロック。アクティブなビューや公開権限の解決に使用します。独立したデータベースをレンダリングする場合は省略します+ * `viewID`: レンダリングするビュー。省略時は現在のビュー(`viewID` フィールド)を使用+ * `page`: ページ番号(1 始まり)。デフォルトは `1`+ * `pageSize`: 1 ページあたりのアイテム数。`-1` または省略時はビューのデフォルト(`50`)を使用+ * `query`: 主キー値に対する任意の全文フィルターキーワード+ * `groupPaging`: グループ化(カンバン)ビューの任意のページング設定+ * `createIfNotExist`: `true`(デフォルト)の場合、データベースにビューが無ければデフォルトビューを作成+* 戻り値(実際のレスポンス、テーブルレイアウト、1 行を表示):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "name": "API テスト",+ "id": "20240118120204-kwyzf77",+ "viewType": "table",+ "viewID": "20240118120204-7rnmyc1",+ "isMirror": false,+ "views": [+ {+ "id": "20240118120204-7rnmyc1",+ "icon": "",+ "name": "テーブル",+ "desc": "",+ "hideAttrViewName": false,+ "type": "table",+ "pageSize": 50+ }+ ],+ "view": {+ "id": "20240118120204-7rnmyc1",+ "icon": "",+ "name": "テーブル",+ "desc": "",+ "hideAttrViewName": false,+ "filters": [],+ "sorts": [],+ "group": null,+ "pageSize": 50,+ "showIcon": true,+ "wrapField": false,+ "groupFolded": false,+ "groupHidden": 0,+ "columns": [+ {+ "id": "20240118120204-w6cggab",+ "name": "主キー",+ "type": "block",+ "icon": "",+ "wrap": false,+ "hidden": false,+ "desc": "",+ "calc": null,+ "numberFormat": "",+ "template": "",+ "pin": false,+ "width": ""+ }+ ],+ "rows": [+ {+ "id": "20240118203831-fkfvvtx",+ "cells": [+ {+ "id": "20240118203911-xrg9obl",+ "value": {+ "id": "20240118203911-xrg9obl",+ "keyID": "20240118120204-w6cggab",+ "blockID": "20240118203831-fkfvvtx",+ "type": "block",+ "createdAt": 1706843791000,+ "updatedAt": 1706843791000,+ "block": {+ "id": "20240118203831-fkfvvtx",+ "content": "3",+ "created": 1706843791000,+ "updated": 1706843791000+ }+ },+ "valueType": "block",+ "color": "",+ "bgColor": ""+ }+ ]+ }+ ],+ "rowCount": 5+ }+ }+ }+ ```++ * `data.view`: レンダリングされたビューインスタンス。形状は `viewType` により異なります——`table` は `columns`/`rows`/`rowCount`、`gallery` は `columns`/`rows`、`kanban` は `columns`/`groups`(各グループ自体が `groupKey`/`groupValue` を持つビューインスタンス)を返します。`view` は `filters`/`sorts`/`group`/`showIcon`/`wrapField`/`groupFolded`/`groupHidden` も含みます。注意:有効なフィルター/グループ化により、`rowCount` > 0 でも `rows` が空になることがあります+ * `data.view.columns[]`: 各列は `id`/`name`/`type`/`icon`/`wrap`/`hidden`/`desc`/`calc`/`numberFormat`/`template`/`pin`/`width` を持ちます;`select`/`mSelect` 列はさらに `options` を含みます+ * `data.view.rows[].id`: **行 ID**(アイテム ID)。紐づく行の場合は紐づくブロック ID と同じです;独立行の場合は生成されたアイテム ID で、いかなるブロックとも異なります+ * `data.view.rows[].cells[].value`: `Value` オブジェクト——すべての value 形状は [セル値を設定](#セル値を設定) を参照。`createdAt`/`updatedAt` は int64 ミリ秒タイムスタンプ+ * `data.views`: 全ビューのメタデータ(行データなし)+ * `data.isMirror`: データベースブロックがデータベースのミラー(読み取り専用コピー)の場合 `true`++### 取得++* `/api/av/getAttributeView`+* パラメータ++ ```json+ {+ "id": "20240118120204-kwyzf77"+ }+ ```++ * `id`: データベース ID+* 戻り値(実際のレスポンス、トリム済み——`keyValues`/`views` 配列は省略):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "av": {+ "spec": 4,+ "id": "20240118120204-kwyzf77",+ "name": "API テスト",+ "keyValues": [+ {+ "key": {+ "id": "20240118120204-w6cggab",+ "name": "主キー",+ "type": "block",+ "icon": "",+ "desc": "",+ "numberFormat": "",+ "template": ""+ },+ "values": [+ {+ "id": "20240118203911-xrg9obl",+ "keyID": "20240118120204-w6cggab",+ "blockID": "20240118203831-fkfvvtx",+ "type": "block",+ "createdAt": 1706843791000,+ "updatedAt": 1706843791000,+ "block": {+ "id": "20240118203831-fkfvvtx",+ "content": "3",+ "created": 1706843791000,+ "updated": 1706843791000+ }+ }+ ]+ }+ ],+ "keyIDs": null,+ "viewID": "20240118120204-7rnmyc1",+ "views": [+ {+ "id": "20240118120204-7rnmyc1",+ "icon": "",+ "name": "テーブル",+ "hideAttrViewName": false,+ "desc": "",+ "pageSize": 50,+ "type": "table",+ "table": {+ "spec": 0,+ "id": "20240118120204-grokgmm",+ "showIcon": true,+ "wrapField": false,+ "columns": [+ {+ "id": "20240118120204-w6cggab",+ "wrap": false,+ "hidden": false,+ "pin": false,+ "width": ""+ }+ ],+ "rowIds": null+ },+ "itemIds": ["20240118203818-ct041hj", "20240118203855-sqzbja0", "20240118203831-fkfvvtx", "20240118203842-kc31ovy", "20240531235026-uiap07y"],+ "groupCreated": 0,+ "groupItemIds": null,+ "groupFolded": false,+ "groupHidden": 0,+ "groupSort": 0+ }+ ]+ }+ }+ }+ ```++ * `data.av`: 完全な `AttributeView` 定義——フィールド(`keyValues`)、フィールド順序(`keyIDs`、`null` の場合あり)、現在のビュー(`viewID`)、および全ビューの生のレイアウト設定(`table`/`gallery`/`kanban`)とアイテム順序(`itemIds`)。生の定義を返します(レンダリング後の行やページングを含まない);計算後の行データが必要な場合は [レンダリング](#レンダリング) を使用してください++### 主キー値を取得++* `/api/av/getAttributeViewPrimaryKeyValues`+* パラメータ++ ```json+ {+ "id": "20240118120204-kwyzf77",+ "keyword": "",+ "page": 1,+ "pageSize": 16+ }+ ```++ * `id`: データベース ID+ * `keyword`: 主キーテキストに対する任意の部分一致フィルター(大文字小文字を区別しない)+ * `page`: ページ番号(1 始まり)。デフォルトは `1`+ * `pageSize`: 1 ページあたりのアイテム数。`-1` または省略時は `16`。結果は `block.updated` の降順+* 戻り値(実際のレスポンス、1 値を表示):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "name": "API テスト",+ "blockIDs": ["20240118120201-kldj15t"],+ "rows": {+ "key": {+ "id": "20240118120204-w6cggab",+ "name": "主キー",+ "type": "block",+ "icon": "",+ "desc": "",+ "numberFormat": "",+ "template": ""+ },+ "values": [+ {+ "id": "20240118203911-xrg9obl",+ "keyID": "20240118120204-w6cggab",+ "blockID": "20240118203831-fkfvvtx",+ "type": "block",+ "createdAt": 1706843791000,+ "updatedAt": 1706843791000,+ "block": {+ "id": "20240118203831-fkfvvtx",+ "content": "3",+ "created": 1706843791000,+ "updated": 1706843791000+ }+ }+ ]+ }+ }+ }+ ```++ * `data.rows`: 主キー(`block`)フィールドとそのページングされた値を保持する `KeyValues` オブジェクト+ * `data.blockIDs`: このデータベースを参照する全データベースブロック(ミラー)の ID++### 検索++* `/api/av/searchAttributeView`+* パラメータ++ ```json+ {+ "keyword": "API",+ "excludes": []+ }+ ```++ * `keyword`: 検索キーワード(データベース名に一致)+ * `excludes`: 任意。結果から除外するデータベース ID のリスト+* 戻り値(実際のレスポンス):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "results": [+ {+ "avID": "20240118120204-kwyzf77",+ "avName": "API テスト",+ "viewName": "",+ "viewID": "",+ "viewLayout": "",+ "blockID": "20240118120201-kldj15t",+ "hPath": "正在跟进的问题/数据库/API",+ "children": [+ {+ "avID": "20240118120204-kwyzf77",+ "avName": "API テスト",+ "viewName": "テーブル",+ "viewID": "20240118120204-7rnmyc1",+ "viewLayout": "table",+ "blockID": "20240118120201-kldj15t",+ "hPath": "正在跟进的问题/数据库/API"+ }+ ]+ }+ ]+ }+ }+ ```++ * `data.results[]`: 各トップレベル結果は `avID` ごとにデータベースを集約します;その `children[]` が各ビュー(`viewName`/`viewID`/`viewLayout`)を列挙します++### セル値を設定++1 つのセル(1 行の 1 フィールド)を更新します。セル値の主要な書き込みエンドポイントです。リクエストの `value` はフィールドの `keyType` に応じた部分 `Value` オブジェクトです。主な value の形状は以下の通りです:++| `keyType` | `value` の形状 |+|------------|----------------------------------------------------------------------------------------------------------------------|+| `block` | `{"block": {"content": "1行目", "id": "<紐づくブロックID>"}, "isDetached": false}` |+| `text` | `{"text": {"content": "テキスト"}}` |+| `number` | `{"number": {"content": 42, "isNotEmpty": true}}`(クリアは `{"isNotEmpty": false}`) |+| `date` | `{"date": {"content": 1676042451000, "isNotEmpty": true}}`(ミリ秒タイムスタンプ) |+| `select` | `{"mSelect": [{"content": "完了", "color": "1"}]}`(最大1つ) |+| `mSelect` | `{"mSelect": [{"content": "A", "color": "1"}, {"content": "B", "color": "2"}]}` |+| `url` | `{"url": {"content": "https://siyuan.com"}}` |+| `email` | `{"email": {"content": "[email protected]"}}` |+| `phone` | `{"phone": {"content": "1234567890"}}` |+| `checkbox` | `{"checkbox": {"checked": true}}` |++> ⚠️ `itemID` は**行 ID**([レンダリング](#レンダリング) が返す `rows[].id`)です。紐づく行の場合は行 ID は紐づくブロック ID と等しく、独立行の場合は生成されたアイテム ID です。誤った ID を渡すと、値はレンダリングされたセルに現れない孤立データとして保存されます。++* `/api/av/setAttributeViewBlockAttr`+* パラメータ++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "keyID": "20240531232156-ahsyx8l",+ "itemID": "20240118203831-fkfvvtx",+ "value": {+ "type": "number",+ "number": {+ "content": 42,+ "isNotEmpty": true+ }+ }+ }+ ```++ * `avID`: データベース ID+ * `keyID`: フィールド ID(更新対象の列)+ * `itemID`: **行 ID**([レンダリング](#レンダリング) が返す `rows[].id`)。従来の `rowID` パラメータは非推奨で 2026-12-01 以降に削除されるため、`itemID` を使用してください+ * `value`: 部分 `Value` オブジェクト(上記表を参照)。未知または未サポートのキーは無視されます+* 戻り値(実際のレスポンス、数値):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "value": {+ "id": "20240531235048-4zisj1p",+ "keyID": "20240531232156-ahsyx8l",+ "blockID": "20240118203831-fkfvvtx",+ "type": "number",+ "createdAt": 1717170648596,+ "updatedAt": 1781610266432,+ "number": {+ "content": 42,+ "isNotEmpty": true,+ "format": "",+ "formattedContent": "42"+ }+ }+ }+ }+ ```++ * `data.value`: 更新後に正規化された値(`number.formattedContent` などの計算フィールドを含む)。リクエストペイロードを再送せず、この戻り値で UI を更新してください++### アイテムを追加++1つ以上のアイテム(行)を追加します。各ソースは既存ブロックを紐づける(`isDetached: false`)か、ビュー内にのみ存在する独立行を作成(`isDetached: true`)できます。++* `/api/av/addAttributeViewBlocks`+* パラメータ++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "viewID": "",+ "groupID": "",+ "previousID": "",+ "srcs": [+ {+ "id": "20240118120201-kldj15t",+ "isDetached": false,+ "content": "新しい行"+ }+ ],+ "ignoreDefaultFill": false+ }+ ```++ * `avID`: データベース ID+ * `blockID`: このデータベースを所有するデータベースブロック(ターゲットビュー/グループの解決に使用)+ * `viewID`: ターゲットビュー。省略時は現在のビューを使用+ * `groupID`: カンバンビューのターゲットグループ ID。テーブル/ギャラリーでは省略可+ * `previousID`: このアイテム ID の後に挿入。空の場合は末尾に追加+ * `srcs[].id`: ブロックを紐づける場合(`isDetached: false`)、紐づけるブロック ID。ノード ID 形式である必要があります+ * `srcs[].isDetached`: `true` で独立行を作成、`false` で既存ブロックを紐づけ+ * `srcs[].content`: 主キーの表示テキスト(`isDetached: true` の場合、または紐づくブロックの内容を上書きする場合に使用)+ * `srcs[].itemID`: 任意。アイテム ID を明示指定。省略時は自動生成+ * `ignoreDefaultFill`: `true` の場合、フィルター/グループフィールドへのデフォルト値の自動入力をスキップ+* 戻り値++ ```json+ {+ "code": 0,+ "msg": "",+ "data": null+ }+ ```++ * このエンドポイントは `null` を返します。成功後、[レンダリング](#レンダリング) を呼び出して更新された行(セル更新に必要な新しい行 ID を含む)を取得してください++### アイテムを削除++1つ以上のアイテム(行)を削除します。独立行は削除され、紐づくブロックは紐付け解除されます(元のドキュメントブロックは削除されません)。++* `/api/av/removeAttributeViewBlocks`+* パラメータ++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "srcIDs": ["20240118203831-fkfvvtx"]+ }+ ```++ * `avID`: データベース ID+ * `srcIDs`: 削除する行 ID([レンダリング](#レンダリング) が返す `rows[].id`)のリスト+* 戻り値++ ```json+ {+ "code": 0,+ "msg": "",+ "data": null+ }+ ```++### レイアウトを切り替え++現在のビューのレイアウトタイプを `table`(テーブル)、`gallery`(ギャラリー)、`kanban`(カンバン)の間で切り替えます。成功時、サーバーはビューを再レンダリングして返します([レンダリング](#レンダリング) と同じ形状)。++* `/api/av/changeAttrViewLayout`+* パラメータ++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "layoutType": "kanban"+ }+ ```++ * `avID`: データベース ID+ * `blockID`: このビューを所有するデータベースブロック+ * `layoutType`: ターゲットレイアウト——`table`、`gallery`、`kanban` のいずれか+* 戻り値:[レンダリング](#レンダリング) の戻り値と同じ形状。`kanban` に切り替えてグループが設定されている場合、`data.view` は `groups[]` 配列を持ちます;各グループはビューインスタンスで、`groupKey`、`groupValue`、およびカンバン固有フィールド(`coverFrom`、`cardAspectRatio`、`cardSize`、`fitImage`、`displayFieldName`、`fillColBackgroundColor`、`fields`)を含みます++### グループ化を設定++カンバンビューのグループ化ルールを設定またはクリアします。`group.field` が空の場合、グループ化を削除します。成功時、サーバーはビューを再レンダリングして返します。++* `/api/av/setAttrViewGroup`+* パラメータ++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "group": {+ "field": "20240118203822-io6ofxb",+ "method": 0,+ "order": 0,+ "hideEmpty": false+ }+ }+ ```++ * `avID`: データベース ID+ * `blockID`: このビューを所有するデータベースブロック+ * `group`: グループ化ルール+ * `group.field`: グループ化の基準フィールド(列)ID。空文字列でグループ化を削除+ * `group.method`: グループ化方式——`0` 値ごと、`1` 数値範囲、`2` 相対日付、`3` 日ごと、`4` 週ごと、`5` 月ごと、`6` 年ごと+ * `group.range`: 任意。`method` が `1`(数値範囲)の場合は必須:`{ "numStart": 0, "numEnd": 100, "numStep": 10 }`+ * `group.order`: グループの並び順——`0` 昇順、`1` 降順、`2` 手動、`3` 選択肢の順序に従う+ * `group.hideEmpty`: 空のグループを非表示にするか+* 戻り値:[レンダリング](#レンダリング) の戻り値と同じ形状++### フィルターとソートを取得++データベースブロックに紐づくビューの現在のフィルターおよびソートルールを返します。++* `/api/av/getAttributeViewFilterSort`+* パラメータ++ ```json+ {+ "id": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t"+ }+ ```++ * `id`: データベース ID+ * `blockID`: このビューを所有するデータベースブロック+* 戻り値(実際のレスポンス、フィルター/ソート未設定):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "filters": [],+ "sorts": []+ }+ }+ ```++ 設定後(実際に取得したレスポンス)、フィルターとソートは以下の形になります:++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "filters": [+ {+ "column": "20240118203822-io6ofxb",+ "operator": "=",+ "value": {+ "type": "select",+ "mSelect": [+ { "content": "完了", "color": "1" }+ ]+ }+ }+ ],+ "sorts": [+ {+ "column": "20240118120204-w6cggab",+ "order": "DESC"+ }+ ]+ }+ }+ ```++ * `data.filters`: `ViewFilter` の配列+ * `data.filters[].column`: フィルターが適用されるフィールド(列)ID+ * `data.filters[].operator`: フィルター演算子(下記の演算子表を参照)+ * `data.filters[].value`: フィルター値。`Value` オブジェクト(形状は [セル値を設定](#セル値を設定) を参照)+ * `data.filters[].relativeDate`: 任意。日付フィルターが使用する相対日時記述子(`{ "count": 7, "unit": 0, "direction": -1 }`、`unit`:`0` 日、`1` 週、`2` 月、`3` 年、`direction`:`-1` 前、`0` 今期、`1` 後)+ * `data.sorts`: `ViewSort` の配列+ * `data.sorts[].column`: ソートが適用されるフィールド(列)ID+ * `data.sorts[].order`: `ASC` または `DESC`++ フィルター演算子:++ | 値 | 説明 |+ |----------------------|------------------------|+ | `=` | 等しい |+ | `!=` | 等しくない |+ | `>` | より大きい |+ | `>=` | 以上 |+ | `<` | より小さい |+ | `<=` | 以下 |+ | `Contains` | 含む |+ | `Does not contains` | 含まない |+ | `Is empty` | 空である |+ | `Is not empty` | 空でない |+ | `Starts with` | 〜で始まる |+ | `Ends with` | 〜で終わる |+ | `Is between` | の間である |+ | `Is true` | 真(チェックボックス) |+ | `Is false` | 偽(チェックボックス) |++### フィルターとソートを設定++フィルターとソートは、変更がアンドゥ可能な編集トランザクションの一部であるため、トランザクションエンドポイント `/api/transactions`(複数形)を通じて永続化します。各ルール変更を `doOperations` エントリに包み、`action` を `setAttrViewFilters` または `setAttrViewSorts` とし、`data` フィールドに完全な新しい配列を指定します(ビューの既存ルールを完全に置き換えます)。++* `/api/transactions`+* パラメータ++ ```json+ {+ "reqId": 1781610129661,+ "app": "",+ "session": "",+ "transactions": [+ {+ "doOperations": [+ {+ "action": "setAttrViewFilters",+ "avID": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "data": [+ {+ "column": "20240118203822-io6ofxb",+ "operator": "=",+ "value": {+ "type": "select",+ "mSelect": [+ { "content": "完了", "color": "1" }+ ]+ }+ }+ ]+ },+ {+ "action": "setAttrViewSorts",+ "avID": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "data": [+ {+ "column": "20240118120204-w6cggab",+ "order": "DESC"+ }+ ]+ }+ ]+ }+ ]+ }+ ```++ * `reqId`: 必須。クライアントが生成したタイムスタンプ/ノンス(数値)。アンドゥ/リドゥ用にトランザクションをタグ付けします+ * `app` / `session`: 任意。結果の WebSocket プッシュをスコープし、他のクライアント/セッションがリフレッシュできるようにします+ * `transactions[].doOperations[]`: 置換するルールセットごとに1つの操作+ * `doOperations[].action`: `setAttrViewFilters` でフィルターを置換、`setAttrViewSorts` でソートを置換+ * `doOperations[].avID`: データベース ID+ * `doOperations[].blockID`: このビューを所有するデータベースブロック+ * `doOperations[].data`: 完全な新しい `ViewFilter` または `ViewSort` の配列(形状は [フィルターとソートを取得](#フィルターとソートを取得) を参照)。`[]` を渡してクリア+* 戻り値(実際のレスポンス、送信した操作をエコーし、サーバー割り当ての `timestamp` を付加):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": [+ {+ "timestamp": 1781610129661,+ "doOperations": [+ {+ "action": "setAttrViewFilters",+ "id": "",+ "avID": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "data": [+ {+ "column": "20240118203822-io6ofxb",+ "operator": "=",+ "value": {+ "type": "select",+ "mSelect": [{ "content": "完了", "color": "1" }]+ }+ }+ ]+ }+ ]+ }+ ]+ }+ ```++ * 呼び出し成功後、[フィルターとソートを取得](#フィルターとソートを取得) で永続化されたか確認できます++### フィールドを追加++新しいフィールド(列)を追加します。フィールドは全ビュー(テーブル/ギャラリー/カンバン)の `previousKeyID` の後の位置に追加されます(空の場合はデフォルト位置)。++* `/api/av/addAttributeViewKey`+* パラメータ++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "keyID": "20240118120204-7k9wzbp",+ "keyName": "ステータス",+ "keyType": "select",+ "keyIcon": "",+ "previousKeyID": "20240118120204-w6cggab"+ }+ ```++ * `avID`: データベース ID+ * `keyID`: 新しいフィールドの ID。`Lute.NewNodeID()` で生成された有効なノード ID(14 桁のタイムスタンプ + `-` + 7 文字のランダム英数字、例:`20240118120204-abc1234`)である必要があります+ * `keyName`: フィールドの表示名+ * `keyType`: フィールドタイプ——`text`、`number`、`date`、`select`、`mSelect`、`url`、`email`、`phone`、`mAsset`、`template`、`created`、`updated`、`checkbox`、`relation`、`rollup`、`lineNumber` のいずれか。`block`(主キー)はこのエンドポイントから追加できません+ * `keyIcon`: 任意のフィールドアイコン(emoji または空文字列)+ * `previousKeyID`: このフィールド ID の後に新しい列を挿入。空文字列の場合はレイアウトのデフォルト位置(テーブルは先頭、ギャラリー/カンバンは末尾)を使用+* 戻り値++ ```json+ {+ "code": 0,+ "msg": "",+ "data": null+ }+ ```++### フィールドを削除++フィールド(列)とその全ての値を削除します。`keyID` が存在しない場合、`code: -1`、`msg: "key not found"` を返します。++* `/api/av/removeAttributeViewKey`+* パラメータ++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "keyID": "20240118120204-7k9wzbp",+ "removeRelationDest": false+ }+ ```++ * `avID`: データベース ID+ * `keyID`: 削除するフィールド ID+ * `removeRelationDest`: `true` かつフィールドが関連型の場合、宛先データベースの対応する逆関連フィールドも削除します。デフォルトは `false`+* 戻り値++ ```json+ {+ "code": 0,+ "msg": "",+ "data": null+ }+ ```++### グローバルのフィールドソートを設定++フィールド(列)を全体として並べ替えます——`keyID` をフィールド順序の `previousKeyID` の後の位置に移動し、全ビューに影響します。++* `/api/av/sortAttributeViewKey`+* パラメータ++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "keyID": "20240118203822-io6ofxb",+ "previousKeyID": "20240118120204-w6cggab"+ }+ ```++ * `avID`: データベース ID+ * `keyID`: 移動するフィールド ID+ * `previousKeyID`: `keyID` をその後に配置するフィールド ID。空文字列で先頭に移動+* 戻り値++ ```json+ {+ "code": 0,+ "msg": "",+ "data": null+ }+ ```++### ビュー内のフィールドソートを設定++全体のフィールド順序を変えずに、単一ビューのレイアウト内で列を並べ替えます(例:テーブルの列順序)。++* `/api/av/sortAttributeViewViewKey`+* パラメータ++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "viewID": "20240118120204-7rnmyc1",+ "keyID": "20240118203822-io6ofxb",+ "previousKeyID": "20240118120204-w6cggab"+ }+ ```++ * `avID`: データベース ID+ * `viewID`: ターゲットビュー。空の場合は現在のビューを使用+ * `keyID`: 移動するフィールド ID+ * `previousKeyID`: `keyID` をその後に配置するフィールド ID。空文字列で先頭に移動+* 戻り値++ ```json+ {+ "code": 0,+ "msg": "",+ "data": null+ }+ ```diff --git a/API.md b/API.mdindex ec2d806666..38052b5db2 100644--- a/API.md+++ b/API.md@@ -40,6 +40,22 @@* [Attributes](#Attributes)* [Set block attributes](#Set-block-attributes)* [Get block attributes](#Get-block-attributes)+* [Database](#Database)+ * [Render](#Render)+ * [Get](#Get)+ * [Get primary key values](#Get-primary-key-values)+ * [Search](#Search)+ * [Set a cell value](#Set-a-cell-value)+ * [Add items](#Add-items)+ * [Remove items](#Remove-items)+ * [Change layout](#Change-layout)+ * [Set grouping](#Set-grouping)+ * [Get filter and sort](#Get-filter-and-sort)+ * [Set filter and sort](#Set-filter-and-sort)+ * [Add a field](#Add-a-field)+ * [Remove a field](#Remove-a-field)+ * [Set global field sort](#Set-global-field-sort)+ * [Set per-view field sort](#Set-per-view-field-sort)* [SQL](#SQL)* [Execute SQL query](#Execute-SQL-query)* [Flush transaction](#Flush-transaction)@@ -1583,3 +1599,840 @@ Note: To ensure data security, access to this interface is prohibited in Publish```* `data`: Precision in milliseconds++## Database++A database (internally an "attribute view") stores structured data as fields (columns) and items (rows). Each database is identified by an `avID` and can be embedded into a document through one or more database blocks (`blockID`). A single database may contain multiple views (`viewID`) of different layout types: `table`, `gallery`, and `kanban`.++The field types (`keyType`) are:++| Value | Description |+|--------------|----------------------------|+| `block` | Primary key (bound block) |+| `text` | Text |+| `number` | Number |+| `date` | Date |+| `select` | Single select |+| `mSelect` | Multi-select |+| `url` | URL |+| `email` | Email |+| `phone` | Phone |+| `mAsset` | Asset |+| `template` | Template |+| `created` | Creation time |+| `updated` | Update time |+| `checkbox` | Checkbox |+| `relation` | Relation |+| `rollup` | Rollup |+| `lineNumber` | Line number |++### Render++* `/api/av/renderAttributeView`+* Parameters++ ```json+ {+ "id": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "viewID": "",+ "page": 1,+ "pageSize": 50,+ "query": "",+ "groupPaging": {},+ "createIfNotExist": true+ }+ ```++ * `id`: Database ID+ * `blockID`: The database block that embeds this database. Used to resolve the active view and publish access. Omit when rendering a detached database.+ * `viewID`: The view to render. When omitted, the current view (`viewID` field) is used+ * `page`: Page number, 1-based. Defaults to `1`+ * `pageSize`: Items per page. `-1` or omitted means use the view's default (`50`)+ * `query`: Optional full-text filter for the primary-key values+ * `groupPaging`: Optional paging configuration for grouped (kanban) views+ * `createIfNotExist`: When `true` (default), create a default view if the database has none+* Return value (real response, table layout, one row shown):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "name": "API 测试",+ "id": "20240118120204-kwyzf77",+ "viewType": "table",+ "viewID": "20240118120204-7rnmyc1",+ "isMirror": false,+ "views": [+ {+ "id": "20240118120204-7rnmyc1",+ "icon": "",+ "name": "表格",+ "desc": "",+ "hideAttrViewName": false,+ "type": "table",+ "pageSize": 50+ }+ ],+ "view": {+ "id": "20240118120204-7rnmyc1",+ "icon": "",+ "name": "表格",+ "desc": "",+ "hideAttrViewName": false,+ "filters": [],+ "sorts": [],+ "group": null,+ "pageSize": 50,+ "showIcon": true,+ "wrapField": false,+ "groupFolded": false,+ "groupHidden": 0,+ "columns": [+ {+ "id": "20240118120204-w6cggab",+ "name": "主键",+ "type": "block",+ "icon": "",+ "wrap": false,+ "hidden": false,+ "desc": "",+ "calc": null,+ "numberFormat": "",+ "template": "",+ "pin": false,+ "width": ""+ }+ ],+ "rows": [+ {+ "id": "20240118203831-fkfvvtx",+ "cells": [+ {+ "id": "20240118203911-xrg9obl",+ "value": {+ "id": "20240118203911-xrg9obl",+ "keyID": "20240118120204-w6cggab",+ "blockID": "20240118203831-fkfvvtx",+ "type": "block",+ "createdAt": 1706843791000,+ "updatedAt": 1706843791000,+ "block": {+ "id": "20240118203831-fkfvvtx",+ "content": "3",+ "created": 1706843791000,+ "updated": 1706843791000+ }+ },+ "valueType": "block",+ "color": "",+ "bgColor": ""+ }+ ]+ }+ ],+ "rowCount": 5+ }+ }+ }+ ```++ * `data.view`: The rendered viewable instance. Shape depends on `viewType` — `table` returns `columns`/`rows`/`rowCount`, `gallery` returns `columns`/`rows`, `kanban` returns `columns`/`groups` (each group is itself a view instance with `groupKey`/`groupValue`). `view` also carries `filters`, `sorts`, `group`, `showIcon`, `wrapField`, `groupFolded`, `groupHidden`. Note: active filters/grouping can make `rows` empty even when `rowCount` > 0+ * `data.view.columns[]`: Each has `id`, `name`, `type`, `icon`, `wrap`, `hidden`, `desc`, `calc`, `numberFormat`, `template`, `pin`, `width`; `select`/`mSelect` columns additionally carry `options`+ * `data.view.rows[].id`: The **row ID** (an item ID). For a bound row this is the same as the bound block ID; for a detached row it is a generated item ID distinct from any block+ * `data.view.rows[].cells[].value`: A `Value` object — see [Set a cell value](#Set-a-cell-value) for all value shapes. `createdAt`/`updatedAt` are int64 millisecond timestamps+ * `data.views`: Metadata of every view (no rows)+ * `data.isMirror`: `true` when the database block is a mirror (read-only copy) of the database++### Get++* `/api/av/getAttributeView`+* Parameters++ ```json+ {+ "id": "20240118120204-kwyzf77"+ }+ ```++ * `id`: Database ID+* Return value (real response, trimmed — `keyValues`/`views` arrays truncated):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "av": {+ "spec": 4,+ "id": "20240118120204-kwyzf77",+ "name": "API 测试",+ "keyValues": [+ {+ "key": {+ "id": "20240118120204-w6cggab",+ "name": "主键",+ "type": "block",+ "icon": "",+ "desc": "",+ "numberFormat": "",+ "template": ""+ },+ "values": [+ {+ "id": "20240118203911-xrg9obl",+ "keyID": "20240118120204-w6cggab",+ "blockID": "20240118203831-fkfvvtx",+ "type": "block",+ "createdAt": 1706843791000,+ "updatedAt": 1706843791000,+ "block": {+ "id": "20240118203831-fkfvvtx",+ "content": "3",+ "created": 1706843791000,+ "updated": 1706843791000+ }+ }+ ]+ }+ ],+ "keyIDs": null,+ "viewID": "20240118120204-7rnmyc1",+ "views": [+ {+ "id": "20240118120204-7rnmyc1",+ "icon": "",+ "name": "表格",+ "hideAttrViewName": false,+ "desc": "",+ "pageSize": 50,+ "type": "table",+ "table": {+ "spec": 0,+ "id": "20240118120204-grokgmm",+ "showIcon": true,+ "wrapField": false,+ "columns": [+ {+ "id": "20240118120204-w6cggab",+ "wrap": false,+ "hidden": false,+ "pin": false,+ "width": ""+ }+ ],+ "rowIds": null+ },+ "itemIds": ["20240118203818-ct041hj", "20240118203855-sqzbja0", "20240118203831-fkfvvtx", "20240118203842-kc31ovy", "20240531235026-uiap07y"],+ "groupCreated": 0,+ "groupItemIds": null,+ "groupFolded": false,+ "groupHidden": 0,+ "groupSort": 0+ }+ ]+ }+ }+ }+ ```++ * `data.av`: The full `AttributeView` definition — fields (`keyValues`), field ordering (`keyIDs`, may be `null`), current view (`viewID`), and all views with their raw layout config (`table`/`gallery`/`kanban`) and item ordering (`itemIds`). Returns the raw definition (no rendered rows or pagination); use [Render](#Render) for computed rows++### Get primary key values++* `/api/av/getAttributeViewPrimaryKeyValues`+* Parameters++ ```json+ {+ "id": "20240118120204-kwyzf77",+ "keyword": "",+ "page": 1,+ "pageSize": 16+ }+ ```++ * `id`: Database ID+ * `keyword`: Optional substring filter against primary-key text (case-insensitive)+ * `page`: Page number, 1-based. Defaults to `1`+ * `pageSize`: Items per page. `-1` or omitted means `16`. Values are sorted by `block.updated` descending+* Return value (real response, one value shown):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "name": "API 测试",+ "blockIDs": ["20240118120201-kldj15t"],+ "rows": {+ "key": {+ "id": "20240118120204-w6cggab",+ "name": "主键",+ "type": "block",+ "icon": "",+ "desc": "",+ "numberFormat": "",+ "template": ""+ },+ "values": [+ {+ "id": "20240118203911-xrg9obl",+ "keyID": "20240118120204-w6cggab",+ "blockID": "20240118203831-fkfvvtx",+ "type": "block",+ "createdAt": 1706843791000,+ "updatedAt": 1706843791000,+ "block": {+ "id": "20240118203831-fkfvvtx",+ "content": "3",+ "created": 1706843791000,+ "updated": 1706843791000+ }+ }+ ]+ }+ }+ }+ ```++ * `data.rows`: A `KeyValues` object holding the primary-key (`block`) field and its paginated values+ * `data.blockIDs`: IDs of all database blocks (mirrors) that reference this database++### Search++* `/api/av/searchAttributeView`+* Parameters++ ```json+ {+ "keyword": "API",+ "excludes": []+ }+ ```++ * `keyword`: Search keyword (matches database name)+ * `excludes`: Optional list of database IDs to exclude from the results+* Return value (real response):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "results": [+ {+ "avID": "20240118120204-kwyzf77",+ "avName": "API 测试",+ "viewName": "",+ "viewID": "",+ "viewLayout": "",+ "blockID": "20240118120201-kldj15t",+ "hPath": "正在跟进的问题/数据库/API",+ "children": [+ {+ "avID": "20240118120204-kwyzf77",+ "avName": "API 测试",+ "viewName": "表格",+ "viewID": "20240118120204-7rnmyc1",+ "viewLayout": "table",+ "blockID": "20240118120201-kldj15t",+ "hPath": "正在跟进的问题/数据库/API"+ }+ ]+ }+ ]+ }+ }+ ```++ * `data.results[]`: Each top-level result groups a database by `avID`; its `children[]` list the individual views (`viewName`/`viewID`/`viewLayout`)++### Set a cell value++Updates a single cell (one field of one row). This is the primary write endpoint for cell values. The request `value` is a partial `Value` object whose shape depends on the field's `keyType`. The most common value shapes are:++| `keyType` | `value` shape |+|------------|----------------------------------------------------------------------------------------------------------------------|+| `block` | `{"block": {"content": "First row", "id": "<boundBlockID>"}, "isDetached": false}` |+| `text` | `{"text": {"content": "Some text"}}` |+| `number` | `{"number": {"content": 42, "isNotEmpty": true}}` (clear with `{"isNotEmpty": false}`) |+| `date` | `{"date": {"content": 1676042451000, "isNotEmpty": true}}` (millisecond timestamp) |+| `select` | `{"mSelect": [{"content": "Done", "color": "1"}]}` (at most one option) |+| `mSelect` | `{"mSelect": [{"content": "A", "color": "1"}, {"content": "B", "color": "2"}]}` |+| `url` | `{"url": {"content": "https://siyuan.com"}}` |+| `email` | `{"email": {"content": "[email protected]"}}` |+| `phone` | `{"phone": {"content": "1234567890"}}` |+| `checkbox` | `{"checkbox": {"checked": true}}` |++> ⚠️ `itemID` is the **row ID** (`rows[].id` from [Render](#Render)). For a bound row the row ID equals the bound block ID; for a detached row it is a generated item ID. Passing the wrong ID stores the value as an orphan that does not appear in the rendered cell.++* `/api/av/setAttributeViewBlockAttr`+* Parameters++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "keyID": "20240531232156-ahsyx8l",+ "itemID": "20240118203831-fkfvvtx",+ "value": {+ "type": "number",+ "number": {+ "content": 42,+ "isNotEmpty": true+ }+ }+ }+ ```++ * `avID`: Database ID+ * `keyID`: Field ID (the column being updated)+ * `itemID`: **Row ID** (`rows[].id` from [Render](#Render)). The legacy `rowID` parameter is deprecated and will be removed after 2026-12-01; use `itemID` instead+ * `value`: Partial `Value` object (see the table above). Unknown or unsupported keys are ignored+* Return value (real response, number value):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "value": {+ "id": "20240531235048-4zisj1p",+ "keyID": "20240531232156-ahsyx8l",+ "blockID": "20240118203831-fkfvvtx",+ "type": "number",+ "createdAt": 1717170648596,+ "updatedAt": 1781610266432,+ "number": {+ "content": 42,+ "isNotEmpty": true,+ "format": "",+ "formattedContent": "42"+ }+ }+ }+ }+ ```++ * `data.value`: The fully-normalized value after the update (with computed fields such as `number.formattedContent`). Use this to refresh the UI rather than re-sending the request payload++### Add items++Adds one or more items (rows). Each source can either bind an existing block (`isDetached: false`) or create a detached row that only lives inside the view (`isDetached: true`).++* `/api/av/addAttributeViewBlocks`+* Parameters++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "viewID": "",+ "groupID": "",+ "previousID": "",+ "srcs": [+ {+ "id": "20240118120201-kldj15t",+ "isDetached": false,+ "content": "New row"+ }+ ],+ "ignoreDefaultFill": false+ }+ ```++ * `avID`: Database ID+ * `blockID`: The database block that owns this database (resolves target view/group)+ * `viewID`: Target view. When omitted, the current view is used+ * `groupID`: Target group ID for kanban views. Omit for table/gallery+ * `previousID`: Insert after this item ID. Empty means append to the end+ * `srcs[].id`: For bound blocks (`isDetached: false`), the block ID to bind. Must match the node ID pattern+ * `srcs[].isDetached`: `true` to create a detached row; `false` to bind an existing block+ * `srcs[].content`: Display text for the primary key (used when `isDetached: true`, or to override the bound block's content)+ * `srcs[].itemID`: Optional explicit item ID. Auto-generated when omitted+ * `ignoreDefaultFill`: When `true`, skip auto-filling default values into filter/group fields+* Return value++ ```json+ {+ "code": 0,+ "msg": "",+ "data": null+ }+ ```++ * The endpoint returns `null`; after it succeeds, call [Render](#Render) to fetch the updated rows (including the new row IDs needed for cell updates)++### Remove items++Removes one or more items (rows). Detached rows are deleted; bound blocks are unbound (the underlying document block is not deleted).++* `/api/av/removeAttributeViewBlocks`+* Parameters++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "srcIDs": ["20240118203831-fkfvvtx"]+ }+ ```++ * `avID`: Database ID+ * `srcIDs`: Row IDs (`rows[].id` from [Render](#Render)) to remove+* Return value++ ```json+ {+ "code": 0,+ "msg": "",+ "data": null+ }+ ```++### Change layout++Switches the layout type of the current view between `table`, `gallery`, and `kanban`. On success the server re-renders the view and returns it (same shape as [Render](#Render)).++* `/api/av/changeAttrViewLayout`+* Parameters++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "layoutType": "kanban"+ }+ ```++ * `avID`: Database ID+ * `blockID`: The database block that owns the view+ * `layoutType`: Target layout — one of `table`, `gallery`, `kanban`+* Return value: same shape as [Render](#Render). When switching to `kanban` and a group is configured, `data.view` carries a `groups[]` array; each group is a view instance with `groupKey`, `groupValue`, plus kanban-specific fields (`coverFrom`, `cardAspectRatio`, `cardSize`, `fitImage`, `displayFieldName`, `fillColBackgroundColor`, `fields`)++### Set grouping++Sets or clears the grouping rule for a kanban view. When `group.field` is empty, grouping is removed. On success the server re-renders the view and returns it.++* `/api/av/setAttrViewGroup`+* Parameters++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "group": {+ "field": "20240118203822-io6ofxb",+ "method": 0,+ "order": 0,+ "hideEmpty": false+ }+ }+ ```++ * `avID`: Database ID+ * `blockID`: The database block that owns the view+ * `group`: Grouping rule+ * `group.field`: Field (column) ID to group by. Empty string removes grouping+ * `group.method`: Group method — `0` by value, `1` by number range, `2` by relative date, `3` by day, `4` by week, `5` by month, `6` by year+ * `group.range`: Optional. Required when `method` is `1` (number range): `{ "numStart": 0, "numEnd": 100, "numStep": 10 }`+ * `group.order`: Group ordering — `0` ascending, `1` descending, `2` manual, `3` follow select-option order+ * `group.hideEmpty`: Whether to hide empty groups+* Return value: same shape as [Render](#Render)++### Get filter and sort++Returns the current filter and sort rules of the view bound to a database block.++* `/api/av/getAttributeViewFilterSort`+* Parameters++ ```json+ {+ "id": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t"+ }+ ```++ * `id`: Database ID+ * `blockID`: The database block that owns the view+* Return value (real response, no filters/sorts configured):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "filters": [],+ "sorts": []+ }+ }+ ```++ When configured (real captured response), a filter and sort look like:++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "filters": [+ {+ "column": "20240118203822-io6ofxb",+ "operator": "=",+ "value": {+ "type": "select",+ "mSelect": [+ { "content": "Done", "color": "1" }+ ]+ }+ }+ ],+ "sorts": [+ {+ "column": "20240118120204-w6cggab",+ "order": "DESC"+ }+ ]+ }+ }+ ```++ * `data.filters`: Array of `ViewFilter`+ * `data.filters[].column`: Field (column) ID the filter applies to+ * `data.filters[].operator`: Filter operator (see the operator table below)+ * `data.filters[].value`: Filter value, a `Value` object (see [Set a cell value](#Set-a-cell-value) for the value shapes)+ * `data.filters[].relativeDate`: Optional relative-date descriptor used by date filters (`{ "count": 7, "unit": 0, "direction": -1 }`; `unit`: `0` day, `1` week, `2` month, `3` year; `direction`: `-1` before, `0` this, `1` after)+ * `data.sorts`: Array of `ViewSort`+ * `data.sorts[].column`: Field (column) ID the sort applies to+ * `data.sorts[].order`: `ASC` or `DESC`++ Filter operators:++ | Value | Description |+ |----------------------|----------------------|+ | `=` | Equals |+ | `!=` | Not equals |+ | `>` | Greater than |+ | `>=` | Greater or equal |+ | `<` | Less than |+ | `<=` | Less or equal |+ | `Contains` | Contains |+ | `Does not contains` | Does not contain |+ | `Is empty` | Is empty |+ | `Is not empty` | Is not empty |+ | `Starts with` | Starts with |+ | `Ends with` | Ends with |+ | `Is between` | Is between |+ | `Is true` | Is true (checkbox) |+ | `Is false` | Is false (checkbox) |++### Set filter and sort++Filters and sorts are persisted through the transaction endpoint `/api/transactions` (plural), because changing them is part of an undoable editing transaction. Wrap each rule change in a `doOperations` entry whose `action` is `setAttrViewFilters` or `setAttrViewSorts`; the `data` field is the full new array (it replaces the view's existing rules entirely).++* `/api/transactions`+* Parameters++ ```json+ {+ "reqId": 1781610129661,+ "app": "",+ "session": "",+ "transactions": [+ {+ "doOperations": [+ {+ "action": "setAttrViewFilters",+ "avID": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "data": [+ {+ "column": "20240118203822-io6ofxb",+ "operator": "=",+ "value": {+ "type": "select",+ "mSelect": [+ { "content": "Done", "color": "1" }+ ]+ }+ }+ ]+ },+ {+ "action": "setAttrViewSorts",+ "avID": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "data": [+ {+ "column": "20240118120204-w6cggab",+ "order": "DESC"+ }+ ]+ }+ ]+ }+ ]+ }+ ```++ * `reqId`: Required. A client-generated timestamp/nonce (number); tags the transaction for undo/redo+ * `app` / `session`: Optional. Used to scope the resulting WebSocket push so other clients/sessions can refresh+ * `transactions[].doOperations[]`: One operation per rule set to replace+ * `doOperations[].action`: `setAttrViewFilters` to replace filters, or `setAttrViewSorts` to replace sorts+ * `doOperations[].avID`: Database ID+ * `doOperations[].blockID`: The database block that owns the view+ * `doOperations[].data`: Full new array of `ViewFilter` or `ViewSort` objects (see [Get filter and sort](#Get-filter-and-sort)). Pass `[]` to clear+* Return value (real response, echoes the submitted operations with a server-assigned `timestamp`):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": [+ {+ "timestamp": 1781610129661,+ "doOperations": [+ {+ "action": "setAttrViewFilters",+ "id": "",+ "avID": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "data": [+ {+ "column": "20240118203822-io6ofxb",+ "operator": "=",+ "value": {+ "type": "select",+ "mSelect": [{ "content": "Done", "color": "1" }]+ }+ }+ ]+ }+ ]+ }+ ]+ }+ ```++ * After a successful call, verify persistence via [Get filter and sort](#Get-filter-and-sort)++### Add a field++Adds a new field (column). The field is appended to every view (table/gallery/kanban) at the position after `previousKeyID` (or at the default position when empty).++* `/api/av/addAttributeViewKey`+* Parameters++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "keyID": "20240118120204-7k9wzbp",+ "keyName": "状态",+ "keyType": "select",+ "keyIcon": "",+ "previousKeyID": "20240118120204-w6cggab"+ }+ ```++ * `avID`: Database ID+ * `keyID`: ID for the new field. Must be a valid node ID generated by `Lute.NewNodeID()` (14-digit timestamp + `-` + 7-char random alphanumerics, e.g. `20240118120204-abc1234`)+ * `keyName`: Field display name+ * `keyType`: Field type — one of `text`, `number`, `date`, `select`, `mSelect`, `url`, `email`, `phone`, `mAsset`, `template`, `created`, `updated`, `checkbox`, `relation`, `rollup`, `lineNumber`. `block` (primary key) cannot be added through this endpoint+ * `keyIcon`: Optional field icon (emoji or empty string)+ * `previousKeyID`: Insert the new column after this field ID. Empty string uses the layout default (first column for table, last for gallery/kanban)+* Return value++ ```json+ {+ "code": 0,+ "msg": "",+ "data": null+ }+ ```++### Remove a field++Removes a field (column) and all of its values. Returns `code: -1` with `msg: "key not found"` if `keyID` does not exist.++* `/api/av/removeAttributeViewKey`+* Parameters++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "keyID": "20240118120204-7k9wzbp",+ "removeRelationDest": false+ }+ ```++ * `avID`: Database ID+ * `keyID`: Field ID to remove+ * `removeRelationDest`: When `true` and the field is a relation, also remove the corresponding back-relation field from the destination database. Defaults to `false`+* Return value++ ```json+ {+ "code": 0,+ "msg": "",+ "data": null+ }+ ```++### Set global field sort++Reorders a field (column) globally — moves `keyID` to the position after `previousKeyID` in the field ordering, affecting every view.++* `/api/av/sortAttributeViewKey`+* Parameters++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "keyID": "20240118203822-io6ofxb",+ "previousKeyID": "20240118120204-w6cggab"+ }+ ```++ * `avID`: Database ID+ * `keyID`: Field ID to move+ * `previousKeyID`: Field ID after which `keyID` should be placed. Empty string moves it to the first position+* Return value++ ```json+ {+ "code": 0,+ "msg": "",+ "data": null+ }+ ```++### Set per-view field sort++Reorders a column within a single view's layout (e.g. a table's column order), without changing the global field ordering.++* `/api/av/sortAttributeViewViewKey`+* Parameters++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "viewID": "20240118120204-7rnmyc1",+ "keyID": "20240118203822-io6ofxb",+ "previousKeyID": "20240118120204-w6cggab"+ }+ ```++ * `avID`: Database ID+ * `viewID`: Target view. When empty, uses the current view+ * `keyID`: Field ID to move+ * `previousKeyID`: Field ID after which `keyID` should be placed. Empty string moves it to the first position+* Return value++ ```json+ {+ "code": 0,+ "msg": "",+ "data": null+ }+ ```diff --git a/API.zh-CN.md b/API.zh-CN.mdindex 5900afd3d5..62677afba8 100644--- a/API.zh-CN.md+++ b/API.zh-CN.md@@ -40,6 +40,22 @@* [属性](#属性)* [设置块属性](#设置块属性)* [获取块属性](#获取块属性)+* [数据库](#数据库)+ * [渲染](#渲染)+ * [获取](#获取)+ * [获取主键值](#获取主键值)+ * [搜索](#搜索)+ * [设置单元格值](#设置单元格值)+ * [添加条目](#添加条目)+ * [移除条目](#移除条目)+ * [切换布局](#切换布局)+ * [设置分组](#设置分组)+ * [获取过滤与排序](#获取过滤与排序)+ * [设置过滤与排序](#设置过滤与排序)+ * [添加字段](#添加字段)+ * [移除字段](#移除字段)+ * [设置全局字段排序](#设置全局字段排序)+ * [设置视图内字段排序](#设置视图内字段排序)* [SQL](#SQL)* [执行 SQL 查询](#执行-SQL-查询)* [提交事务](#提交事务)@@ -1572,3 +1588,840 @@```* `data`: 精度为毫秒++## 数据库++数据库(内核中为“属性视图”)以字段(列)和条目(行)的形式存储结构化数据。每个数据库由 `avID` 标识,可通过一个或多个数据库块(`blockID`)嵌入到文档中。一个数据库可包含多个不同布局类型的视图(`viewID`):`table`(表格)、`gallery`(卡片)和 `kanban`(看板)。++字段类型(`keyType`)如下:++| 取值 | 说明 |+|--------------|----------------------|+| `block` | 主键(绑定的块) |+| `text` | 文本 |+| `number` | 数字 |+| `date` | 日期 |+| `select` | 单选 |+| `mSelect` | 多选 |+| `url` | URL |+| `email` | 邮箱 |+| `phone` | 电话 |+| `mAsset` | 资源 |+| `template` | 模板 |+| `created` | 创建时间 |+| `updated` | 更新时间 |+| `checkbox` | 复选框 |+| `relation` | 关联 |+| `rollup` | 汇总 |+| `lineNumber` | 行号 |++### 渲染++* `/api/av/renderAttributeView`+* 参数++ ```json+ {+ "id": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "viewID": "",+ "page": 1,+ "pageSize": 50,+ "query": "",+ "groupPaging": {},+ "createIfNotExist": true+ }+ ```++ * `id`: 数据库 ID+ * `blockID`: 嵌入该数据库的数据库块,用于解析当前视图和发布权限。渲染独立数据库时可省略+ * `viewID`: 要渲染的视图。省略时使用当前视图(`viewID` 字段)+ * `page`: 页码,从 1 开始。默认为 `1`+ * `pageSize`: 每页条目数。`-1` 或省略表示使用视图默认值(`50`)+ * `query`: 可选的主键值全文过滤关键字+ * `groupPaging`: 分组(看板)视图的可选分页配置+ * `createIfNotExist`: 为 `true`(默认)时,若数据库不存在视图则创建默认视图+* 返回值(真实响应,表格布局,展示一行):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "name": "API 测试",+ "id": "20240118120204-kwyzf77",+ "viewType": "table",+ "viewID": "20240118120204-7rnmyc1",+ "isMirror": false,+ "views": [+ {+ "id": "20240118120204-7rnmyc1",+ "icon": "",+ "name": "表格",+ "desc": "",+ "hideAttrViewName": false,+ "type": "table",+ "pageSize": 50+ }+ ],+ "view": {+ "id": "20240118120204-7rnmyc1",+ "icon": "",+ "name": "表格",+ "desc": "",+ "hideAttrViewName": false,+ "filters": [],+ "sorts": [],+ "group": null,+ "pageSize": 50,+ "showIcon": true,+ "wrapField": false,+ "groupFolded": false,+ "groupHidden": 0,+ "columns": [+ {+ "id": "20240118120204-w6cggab",+ "name": "主键",+ "type": "block",+ "icon": "",+ "wrap": false,+ "hidden": false,+ "desc": "",+ "calc": null,+ "numberFormat": "",+ "template": "",+ "pin": false,+ "width": ""+ }+ ],+ "rows": [+ {+ "id": "20240118203831-fkfvvtx",+ "cells": [+ {+ "id": "20240118203911-xrg9obl",+ "value": {+ "id": "20240118203911-xrg9obl",+ "keyID": "20240118120204-w6cggab",+ "blockID": "20240118203831-fkfvvtx",+ "type": "block",+ "createdAt": 1706843791000,+ "updatedAt": 1706843791000,+ "block": {+ "id": "20240118203831-fkfvvtx",+ "content": "3",+ "created": 1706843791000,+ "updated": 1706843791000+ }+ },+ "valueType": "block",+ "color": "",+ "bgColor": ""+ }+ ]+ }+ ],+ "rowCount": 5+ }+ }+ }+ ```++ * `data.view`: 渲染后的视图实例。结构随 `viewType` 而变——`table` 返回 `columns`/`rows`/`rowCount`,`gallery` 返回 `columns`/`rows`,`kanban` 返回 `columns`/`groups`(每个分组本身也是视图实例,含 `groupKey`/`groupValue`)。`view` 还包含 `filters`/`sorts`/`group`/`showIcon`/`wrapField`/`groupFolded`/`groupHidden`。注意:启用的过滤/分组可能使 `rows` 为空,即使 `rowCount` > 0+ * `data.view.columns[]`: 每列含 `id`/`name`/`type`/`icon`/`wrap`/`hidden`/`desc`/`calc`/`numberFormat`/`template`/`pin`/`width`;`select`/`mSelect` 列还额外包含 `options`+ * `data.view.rows[].id`: **行 ID**(一个条目 ID)。对于绑定行,它等于绑定的块 ID;对于独立行,它是生成的条目 ID,与任何块都不同+ * `data.view.rows[].cells[].value`: 一个 `Value` 对象——所有 value 形态见 [设置单元格值](#设置单元格值)。`createdAt`/`updatedAt` 为 int64 毫秒时间戳+ * `data.views`: 所有视图的元数据(不含行数据)+ * `data.isMirror`: 当数据库块为数据库的镜像(只读副本)时为 `true`++### 获取++* `/api/av/getAttributeView`+* 参数++ ```json+ {+ "id": "20240118120204-kwyzf77"+ }+ ```++ * `id`: 数据库 ID+* 返回值(真实响应,已裁剪——`keyValues`/`views` 数组做了截断):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "av": {+ "spec": 4,+ "id": "20240118120204-kwyzf77",+ "name": "API 测试",+ "keyValues": [+ {+ "key": {+ "id": "20240118120204-w6cggab",+ "name": "主键",+ "type": "block",+ "icon": "",+ "desc": "",+ "numberFormat": "",+ "template": ""+ },+ "values": [+ {+ "id": "20240118203911-xrg9obl",+ "keyID": "20240118120204-w6cggab",+ "blockID": "20240118203831-fkfvvtx",+ "type": "block",+ "createdAt": 1706843791000,+ "updatedAt": 1706843791000,+ "block": {+ "id": "20240118203831-fkfvvtx",+ "content": "3",+ "created": 1706843791000,+ "updated": 1706843791000+ }+ }+ ]+ }+ ],+ "keyIDs": null,+ "viewID": "20240118120204-7rnmyc1",+ "views": [+ {+ "id": "20240118120204-7rnmyc1",+ "icon": "",+ "name": "表格",+ "hideAttrViewName": false,+ "desc": "",+ "pageSize": 50,+ "type": "table",+ "table": {+ "spec": 0,+ "id": "20240118120204-grokgmm",+ "showIcon": true,+ "wrapField": false,+ "columns": [+ {+ "id": "20240118120204-w6cggab",+ "wrap": false,+ "hidden": false,+ "pin": false,+ "width": ""+ }+ ],+ "rowIds": null+ },+ "itemIds": ["20240118203818-ct041hj", "20240118203855-sqzbja0", "20240118203831-fkfvvtx", "20240118203842-kc31ovy", "20240531235026-uiap07y"],+ "groupCreated": 0,+ "groupItemIds": null,+ "groupFolded": false,+ "groupHidden": 0,+ "groupSort": 0+ }+ ]+ }+ }+ }+ ```++ * `data.av`: 完整的 `AttributeView` 定义——字段(`keyValues`)、字段顺序(`keyIDs`,可能为 `null`)、当前视图(`viewID`)、以及所有视图的原始布局配置(`table`/`gallery`/`kanban`)和条目顺序(`itemIds`)。返回原始定义(不含渲染后的行或分页);需要计算后的行数据请使用 [渲染](#渲染)++### 获取主键值++* `/api/av/getAttributeViewPrimaryKeyValues`+* 参数++ ```json+ {+ "id": "20240118120204-kwyzf77",+ "keyword": "",+ "page": 1,+ "pageSize": 16+ }+ ```++ * `id`: 数据库 ID+ * `keyword`: 可选的主键文本子串过滤(不区分大小写)+ * `page`: 页码,从 1 开始。默认为 `1`+ * `pageSize`: 每页条目数。`-1` 或省略表示 `16`。结果按 `block.updated` 倒序排序+* 返回值(真实响应,展示一个值):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "name": "API 测试",+ "blockIDs": ["20240118120201-kldj15t"],+ "rows": {+ "key": {+ "id": "20240118120204-w6cggab",+ "name": "主键",+ "type": "block",+ "icon": "",+ "desc": "",+ "numberFormat": "",+ "template": ""+ },+ "values": [+ {+ "id": "20240118203911-xrg9obl",+ "keyID": "20240118120204-w6cggab",+ "blockID": "20240118203831-fkfvvtx",+ "type": "block",+ "createdAt": 1706843791000,+ "updatedAt": 1706843791000,+ "block": {+ "id": "20240118203831-fkfvvtx",+ "content": "3",+ "created": 1706843791000,+ "updated": 1706843791000+ }+ }+ ]+ }+ }+ }+ ```++ * `data.rows`: 一个 `KeyValues` 对象,包含主键(`block`)字段及其分页后的值+ * `data.blockIDs`: 引用该数据库的所有数据库块(镜像)ID++### 搜索++* `/api/av/searchAttributeView`+* 参数++ ```json+ {+ "keyword": "API",+ "excludes": []+ }+ ```++ * `keyword`: 搜索关键字(匹配数据库名称)+ * `excludes`: 可选,需从结果中排除的数据库 ID 列表+* 返回值(真实响应):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "results": [+ {+ "avID": "20240118120204-kwyzf77",+ "avName": "API 测试",+ "viewName": "",+ "viewID": "",+ "viewLayout": "",+ "blockID": "20240118120201-kldj15t",+ "hPath": "正在跟进的问题/数据库/API",+ "children": [+ {+ "avID": "20240118120204-kwyzf77",+ "avName": "API 测试",+ "viewName": "表格",+ "viewID": "20240118120204-7rnmyc1",+ "viewLayout": "table",+ "blockID": "20240118120201-kldj15t",+ "hPath": "正在跟进的问题/数据库/API"+ }+ ]+ }+ ]+ }+ }+ ```++ * `data.results[]`: 每个顶层结果按 `avID` 聚合一个数据库;其 `children[]` 列出该数据库的各个视图(`viewName`/`viewID`/`viewLayout`)++### 设置单元格值++更新单个单元格(某一行的某个字段)。这是单元格值的主要写入接口。请求中的 `value` 是一个部分 `Value` 对象,其结构取决于字段的 `keyType`。常见 value 结构如下:++| `keyType` | `value` 结构 |+|------------|----------------------------------------------------------------------------------------------------------------------|+| `block` | `{"block": {"content": "第一行", "id": "<绑定块ID>"}, "isDetached": false}` |+| `text` | `{"text": {"content": "文本"}}` |+| `number` | `{"number": {"content": 42, "isNotEmpty": true}}`(清空用 `{"isNotEmpty": false}`) |+| `date` | `{"date": {"content": 1676042451000, "isNotEmpty": true}}`(毫秒时间戳) |+| `select` | `{"mSelect": [{"content": "已完成", "color": "1"}]}`(至多一个选项) |+| `mSelect` | `{"mSelect": [{"content": "A", "color": "1"}, {"content": "B", "color": "2"}]}` |+| `url` | `{"url": {"content": "https://siyuan.com"}}` |+| `email` | `{"email": {"content": "[email protected]"}}` |+| `phone` | `{"phone": {"content": "1234567890"}}` |+| `checkbox` | `{"checkbox": {"checked": true}}` |++> ⚠️ `itemID` 是**行 ID**([渲染](#渲染) 返回的 `rows[].id`)。对于绑定行,行 ID 等于绑定的块 ID;对于独立行,它是生成的条目 ID。传入错误的 ID 会把值存为孤儿数据,不会出现在渲染后的单元格中。++* `/api/av/setAttributeViewBlockAttr`+* 参数++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "keyID": "20240531232156-ahsyx8l",+ "itemID": "20240118203831-fkfvvtx",+ "value": {+ "type": "number",+ "number": {+ "content": 42,+ "isNotEmpty": true+ }+ }+ }+ ```++ * `avID`: 数据库 ID+ * `keyID`: 字段 ID(被更新的列)+ * `itemID`: **行 ID**([渲染](#渲染) 返回的 `rows[].id`)。旧参数 `rowID` 已弃用,将于 2026-12-01 后删除,请改用 `itemID`+ * `value`: 部分 `Value` 对象(见上表)。未知或不支持的键会被忽略+* 返回值(真实响应,数字值):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "value": {+ "id": "20240531235048-4zisj1p",+ "keyID": "20240531232156-ahsyx8l",+ "blockID": "20240118203831-fkfvvtx",+ "type": "number",+ "createdAt": 1717170648596,+ "updatedAt": 1781610266432,+ "number": {+ "content": 42,+ "isNotEmpty": true,+ "format": "",+ "formattedContent": "42"+ }+ }+ }+ }+ ```++ * `data.value`: 更新后规范化完成的值(含 `number.formattedContent` 等计算字段)。请使用该返回值刷新 UI,无需重新发送请求体++### 添加条目++添加一个或多个条目(行)。每个来源既可绑定已有块(`isDetached: false`),也可创建仅存在于视图内的独立行(`isDetached: true`)。++* `/api/av/addAttributeViewBlocks`+* 参数++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "viewID": "",+ "groupID": "",+ "previousID": "",+ "srcs": [+ {+ "id": "20240118120201-kldj15t",+ "isDetached": false,+ "content": "新行"+ }+ ],+ "ignoreDefaultFill": false+ }+ ```++ * `avID`: 数据库 ID+ * `blockID`: 拥有该数据库的数据库块(用于解析目标视图/分组)+ * `viewID`: 目标视图。省略时使用当前视图+ * `groupID`: 看板视图的目标分组 ID。表格/卡片视图可省略+ * `previousID`: 在此条目 ID 之后插入。为空表示追加到末尾+ * `srcs[].id`: 绑定块时(`isDetached: false`)为要绑定的块 ID,需符合节点 ID 格式+ * `srcs[].isDetached`: `true` 创建独立行;`false` 绑定已有块+ * `srcs[].content`: 主键的显示文本(`isDetached: true` 时使用,或覆盖绑定块的内容)+ * `srcs[].itemID`: 可选,显式指定条目 ID。省略时自动生成+ * `ignoreDefaultFill`: 为 `true` 时,跳过向过滤/分组字段自动填充默认值+* 返回值++ ```json+ {+ "code": 0,+ "msg": "",+ "data": null+ }+ ```++ * 该接口返回 `null`;成功后请调用 [渲染](#渲染) 获取更新后的行(含更新单元格所需的新行 ID)++### 移除条目++移除一个或多个条目(行)。独立行会被删除;绑定块会解绑(不会删除底层文档块)。++* `/api/av/removeAttributeViewBlocks`+* 参数++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "srcIDs": ["20240118203831-fkfvvtx"]+ }+ ```++ * `avID`: 数据库 ID+ * `srcIDs`: 要移除的行 ID([渲染](#渲染) 返回的 `rows[].id`)列表+* 返回值++ ```json+ {+ "code": 0,+ "msg": "",+ "data": null+ }+ ```++### 切换布局++在 `table`(表格)、`gallery`(卡片)和 `kanban`(看板)之间切换当前视图的布局类型。成功时服务端会重新渲染并返回视图(结构与 [渲染](#渲染) 相同)。++* `/api/av/changeAttrViewLayout`+* 参数++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "layoutType": "kanban"+ }+ ```++ * `avID`: 数据库 ID+ * `blockID`: 拥有该视图的数据库块+ * `layoutType`: 目标布局——`table`、`gallery`、`kanban` 之一+* 返回值:与 [渲染](#渲染) 返回结构相同。当切换到 `kanban` 且已配置分组时,`data.view` 携带 `groups[]` 数组;每个分组是视图实例,含 `groupKey`、`groupValue`,以及看板特有字段(`coverFrom`、`cardAspectRatio`、`cardSize`、`fitImage`、`displayFieldName`、`fillColBackgroundColor`、`fields`)++### 设置分组++为看板视图设置或清除分组规则。当 `group.field` 为空时移除分组。成功时服务端会重新渲染并返回视图。++* `/api/av/setAttrViewGroup`+* 参数++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "group": {+ "field": "20240118203822-io6ofxb",+ "method": 0,+ "order": 0,+ "hideEmpty": false+ }+ }+ ```++ * `avID`: 数据库 ID+ * `blockID`: 拥有该视图的数据库块+ * `group`: 分组规则+ * `group.field`: 用于分组的字段(列)ID。为空字符串表示移除分组+ * `group.method`: 分组方式——`0` 按值、`1` 按数字范围、`2` 按相对日期、`3` 按天、`4` 按周、`5` 按月、`6` 按年+ * `group.range`: 可选。`method` 为 `1`(数字范围)时必填:`{ "numStart": 0, "numEnd": 100, "numStep": 10 }`+ * `group.order`: 分组排序——`0` 升序、`1` 降序、`2` 手动、`3` 按选项顺序+ * `group.hideEmpty`: 是否隐藏空分组+* 返回值:与 [渲染](#渲染) 返回结构相同++### 获取过滤与排序++返回绑定到数据库块的视图当前的过滤和排序规则。++* `/api/av/getAttributeViewFilterSort`+* 参数++ ```json+ {+ "id": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t"+ }+ ```++ * `id`: 数据库 ID+ * `blockID`: 拥有该视图的数据库块+* 返回值(真实响应,未配置过滤/排序):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "filters": [],+ "sorts": []+ }+ }+ ```++ 配置后(真实抓取的响应),过滤与排序形如:++ ```json+ {+ "code": 0,+ "msg": "",+ "data": {+ "filters": [+ {+ "column": "20240118203822-io6ofxb",+ "operator": "=",+ "value": {+ "type": "select",+ "mSelect": [+ { "content": "已完成", "color": "1" }+ ]+ }+ }+ ],+ "sorts": [+ {+ "column": "20240118120204-w6cggab",+ "order": "DESC"+ }+ ]+ }+ }+ ```++ * `data.filters`: `ViewFilter` 数组+ * `data.filters[].column`: 过滤规则作用的字段(列)ID+ * `data.filters[].operator`: 过滤操作符(见下方操作符表)+ * `data.filters[].value`: 过滤值,一个 `Value` 对象(结构见 [设置单元格值](#设置单元格值))+ * `data.filters[].relativeDate`: 可选,日期过滤使用的相对时间描述(`{ "count": 7, "unit": 0, "direction": -1 }`;`unit`:`0` 天、`1` 周、`2` 月、`3` 年;`direction`:`-1` 前、`0` 当前、`1` 后)+ * `data.sorts`: `ViewSort` 数组+ * `data.sorts[].column`: 排序规则作用的字段(列)ID+ * `data.sorts[].order`: `ASC` 或 `DESC`++ 过滤操作符:++ | 取值 | 说明 |+ |---------------------|----------------|+ | `=` | 等于 |+ | `!=` | 不等于 |+ | `>` | 大于 |+ | `>=` | 大于等于 |+ | `<` | 小于 |+ | `<=` | 小于等于 |+ | `Contains` | 包含 |+ | `Does not contains` | 不包含 |+ | `Is empty` | 为空 |+ | `Is not empty` | 不为空 |+ | `Starts with` | 以...开头 |+ | `Ends with` | 以...结尾 |+ | `Is between` | 介于之间 |+ | `Is true` | 为真(复选框) |+ | `Is false` | 为假(复选框) |++### 设置过滤与排序++过滤和排序通过事务接口 `/api/transactions`(注意是复数)持久化,因为修改它们属于可撤销的编辑事务。把每条规则变更包进一个 `doOperations` 条目,`action` 取 `setAttrViewFilters` 或 `setAttrViewSorts`,`data` 字段是完整的新数组(将整体替换视图现有规则)。++* `/api/transactions`+* 参数++ ```json+ {+ "reqId": 1781610129661,+ "app": "",+ "session": "",+ "transactions": [+ {+ "doOperations": [+ {+ "action": "setAttrViewFilters",+ "avID": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "data": [+ {+ "column": "20240118203822-io6ofxb",+ "operator": "=",+ "value": {+ "type": "select",+ "mSelect": [+ { "content": "已完成", "color": "1" }+ ]+ }+ }+ ]+ },+ {+ "action": "setAttrViewSorts",+ "avID": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "data": [+ {+ "column": "20240118120204-w6cggab",+ "order": "DESC"+ }+ ]+ }+ ]+ }+ ]+ }+ ```++ * `reqId`: 必填。客户端生成的时间戳/随机数(数字),用于标记事务以支持撤销/重做+ * `app` / `session`: 可选。用于限定产生的 WebSocket 推送,使其它客户端/会话能刷新+ * `transactions[].doOperations[]`: 每个要替换的规则集对应一个操作+ * `doOperations[].action`: `setAttrViewFilters` 替换过滤规则,`setAttrViewSorts` 替换排序规则+ * `doOperations[].avID`: 数据库 ID+ * `doOperations[].blockID`: 拥有该视图的数据库块+ * `doOperations[].data`: 完整的 `ViewFilter` 或 `ViewSort` 新数组(结构见 [获取过滤与排序](#获取过滤与排序))。传 `[]` 可清空+* 返回值(真实响应,回显提交的操作,并附带服务端分配的 `timestamp`):++ ```json+ {+ "code": 0,+ "msg": "",+ "data": [+ {+ "timestamp": 1781610129661,+ "doOperations": [+ {+ "action": "setAttrViewFilters",+ "id": "",+ "avID": "20240118120204-kwyzf77",+ "blockID": "20240118120201-kldj15t",+ "data": [+ {+ "column": "20240118203822-io6ofxb",+ "operator": "=",+ "value": {+ "type": "select",+ "mSelect": [{ "content": "已完成", "color": "1" }]+ }+ }+ ]+ }+ ]+ }+ ]+ }+ ```++ * 调用成功后,可通过 [获取过滤与排序](#获取过滤与排序) 验证是否已持久化++### 添加字段++添加新字段(列)。该字段会被添加到每个视图(表格/卡片/看板)中 `previousKeyID` 之后的位置(为空时使用默认位置)。++* `/api/av/addAttributeViewKey`+* 参数++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "keyID": "20240118120204-7k9wzbp",+ "keyName": "状态",+ "keyType": "select",+ "keyIcon": "",+ "previousKeyID": "20240118120204-w6cggab"+ }+ ```++ * `avID`: 数据库 ID+ * `keyID`: 新字段 ID。需为 `Lute.NewNodeID()` 生成的合法节点 ID(14 位时间戳 + `-` + 7 位随机字母数字,如 `20240118120204-abc1234`)+ * `keyName`: 字段显示名+ * `keyType`: 字段类型——`text`、`number`、`date`、`select`、`mSelect`、`url`、`email`、`phone`、`mAsset`、`template`、`created`、`updated`、`checkbox`、`relation`、`rollup`、`lineNumber` 之一。`block`(主键)不能通过该接口添加+ * `keyIcon`: 可选字段图标(emoji 或空字符串)+ * `previousKeyID`: 在此字段 ID 之后插入新列。为空字符串时使用布局默认位置(表格插入到首位,卡片/看板插入到末尾)+* 返回值++ ```json+ {+ "code": 0,+ "msg": "",+ "data": null+ }+ ```++### 移除字段++移除字段(列)及其所有值。若 `keyID` 不存在,返回 `code: -1`、`msg: "key not found"`。++* `/api/av/removeAttributeViewKey`+* 参数++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "keyID": "20240118120204-7k9wzbp",+ "removeRelationDest": false+ }+ ```++ * `avID`: 数据库 ID+ * `keyID`: 要移除的字段 ID+ * `removeRelationDest`: 为 `true` 且字段为关联类型时,同时移除目标数据库中对应的反向关联字段。默认为 `false`+* 返回值++ ```json+ {+ "code": 0,+ "msg": "",+ "data": null+ }+ ```++### 设置全局字段排序++全局重排字段(列)——将 `keyID` 移动到字段顺序中 `previousKeyID` 之后的位置,影响所有视图。++* `/api/av/sortAttributeViewKey`+* 参数++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "keyID": "20240118203822-io6ofxb",+ "previousKeyID": "20240118120204-w6cggab"+ }+ ```++ * `avID`: 数据库 ID+ * `keyID`: 要移动的字段 ID+ * `previousKeyID`: `keyID` 应置于其后的字段 ID。为空字符串表示移动到首位+* 返回值++ ```json+ {+ "code": 0,+ "msg": "",+ "data": null+ }+ ```++### 设置视图内字段排序++在单个视图的布局内重排列(例如表格的列顺序),不改变全局字段顺序。++* `/api/av/sortAttributeViewViewKey`+* 参数++ ```json+ {+ "avID": "20240118120204-kwyzf77",+ "viewID": "20240118120204-7rnmyc1",+ "keyID": "20240118203822-io6ofxb",+ "previousKeyID": "20240118120204-w6cggab"+ }+ ```++ * `avID`: 数据库 ID+ * `viewID`: 目标视图。为空时使用当前视图+ * `keyID`: 要移动的字段 ID+ * `previousKeyID`: `keyID` 应置于其后的字段 ID。为空字符串表示移动到首位+* 返回值++ ```json+ {+ "code": 0,+ "msg": "",+ "data": null+ }+ ```