|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var Harness = require('./support'); |
| 4 | +var post = Harness.definePostTable(); |
| 5 | +var customerAlias = Harness.defineCustomerAliasTable(); |
| 6 | +var sql = require(__dirname + '/../../lib').setDialect('postgres'); |
| 7 | + |
| 8 | +//Postgres needs the to_tsquery function to use with @@ operator |
| 9 | +Harness.test({ |
| 10 | + query: post.select(post.star()).where(post.content.match(sql.functions.TO_TSQUERY('hello'))), |
| 11 | + pg: { |
| 12 | + text : 'SELECT "post".* FROM "post" WHERE ("post"."content" @@ TO_TSQUERY($1))', |
| 13 | + string: 'SELECT "post".* FROM "post" WHERE ("post"."content" @@ TO_TSQUERY(\'hello\'))' |
| 14 | + }, |
| 15 | + params: ['hello'] |
| 16 | +}); |
| 17 | + |
| 18 | + |
| 19 | +Harness.test({ |
| 20 | + query: post.select(post.star()).where(post.content.match('hello')), |
| 21 | + sqlite: { |
| 22 | + text : 'SELECT "post".* FROM "post" WHERE ("post"."content" MATCH $1)', |
| 23 | + string: 'SELECT "post".* FROM "post" WHERE ("post"."content" MATCH \'hello\')' |
| 24 | + }, |
| 25 | + mysql: { |
| 26 | + text : 'SELECT `post`.* FROM `post` WHERE (MATCH `post`.`content` AGAINST ?)', |
| 27 | + string: 'SELECT `post`.* FROM `post` WHERE (MATCH `post`.`content` AGAINST \'hello\')' |
| 28 | + }, |
| 29 | + mssql: { |
| 30 | + text : 'SELECT [post].* FROM [post] WHERE (CONTAINS ([post].[content], @1))', |
| 31 | + string: 'SELECT [post].* FROM [post] WHERE (CONTAINS ([post].[content], \'hello\'))' |
| 32 | + }, |
| 33 | + params: ['hello'] |
| 34 | +}); |
| 35 | + |
| 36 | +//matches, ordered by best rank first |
| 37 | +Harness.test({ |
| 38 | + query: post.select(post.id, sql.functions.TS_RANK_CD(post.content, sql.functions.TO_TSQUERY('hello')).as('rank')). |
| 39 | + where(post.content.match(sql.functions.TO_TSQUERY('hello'))).order(sql.functions.TS_RANK_CD(post.content, sql.functions.TO_TSQUERY('hello')).descending()), |
| 40 | + pg: { |
| 41 | + text : 'SELECT "post"."id", TS_RANK_CD("post"."content", TO_TSQUERY($1)) AS "rank" FROM "post" WHERE ("post"."content" @@ TO_TSQUERY($2)) ORDER BY TS_RANK_CD("post"."content", TO_TSQUERY($3)) DESC', |
| 42 | + string: 'SELECT "post"."id", TS_RANK_CD("post"."content", TO_TSQUERY(\'hello\')) AS "rank" FROM "post" WHERE ("post"."content" @@ TO_TSQUERY(\'hello\')) ORDER BY TS_RANK_CD("post"."content", TO_TSQUERY(\'hello\')) DESC' |
| 43 | + }, |
| 44 | + params: ['hello','hello','hello'] |
| 45 | +}); |
0 commit comments