Skip to content

Commit

Permalink
graph, store: Avoid a bind variable for fulltext queries
Browse files Browse the repository at this point in the history
We control the string we pass as the language, and therefore do not need to
use a bind variable. We just need to make sure we are passing a valid SQL
string constant
  • Loading branch information
lutter committed Dec 16, 2022
1 parent 1f0a9e7 commit 865d608
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
37 changes: 20 additions & 17 deletions graph/src/data/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,24 +163,27 @@ impl TryFrom<&str> for FulltextLanguage {
}

impl FulltextLanguage {
pub fn as_str(&self) -> &'static str {
/// Return the language as a valid SQL string. The string is safe to
/// directly use verbatim in a query, i.e., doesn't require being passed
/// through a bind variable
pub fn as_sql(&self) -> &'static str {
match self {
Self::Simple => "simple",
Self::Danish => "danish",
Self::Dutch => "dutch",
Self::English => "english",
Self::Finnish => "finnish",
Self::French => "french",
Self::German => "german",
Self::Hungarian => "hungarian",
Self::Italian => "italian",
Self::Norwegian => "norwegian",
Self::Portugese => "portugese",
Self::Romanian => "romanian",
Self::Russian => "russian",
Self::Spanish => "spanish",
Self::Swedish => "swedish",
Self::Turkish => "turkish",
Self::Simple => "'simple'",
Self::Danish => "'danish'",
Self::Dutch => "'dutch'",
Self::English => "'english'",
Self::Finnish => "'finnish'",
Self::French => "'french'",
Self::German => "'german'",
Self::Hungarian => "'hungarian'",
Self::Italian => "'italian'",
Self::Norwegian => "'norwegian'",
Self::Portugese => "'portugese'",
Self::Romanian => "'romanian'",
Self::Russian => "'russian'",
Self::Spanish => "'spanish'",
Self::Swedish => "'swedish'",
Self::Turkish => "'turkish'",
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions store/postgres/src/relational_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,10 +599,8 @@ impl<'a> QueryFragment<Pg> for QueryValue<'a> {
out.push_sql(") || ");
}
out.push_sql("to_tsvector(");
out.push_bind_param::<Text, _>(
&config.language.as_str().to_string(),
)?;
out.push_sql("::regconfig, ");
out.push_sql(config.language.as_sql());
out.push_sql(", ");
out.push_bind_param::<Text, _>(&value)?;
}
out.push_sql("))");
Expand Down

0 comments on commit 865d608

Please sign in to comment.