Tearleads

document_calendar_items Client SQLite table

Normalized calendar items projected from hydrated Loro documents (both calendar events and virtual dates such as expirations, birthdays, and to-do due dates).

Declared in packages/client-sdk/src/data/sqlite/schema/documentCalendarSchema.ts

Description

An explicit INTEGER PRIMARY KEY column (calendar_item_rowid) anchors both external-content FTS5 virtual tables (document_calendar_items_fts_word with unicode61 and document_calendar_items_fts_trigram with trigram) so SQLite VACUUM never renumbers rowids under FTS5.

Re-indexing a document deletes its items and inserts the new projection. Text fields are trimmed, dates are YYYY-MM-DD, and clock times are 24-hour HH:MM.

Columns

  • calendar_item_rowidinteger
    • primary key
    • nullable

    Rowid assigned by SQLite on insert; the FTS5 tables key their entries by it.

  • local_idtext
    • not null

    Local document id the item was projected from.

  • item_keytext
    • not null

    Item key, unique within the document, that the document's projector supplies, such as event:<row id> or field:<field key>.

  • categorytext
    • not null

    event, expiration, birthday, or todo_due.

  • titletext
    • not null
    • default ''

    Title on one line, at most 512 characters.

  • all_dayinteger
    • not null
    • default 1

    1 for an all-day item, 0 for a timed one. An item without a valid start time is all-day.

  • start_datetext
    • not null

    First date of the item.

  • start_timetext
    • nullable

    Start time; null for an all-day item.

  • end_datetext
    • not null

    Last date of the item; never before startDate, and equal to it when the source gives none.

  • end_timetext
    • nullable

    End time; null for an all-day item, when unset, or when it falls before the start time on a single-day item.

  • time_zonetext
    • nullable

    Time zone name for the item's times; null when none is set.

  • locationtext
    • not null
    • default ''

    Location on one line, at most 512 characters; empty when none.

  • notestext
    • not null
    • default ''

    Notes, which keep line breaks, at most 4,096 characters; empty when none.

  • repeattext
    • not null
    • default ''

    Recurrence: empty for none, or daily, weekdays, weekly, monthly, or yearly.

  • repeat_intervalinteger
    • not null
    • default 1

    Repeat every this many periods, 1 to 999; 1 when the item does not repeat.

  • repeat_untiltext
    • nullable

    Last date an occurrence may start on, never before startDate; null when the recurrence has no end or the item does not repeat.

  • exdatestext
    • not null
    • default ''

    Comma-separated, sorted, distinct dates the recurrence skips; empty when none.

  • row_idtext
    • nullable

    Id of the document row the item came from, such as an event or to-do row; null for items taken from a document field.

Keys and constraints

  • Unique(local_id, item_key)

Indexes

  • document_calendar_items_repeat_dates_idx(repeat, start_date, end_date)
    • document_calendar_items_category_dates_idx(category, start_date)

      DDL

      The statements the client runs to create this table and its indexes.

      CREATE TABLE IF NOT EXISTS "document_calendar_items" (
        "calendar_item_rowid" INTEGER PRIMARY KEY,
        "local_id" TEXT NOT NULL,
        "item_key" TEXT NOT NULL,
        "category" TEXT NOT NULL,
        "title" TEXT NOT NULL DEFAULT '',
        "all_day" INTEGER NOT NULL DEFAULT 1,
        "start_date" TEXT NOT NULL,
        "start_time" TEXT,
        "end_date" TEXT NOT NULL,
        "end_time" TEXT,
        "time_zone" TEXT,
        "location" TEXT NOT NULL DEFAULT '',
        "notes" TEXT NOT NULL DEFAULT '',
        "repeat" TEXT NOT NULL DEFAULT '',
        "repeat_interval" INTEGER NOT NULL DEFAULT 1,
        "repeat_until" TEXT,
        "exdates" TEXT NOT NULL DEFAULT '',
        "row_id" TEXT,
        UNIQUE ("local_id", "item_key")
      );
      
      CREATE INDEX IF NOT EXISTS "document_calendar_items_repeat_dates_idx" ON "document_calendar_items" ("repeat", "start_date", "end_date");
      
      CREATE INDEX IF NOT EXISTS "document_calendar_items_category_dates_idx" ON "document_calendar_items" ("category", "start_date");