import { Query } from '@vlcn.io/react' import { filterStateToOrder, filterStateToWhere } from '../utils/filterState' import { Schema as S } from './Schema' import { DecodedFilterState, Issue, PriorityType, StatusType, String_of } from './SchemaType' import { ID_of } from '@vlcn.io/id' // Types are auto-generated via `typed-sql` https://github.com/vlcn-io/typed-sql // run `pnpm sql-watch` to generate types export const queries = { totalIssueCount: S.sql<{ c: number }>`SELECT COUNT(*) AS c FROM issue`, filterState: S.sql<{ id: 'singleton' orderBy: string orderDirection: string status: String_of | null priority: String_of | null query: string | null }>`SELECT * FROM filter_state`, boardIssues: (filters: DecodedFilterState) => { return `SELECT * FROM issue ${filterStateToWhere(filters)} ORDER BY kanbanorder ASC` as Query }, listIssues: (filters: DecodedFilterState) => { return `SELECT * FROM issue ${filterStateToWhere(filters)} ${filterStateToOrder(filters)}` as Query }, issue: S.sql<{ id: ID_of title: string creator: string priority: 'none' | 'urgent' | 'high' | 'low' | 'medium' status: 'backlog' | 'todo' | 'in_progress' | 'done' | 'canceled' created: number modified: number kanbanorder: any }>`SELECT * FROM issue WHERE id = ?`, issueDescription: S.sql<{ id: ID_of body: string }>`SELECT * FROM description WHERE id = ?`, issueComments: S.sql<{ id: ID_of body: string creator: string issueId: ID_of created: number }>`SELECT * FROM comment WHERE issueId = ?`, }