JetBrains / Exposed

Kotlin SQL Framework
http://jetbrains.github.io/Exposed/
Apache License 2.0
8.33k stars 694 forks source link

Support for creating a query to be executed later #337

Open jvskriubakken opened 6 years ago

jvskriubakken commented 6 years ago

I'm quite thrilled over a typed SQL api as Exposed and see it's great potential to leverage typed queries on the client side of an application and then serialized as JSON and transferred to server, deserialized and finally executed. This would give both super powers and development speed to SPA applications.

I'm trying to understand if this is possible, but cant't really see any strong evidence of it. Any one amped to clarify?

Cheers, Jørund

Tapac commented 6 years ago

Hi @jvskriubakken , I'm not sure that it's quite easy to use Exposed on client-side because it's tightly bound to Java backend (jdbc-driver) and doesn't provide any common DSL part to be shared in MPP code.

Also, I'm not sure that executing something prepared on client-side is a good idea due to the possibility to SQL-Injections + you expose your data model to everyone. Maybe it's better to look at something like GraphQL (https://github.com/JetBrains/Exposed/issues/316) ?

NekoiNemo commented 6 years ago

Security concerns aside, how's that different from just using Exposed to generate request and passing it as string to server?

Tapac commented 6 years ago

I'm not quite understand how it can be used on client side? What do you mean by client here: browser or mobile app?

NekoiNemo commented 6 years ago

Not sure either. But from the looks of it, it might be possible with some modifications: Statement.prepareSQL() returns prepared request as String, so it could be serialised (along with parameters) and sent to server. Granted method requires Transaction as parameter, but it seems that it only uses it to extract the dialect for the db used by this transaction.

So with some light alterations it would be possible to make a light (possibly even not JVM-dependent) client version of exposed that would just generate prepared requests, that server could then execute with Transaction.exec()... I'm just not sure what the point of it would be.

Tapac commented 6 years ago

It might be possible if DSL part of Exposed will be available as a common kotlin module with a possibility to prepare sql on different backends. I'll discuss it with my colleagues and maybe we'll plan it on future releases.