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 keeps the User row separate from Project. ProjectSource
emits owner = "User:u1", and RemoteServer follows that ref into UserSource
at the next selection level so the client cache stays normalized.