© 2026 Hedgehog Software, LLC
const filters = []; // some filters here const total = db.$with("total").as( db .select({ count: count(tab.id) }) .from(tab) .where(and(...filters)) ); const result = await withPagination(db .with(total) .select({ tab: getTableColumns(tab), tab1: getTableColumns(tab1), tab2: getTableColumns(tab2), total: total, // not entirely sure what to do here or if even I understand it correctly }) .from(tab) .leftJoin(tab1, eq(tab.id, tab1.tabId)) .leftJoin(tab2, eq(tab.id, tab2.tabId)) .where(and(...filters)) .$dynamic() ); function withPagination<T extends SQLiteSelect>( props: { query: T; orderBy: SQL[]; } & Page ) { return props.query .orderBy(...props.orderBy) .limit(props.pageSize) .offset((props.page - 1) * props.pageSize); }