Skip to content

Commit

Permalink
Merge pull request #61 from hmrc/TAV-519D
Browse files Browse the repository at this point in the history
TAV-519: Fix sql error
  • Loading branch information
Ardesco authored Apr 25, 2022
2 parents ebc4725 + 5f3f4f1 commit 3778a01
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions app/repositories/PostgresNonABPAddressRepository.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,17 @@ class PostgresNonABPAddressRepository @Inject()(transactor: Transactor[IO], quer

override def findInCountry(countryCode: String, filter: String): Future[List[NonUKAddress]] = {
val timeLimit = csql(s"SET statement_timeout=${queryConfig.queryTimeoutMillis};")
val limitSql = csql(s" LIMIT ${queryConfig.queryResultsLimit};")

val querySql = csql(
s"""
|SELECT id, number, street, unit, city, district, region, postcode
|FROM $countryCode
|WHERE address_lookup_ft_col @@ plainto_tsquery('english', '$filter');
|""".stripMargin)
| FROM $countryCode
| WHERE address_lookup_ft_col @@ plainto_tsquery('english', '$filter')
| LIMIT ${queryConfig.queryResultsLimit};""".stripMargin)

(for {
_ <- timeLimit.update.run.transact(transactor)
res <- (querySql ++ limitSql).query[NonUKAddress].to[List].transact(transactor)
} yield res).unsafeToFuture()
_ <- timeLimit.update.run.transact(transactor)
res <- querySql.query[NonUKAddress].to[List].transact(transactor)
} yield res).unsafeToFuture()
}
}

0 comments on commit 3778a01

Please sign in to comment.