Slick for play using native SQL queries and stitching SQL

Source: Internet
Author: User

It's cool to manipulate the database on play with functional framework slick. But sometimes, because of some special scenarios, you have to use native SQL. Fortunately slick support this notation, you can look at slick official documents, slick Plain SQL queries


Here is my scene, one of my system has a table, because this system is also a technical staff, in order to facilitate directly on the table open a SQL query box, used to do conditional filtering. When the user enters the SQL where after the condition, need to put the conditions behind SQL, this is the use of slick native SQL execution mode.

The code is as follows:

Implicit val gethostresult = GetResult (r = = Host (r.<<, r.<<, r.<<, r.<<, r.<<, r.<< ;, r.<<, r.<<, r.<<, r.<<, r.<<= ((sql "SELECT * from Ops_host where 1=1 # $con Dition ". As[host]))

Note that Gethostresult is very important, it is used to convert the results returned by the SQL query, if you do not define Gethostresult, then the results can not be resolved, resulting in an error.

Another thing to be aware of is the # $condition

$ is used to pass a variable, but the value passed in will be enclosed in single quotes and will be escaped, that is, if you pass and Name= ' Lemontea ' will become ' and name=\ ' lemontea\ '

So in order not to be escaped, just add the # to the front.

Original articles, reproduced please indicate the source.

Slick for play using native SQL queries and stitching SQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.