(filterState: FilterState)
| 78 | } |
| 79 | |
| 80 | export function filterStateToSql(filterState: FilterState) { |
| 81 | let i = 1 |
| 82 | const sqlWhere = [] |
| 83 | const sqlParams = [] |
| 84 | if (filterState.status?.length) { |
| 85 | sqlWhere.push( |
| 86 | `status IN (${filterState.status.map(() => `$${i++}`).join(` ,`)})` |
| 87 | ) |
| 88 | sqlParams.push(...filterState.status) |
| 89 | } |
| 90 | if (filterState.priority?.length) { |
| 91 | sqlWhere.push( |
| 92 | `priority IN (${filterState.priority.map(() => `$${i++}`).join(` ,`)})` |
| 93 | ) |
| 94 | sqlParams.push(...filterState.priority) |
| 95 | } |
| 96 | if (filterState.query) { |
| 97 | sqlWhere.push(` |
| 98 | (setweight(to_tsvector('simple', coalesce(title, '')), 'A') || |
| 99 | setweight(to_tsvector('simple', coalesce(description, '')), 'B')) |
| 100 | @@ plainto_tsquery('simple', $${i++}) |
| 101 | `) |
| 102 | sqlParams.push(filterState.query) |
| 103 | } |
| 104 | const sql = ` |
| 105 | SELECT id, title, priority, status, modified, created, kanbanorder, username, synced |
| 106 | FROM issue |
| 107 | WHERE |
| 108 | ${sqlWhere.length ? `${sqlWhere.join(` AND `)} AND ` : ``} |
| 109 | deleted = false |
| 110 | ORDER BY |
| 111 | ${filterState.orderBy} ${filterState.orderDirection}, |
| 112 | id ASC |
| 113 | ` |
| 114 | return { sql, sqlParams } |
| 115 | } |
no test coverage detected