Skip to content

selectTsquery

Subhajit Sahu edited this page Feb 12, 2020 · 2 revisions

Generates SQL command for SELECT with tsquery.

sql.selectTsquery(table, query, [tsvector], [options]);
// table: table name
// query: plain query words
// tsvector: tsvector ("tsvector")
// options:  options {columns, order, limit, normalization}
// .columns: select columns (*)
// .order:   order rows? (false)
// .limit:   limit rows (0 => no)
// .normalization: rank normalization (0 => ignores the document length)
const sql = require('extra-sql');

sql.selectTsquery('columns', 'total fat');
// SELECT * FROM "columns" WHERE "tsvector" @@ plainto_tsquery('total fat');
 
sql.selectTsquery('columns', 'total fat', '"tsvector"', {columns: '"code"'});
// SELECT "code" FROM "columns" WHERE "tsvector" @@ plainto_tsquery('total fat');
 
sql.selectTsquery('columns', 'total fat', '"tsvector"', {order: true, limit: 1, normalization: 2});
// SELECT * FROM "columns" WHERE "tsvector" @@ plainto_tsquery('total fat') ORDER BY ts_rank("tsvector", plainto_tsquery('total fat'), 2) DESC LIMIT 1;
Clone this wiki locally