Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

スキーマ定義

スキーマは、コンテンツの構造とデータベースへの保存方法を定義します。

フィールド定義

スキーマ内の各フィールドには名前と設定があります:

schema:
  field_name:
    type: string
    required: true
    index: true

共通オプション

オプションデフォルト説明
typestring-フィールド型(必須)
requiredboolfalseフィールドが必須かどうか
indexboolfalseデータベースインデックスを作成

ネストされたレコード

records型を使用してネストされたテーブルを定義できます:

schema:
  id:
    type: id
  comments:
    type: records
    table: post_comments
    inherit_ids: [post_id]
    schema:
      comment_id:
        type: id
      text:
        type: string

これにより、外部キー関係を持つ別のpost_commentsテーブルが作成されます。

inherit_ids

inherit_idsオプションは、子テーブルに含める親IDを指定します:

comments:
  type: records
  inherit_ids: [post_id]  # post_idを外部キーとして含める

深くネストされたレコードの場合、複数のIDを継承できます:

replies:
  type: records
  inherit_ids: [post_id, comment_id]

schema:
  id:
    type: id
  title:
    type: string
    required: true
  published:
    type: datetime
    index: true
  draft:
    type: boolean
    index: true
  body:
    type: markdown
    storage:
      type: kv
      namespace: content
  tags:
    type: records
    table: post_tags
    inherit_ids: [post_id]
    schema:
      tag:
        type: id