use super::*;
impl PgFunc {
pub fn to_tsquery<T>(expr: T, regconfig: Option<u32>) -> FunctionCall
where
T: Into<Expr>,
{
text_search(PgFunc::ToTsquery, expr.into(), regconfig)
}
pub fn to_tsvector<T>(expr: T, regconfig: Option<u32>) -> FunctionCall
where
T: Into<Expr>,
{
text_search(PgFunc::ToTsvector, expr.into(), regconfig)
}
pub fn phraseto_tsquery<T>(expr: T, regconfig: Option<u32>) -> FunctionCall
where
T: Into<Expr>,
{
text_search(PgFunc::PhrasetoTsquery, expr.into(), regconfig)
}
pub fn plainto_tsquery<T>(expr: T, regconfig: Option<u32>) -> FunctionCall
where
T: Into<Expr>,
{
text_search(PgFunc::PlaintoTsquery, expr.into(), regconfig)
}
pub fn websearch_to_tsquery<T>(expr: T, regconfig: Option<u32>) -> FunctionCall
where
T: Into<Expr>,
{
text_search(PgFunc::WebsearchToTsquery, expr.into(), regconfig)
}
pub fn ts_rank<T>(vector: T, query: T) -> FunctionCall
where
T: Into<Expr>,
{
FunctionCall::new(PgFunc::TsRank).args([vector.into(), query.into()])
}
pub fn ts_rank_cd<T>(vector: T, query: T) -> FunctionCall
where
T: Into<Expr>,
{
FunctionCall::new(PgFunc::TsRankCd).args([vector.into(), query.into()])
}
pub fn any<T>(expr: T) -> FunctionCall
where
T: Into<Expr>,
{
FunctionCall::new(PgFunc::Any).arg(expr)
}
pub fn some<T>(expr: T) -> FunctionCall
where
T: Into<Expr>,
{
FunctionCall::new(PgFunc::Some).arg(expr)
}
pub fn all<T>(expr: T) -> FunctionCall
where
T: Into<Expr>,
{
FunctionCall::new(PgFunc::All).arg(expr)
}
}
fn text_search(func: PgFunc, expr: Expr, regconfig: Option<u32>) -> FunctionCall {
match regconfig {
Some(config) => FunctionCall::new(func).args([Expr::Value(config.into()), expr]),
None => FunctionCall::new(func).arg(expr),
}
}