Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to run raw sql with Kotlin's Exposed library

I'm trying to run some sql specific to postgres and would like to reuse the transaction management within Exposed.

like image 838
pondermatic Avatar asked Dec 05 '16 19:12

pondermatic


People also ask

Should I use raw SQL or ORM?

ORM is good only for developers and maintenance because most developers aren't very good at SQL, but if you're actually talking about performance, SQL completely trumps it.

Should I use raw SQL?

Conclusion. Raw SQL is for sure the most powerful way to interact with your database as it is the databases native language. The drawback is that you might use features which are specific to that database, which makes a future database switch harder.

What is raw SQL query?

Raw SQL queries are useful if the query you want can't be expressed using LINQ. Raw SQL queries are also used if using a LINQ query is resulting in an inefficient SQL query. Raw SQL queries can return regular entity types or keyless entity types that are part of your model.


1 Answers

Exposed has the Transaction.exec(String) method which probably does what you want. See https://github.com/JetBrains/Exposed/blob/master/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/mysql/MysqlTests.kt

like image 98
Kiskae Avatar answered Sep 17 '22 10:09

Kiskae