Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi-target sources #379

Open
fwbrasil opened this issue May 25, 2016 · 8 comments
Open

multi-target sources #379

fwbrasil opened this issue May 25, 2016 · 8 comments

Comments

@fwbrasil
Copy link
Collaborator

fwbrasil commented May 25, 2016

Version: (e.g. 0.6.0)
Module: (e.g. quill-core)

Problem

Quill doesn't provide an easy way to switch to a different SQL dialect at runtime. Queries are generated at compile time and the application needs to be recompiled in order to run on another target dialect.

Solution

Introduce multi-target sources, that generate queries against multiple compatible target sources at compile-time and allows the user to choose the target source type at runtime.

By "compatible" target sources I mean sources that have the exact same method signatures. For instance, it'd be possible to have a

val s = source(new MultiSourceConfig(new JdbcConfig[SnakeCase, MysqlDialect]("mysql"), new JdbcConfig[Literal, H2Dialect]("h2"))

but not

val s = source(new MultiSourceConfig(new JdbcConfig[SnakeCase, MysqlDialect]("mysql"), new AsyncSource[Literal, H2Dialect]("h2")))

The macro would generate a message for all targets:

case class Person(fullName: String)

val s = source(new MultiSourceConfig(new JdbcConfig[SnakeCase, MysqlDialect]("mysql"), new JdbcConfig[Literal, H2Dialect]("h2"))

s.run(query[Person])
// compilation message
// mysql: SELECT full_name FROM person
// h2: SELECT fullName from Person

@getquill/maintainers

@mxl
Copy link
Contributor

mxl commented Dec 12, 2016

Workaround
You can build your application for each context to separate artefacts (jars) and make some supervisor process to stop application with one context and start with another.
See https://gitter.im/getquill/quill?at=58498469c29531ac5d393595.
Also this's useful for those who just want to build application for different environment like test and prod with different contexts.

@mxl
Copy link
Contributor

mxl commented Jan 20, 2017

I made an example project showing how to switch between MySQL and H2 JDBC contexts at compile-time. Do not forget to checkout quill-multiple-jdbc-contexts branch.

@mxl
Copy link
Contributor

mxl commented Jan 20, 2017

If someone needs to switch between sync (e. g. H2JdbcContext) and async (e. g. PostgresAsyncContext) then take a look at this sample project (checkout quill-multiple-mixed-contexts branch).

@fwbrasil fwbrasil removed the 1.0 label Jul 17, 2017
@fwbrasil
Copy link
Collaborator Author

@getquill/maintainers I've been thinking about this feature but I couldn't find a good way to implement it. I think I'll remove it from the 2.0 plans. It's too complex and I don't see push from the community to have it. Wdyt?

@fwbrasil
Copy link
Collaborator Author

fwbrasil commented Sep 21, 2017

I forgot to mention something. Even without this feature, users still can use multiple contexts using @mxl's approach or falling back to dynamic queries using #886

@mxl
Copy link
Contributor

mxl commented Sep 22, 2017

@fwbrasil 👌 We receive questions about context switching on Gitter channel occasionally. But people usually ask about compile-time context switching which can be done by above workaround though it does not work in all cases (for example, when switching sync and async contexts). I think that fixing bugs is top priority now and this feature can wait.

@mielientiev
Copy link

any progress or plans to resolve this issue?

@mosyp
Copy link
Collaborator

mosyp commented Nov 23, 2017

@getquill/maintainers I suggest to close this in favor of #971, since introducing multi-target sources should be avoided in favor of generating queries using idioms and io monad. Wdyt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants