Remote / foldkit-remote-drizzle
queryPlans
function · packages/remote-drizzle/src/plans.ts:120
function queryPlans<P>(
cases: ReadonlyArray<{
readonly source: QuerySource<P, DrizzleDatabase>
readonly input: Readonly<Record<string, unknown>>
readonly principal: P
}>,
): Effect.Effect<ReadonlyArray<QueryPlan>, RemoteServerError, DrizzleDatabase>Each page the sources read for these inputs, a first and a later one, as
the database plans it, for every order a body offers its reader. Run it in
a test over a database migrated as production is: a page that is
sorted reads every matching row on every request.
ts
const plans = yield* queryPlans([
{ source: PostsByOwnerSource, input: { owner: 'u1' }, principal: null },
])
expect(plans.filter(plan => plan.verdict !== 'served')).toEqual([])The rows in the database decide whether there is a later page to plan, and
on SQLite which index the planner picks: seed a few. Only sources made by
query are planned.