# テーブル、フィールド、レコード

- Human documentation: [https://docs.univer.ai/ja-JP/guides/bases/model/tables-fields-records](https://docs.univer.ai/ja-JP/guides/bases/model/tables-fields-records)

- Agent Markdown: [https://docs.univer.ai/ja-JP/guides/bases/model/tables-fields-records.md](https://docs.univer.ai/ja-JP/guides/bases/model/tables-fields-records.md)

- Requested language: `ja-JP`

- Content language: `ja-JP`

- Documentation version: `1.2.0`

- Source: [bases/model/tables-fields-records.ja-JP.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/bases/model/tables-fields-records.ja-JP.mdx)

---

Baseには、順序付けられたテーブルが含まれます。各テーブルには、フィールド定義、レコード値、オプションのセルデータ行列、リソース、ビュー、およびレンダリングや検索のロジックで使用するインデックスが含まれます。

新しいテーブルのレコード数は 0 です。Facade API またはインポートするスナップショットで明示的に追加してください。

## テーブルのスナップショット

| プロパティ          | 型                                   | 説明                        |
| -------------- | ----------------------------------- | ------------------------- |
| id             | `string`                            | テーブルID。                   |
| name           | `string`                            | テーブル名。                    |
| fields         | `Record\<string, IFieldSnapshot\>`  | フィールドIDをキーとするフィールド定義。     |
| fieldOrder     | `string[]`                          | フィールドIDを順番に並べたリスト。        |
| records        | `Record\<string, IRecordSnapshot\>` | レコードIDをキーとするレコードデータ。      |
| recordOrder?   | `string[]`                          | レコードIDを順番に並べたリスト。         |
| primaryFieldId | `string`                            | プライマリフィールドのID。            |
| views          | `Record\<string, IViewSnapshot\>`   | ビューIDをキーとするビュー。           |
| viewOrder      | `string[]`                          | ビューIDを順番に並べたリスト。          |
| resources?     | `IBaseResources`                    | 選択肢、メンバー、添付ファイルで共有するリソース。 |

## フィールドのスナップショット

| プロパティ         | 型                           | 説明                  |
| ------------- | --------------------------- | ------------------- |
| id            | `string`                    | フィールドID。            |
| name          | `string`                    | フィールド名。             |
| description?  | `string`                    | フィールドの説明。           |
| type          | `BaseFieldType`             | フィールドの型。            |
| config        | `Record\<string, unknown\>` | フィールド型固有の設定。        |
| defaultValue? | `BaseCellValue`             | 新しいレコードのデフォルト値。     |
| system?       | `boolean`                   | システムが管理するフィールドかどうか。 |
| readonly?     | `boolean`                   | 値が読み取り専用かどうか。       |

## フィールド型

一般的なフィールド型には、`text`、`number`、`currency`、`progress`、`rating`、`checkbox`、`singleSelect`、`multiSelect`、`person`、`group`、`date`、`attachment`、`formula`、`createdAt`、`updatedAt`、`createdBy`、`updatedBy` があります。

アプリケーションコードを作成するときは、Facadeの列挙型を使用します。

```ts
const field = table.addField('Due date', univerAPI.Enum.BaseFieldType.Date)
```

## レコードのスナップショット

| プロパティ      | 型                                 | 説明                |
| ---------- | --------------------------------- | ----------------- |
| id         | `string`                          | レコードID。           |
| values     | `Record\<string, BaseCellValue\>` | フィールドIDをキーとする値。   |
| orderKey   | `string`                          | 順序を安定して保持するためのキー。 |
| createdAt  | `number`                          | 作成時のタイムスタンプ。      |
| updatedAt  | `number`                          | 更新時のタイムスタンプ。      |
| createdBy? | `string`                          | 作成者のID。           |
| updatedBy? | `string`                          | 最終更新者のID。         |

## Facadeの例

```ts
const table = base.insertTable('Tasks', { primaryFieldName: 'Title' })
const title = table.getPrimaryField()
const status = table.addField('Status', univerAPI.Enum.BaseFieldType.SingleSelect)

const record = table.addRecord({
  [title.getId()]: 'Write guide',
  [status.getId()]: 'In progress',
})
```
