db/cell_field_queries.ts

Raw queries against the cell_field table.

Named-relation primitive: each row is (source_id, name) → target_id, a JSON-object-shaped edge from one cell to another. (source_id, name) is unique — one target per name per source. Multiplicity by composition (target a collection cell whose items[] are the multi-valued tags), not by allowing duplicate field rows.

Reads filter both endpoints by cell.deleted_at IS NULL so relations dangling off a soft-deleted cell don't surface to the live graph, and the list reads apply the view predicate (db/cell_view_sql.ts) to the far end before LIMIT — a page is up to limit edges whose far end the caller can view.

query_cell_field_set upserts on the (source_id, name) PK so re-pointing a name updates target_id in place — JSON-object semantics (obj.foo = bar overwrites whatever was there).

view source

Declarations
#

7 declarations

CELL_FIELD_COLUMNS
#

CellFieldRow
#

db/cell_field_queries.ts view source

CellFieldRow import type {CellFieldRow} from '@fuzdev/fuz_app/db/cell_field_queries.js';

Row shape returned by cell_field SELECTs.

source_id

type Branded

name

type string

target_id

type Branded

created_at

type string

CellFieldSetQueryInput
#

query_cell_field_delete
#

db/cell_field_queries.ts view source

(deps: QueryDeps, source_id: Branded<string, "Uuid">, name: string): Promise<CellFieldRow | null> import {query_cell_field_delete} from '@fuzdev/fuz_app/db/cell_field_queries.js';

Delete a field row by primary key. Returns the deleted row so callers can audit the prior target_id without a pre-fetch.

deps

source_id

type Branded

name

type string

returns

Promise<CellFieldRow | null>

the deleted row, or null when no row matched (idempotent delete: a 200 response is correct even when nothing was deleted)

mutates

  • cell_field — deletes one row

query_cell_field_list_for_source
#

db/cell_field_queries.ts view source

(deps: QueryDeps, viewer: CellViewer, source_id: Branded<string, "Uuid">, options?: { limit?: number | undefined; name_after?: string | undefined; } | undefined): Promise<...> import {query_cell_field_list_for_source} from '@fuzdev/fuz_app/db/cell_field_queries.js';

Forward fields list (source.fields[]).

Up to limit fields whose target is live and one viewer may view (can_view_cell_sql, applied before the limit); name_after pages on. The source-view gate is the caller's responsibility.

deps

query deps

viewer

who is reading; CELL_VIEWER_UNRESTRICTED filters nothing

source_id

source cell id

type Branded

options?

limit caps the row count (omitted = unbounded); name_after resumes after a name (keyset pagination)

type { limit?: number | undefined; name_after?: string | undefined; }
optional

returns

Promise<CellFieldRow[]>

matching rows in lex name order

query_cell_field_list_for_target
#

db/cell_field_queries.ts view source

(deps: QueryDeps, viewer: CellViewer, target_id: Branded<string, "Uuid">, options?: { limit?: number | undefined; } | undefined): Promise<CellFieldRow[]> import {query_cell_field_list_for_target} from '@fuzdev/fuz_app/db/cell_field_queries.js';

Reverse fields list (target.upfields[]).

Up to limit fields whose source is live and one viewer may view — filtered before the limit (can_view_cell_sql), so sources the caller can't see never crowd out ones it can. The target-view gate is the caller's responsibility.

deps

query deps

viewer

who is reading; CELL_VIEWER_UNRESTRICTED filters nothing

target_id

target cell id

type Branded

options?

limit caps the row count (omitted = unbounded)

type { limit?: number | undefined; }
optional

returns

Promise<CellFieldRow[]>

matching rows, oldest field first (by the field row's created_at, then its key)

query_cell_field_set
#

db/cell_field_queries.ts view source

(deps: QueryDeps, input: CellFieldSetQueryInput): Promise<CellFieldRow> import {query_cell_field_set} from '@fuzdev/fuz_app/db/cell_field_queries.js';

Insert or update a field row.

UPSERT on (source_id, name) — re-setting the same name updates target_id and bumps created_at (timestamp reflects last write). Idempotent at the row level: caller can re-issue with the same input without checking existence first.

deps

query deps

input

source, name, target

returns

Promise<CellFieldRow>

the inserted-or-updated row

mutates

  • cell_field — inserts or updates one row

Depends on
#

Imported by
#