MCPcopy Create free account
hub / github.com/electric-sql/electric / filterStateToSql

Function filterStateToSql

examples/linearlite/src/utils/filterState.ts:80–115  ·  view source on GitHub ↗
(filterState: FilterState)

Source from the content-addressed store, hash-verified

78}
79
80export 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}

Callers 2

issueListLoaderFunction · 0.90
boardIssueListLoaderFunction · 0.90

Calls 3

pushMethod · 0.45
joinMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected