Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I mix Ktor with Exposed?

I am writing a service using Ktor and Exposed ORM which apparently isn't async. I am coming from the Python world and back there using a blocking ORM with a async IO library is a sin as it may block all users in thread. Does the same rule apply in Kotlin? Am I creating a bad architecture?

like image 644
Kamyar Avatar asked Aug 18 '17 15:08

Kamyar


2 Answers

Exposed uses thread local storage to keep transaction instance accessible to implementation and avoid passing it along with every function call. Since transaction DSL function is executing synchronously and do not release a thread to be reusable by ktor for other calls there shouldn't be any issues with using them together.

like image 59
Ilya Ryzhenkov Avatar answered Nov 10 '22 22:11

Ilya Ryzhenkov


There is coroutine support in Exposed.

Please read the documentation:

https://github.com/JetBrains/Exposed/wiki/Transactions#working-with-coroutines

like image 30
Tapac Avatar answered Nov 10 '22 23:11

Tapac