import { type Column, type Relation, type SQL, type Table } from 'drizzle-orm'; import type { DrizzleClient } from '../types.js'; /** The public client's SQL construction capability. */ export type RelationQueryBuilder = Pick; export interface RelationFilter { /** * A predicate over the target table alone, for the places where only the target table is in * scope: a `where` handed to a user `select`, or a count that selects from the target table. * SQLite many-to-many relations with a non-null unique target key project identities through * Drizzle's join. Other cases use an `exists` over the junction. */ filter: SQL; /** * Counts the rows the relation yields, as an expression for the surrounding query to select. * A many-to-many relation joins the junction table in, so the count matches the rows the * relational query builder returns for the same relation, junction duplicates included. * * `where` is the predicate the page query was given, and it goes ahead of the relation's own * predicate because that is the order the relational query builder combines the two in. The * count then repeats the page query's `where` verbatim, minus the limit and keyset clauses. */ countRows: (where?: SQL) => SQL; /** * Counts the distinct target rows the relation reaches, for the callers that count a related * row once however many junction rows lead to it. `key` identifies a target row, so it has to * be a single column the database guarantees is unique and non-null. * * This counts off the junction rather than counting the target table filtered by `filter`, * which says the same thing the long way round: the join reads the junction rows the parent * reaches and stops, where the filter reads the same rows and then looks every key it found * back up in the target table. */ countDistinctRows: (key: Column, where?: SQL) => SQL; } /** * The parent-to-child SQL for one relation, built by drizzle so the plugin agrees with the * relational query builder on what "related" means: `through` (many-to-many), the relation's own * `where`, and a reversed relation's inherited `where` all come from drizzle rather than from a * join reassembled here out of source and target columns. * * Both the join and its restrictions come from `relationToSQL`, including when the target is * aliased for the identity lookup. No junction columns or comparisons are reconstructed here. * * `parentTable` is the parent as it appears in the surrounding query, so the aliased table when * the query builder aliased it. */ export declare function buildRelationFilter(client: RelationQueryBuilder, relation: Relation, parentTable: Table, targetKey?: Column[]): RelationFilter; //# sourceMappingURL=relation-filter.d.ts.map