K
Kysely15mo ago
Coffee11

Can this query translate to kysely?

sql`SELECT
frr.reimbursement_request_id,
frr.reference_no,
frrt.request_type,
fret.expense_type,
frrs.request_status,
frr.amount,
frr.attachment,
frr.attachment_mask_name,
frr.remarks,
u.full_name,
u.email,
u.employee_id,
u.hrbp_approver_email,
frr.payroll_date,
frr.date_approve,
frr.created_at,
frr.cursor_id::TEXT
${
data?.text_search
? sql`
,ts_rank(to_tsvector('english', coalesce(frr.text_search_properties, '')), websearch_to_tsquery(${data.text_search})) AS rank`
: sql``
}
FROM finance_reimbursement_requests as
WHERE to_tsvector('english', coalesce(frr.text_search_properties, '')) @@ websearch_to_tsquery(${data.text_search})
ORDER BY rank DESC
sql`SELECT
frr.reimbursement_request_id,
frr.reference_no,
frrt.request_type,
fret.expense_type,
frrs.request_status,
frr.amount,
frr.attachment,
frr.attachment_mask_name,
frr.remarks,
u.full_name,
u.email,
u.employee_id,
u.hrbp_approver_email,
frr.payroll_date,
frr.date_approve,
frr.created_at,
frr.cursor_id::TEXT
${
data?.text_search
? sql`
,ts_rank(to_tsvector('english', coalesce(frr.text_search_properties, '')), websearch_to_tsquery(${data.text_search})) AS rank`
: sql``
}
FROM finance_reimbursement_requests as
WHERE to_tsvector('english', coalesce(frr.text_search_properties, '')) @@ websearch_to_tsquery(${data.text_search})
ORDER BY rank DESC
2 Replies
koskimas
koskimas15mo ago
Yes, very very trivially. Please see the examples here https://kysely.dev/docs/category/examples
Coffee11
Coffee11OP15mo ago
I can't find any docs on how to add this into select in kysely
ts_rank(to_tsvector('english', coalesce(frr.text_search_properties, '')), websearch_to_tsquery(${data.text_search})) AS rank
ts_rank(to_tsvector('english', coalesce(frr.text_search_properties, '')), websearch_to_tsquery(${data.text_search})) AS rank
Want results from more Discord servers?
Add your server