Remote / foldkit-remote-drizzle

Singular relations

Declare a foreign key once with one:

ts
import { entity, one } from 'foldkit-remote-drizzle'

const User = entity('User', users)

const Project = entity('Project', projects, {
  relations: {
    owner: one(User, { field: projects.ownerId }),
  },
})

Now owner is a Remote ref field:

ts
const ProjectSummary = Project.select({
  id: true,
  name: true,
  owner: true,
})

The Source selects owner_id but emits the Remote ref key:

row:         owner_id = u1
wire value:  owner = "User:u1"
client:      { entity: 'User', id: 'u1' }

If the foreign key is nullable, declare that explicitly:

ts
owner: one(User, {
  field: projects.ownerId,
  nullable: true,
})

A database NULL then becomes a present null in Remote rather than looking like an absent field that should be fetched forever.

A nested Selection does not embed the User row into Project. RemoteServer follows the ref into the User Source at the next selection level, preserving the normalized cache:

Project:p1.owner -> User:u1
                      |
                      v
                 User Source