{"action":"created","issue":{"url":"https://api.github.com/repos/getquill/quill/issues/136","labels_url":"https://api.github.com/repos/getquill/quill/issues/136/labels{/name}","comments_url":"https://api.github.com/repos/getquill/quill/issues/136/comments","events_url":"https://api.github.com/repos/getquill/quill/issues/136/events","html_url":"https://github.com/getquill/quill/pull/136","id":130356521,"number":136,"title":"fix #11 - new sources creation mechanism","user":{"login":"fwbrasil","id":831175,"avatar_url":"https://avatars.githubusercontent.com/u/831175?v=3","gravatar_id":"","url":"https://api.github.com/users/fwbrasil","html_url":"https://github.com/fwbrasil","followers_url":"https://api.github.com/users/fwbrasil/followers","following_url":"https://api.github.com/users/fwbrasil/following{/other_user}","gists_url":"https://api.github.com/users/fwbrasil/gists{/gist_id}","starred_url":"https://api.github.com/users/fwbrasil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fwbrasil/subscriptions","organizations_url":"https://api.github.com/users/fwbrasil/orgs","repos_url":"https://api.github.com/users/fwbrasil/repos","events_url":"https://api.github.com/users/fwbrasil/events{/privacy}","received_events_url":"https://api.github.com/users/fwbrasil/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/getquill/quill/labels/in%20progress","name":"in progress","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-02-01T13:00:10Z","updated_at":"2016-02-01T13:25:38Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/getquill/quill/pulls/136","html_url":"https://github.com/getquill/quill/pull/136","diff_url":"https://github.com/getquill/quill/pull/136.diff","patch_url":"https://github.com/getquill/quill/pull/136.patch"},"body":"@godenji @lvicentesanchez  @KarelCemus @mariusmuja @rfranco I'd like to hear your thoughts on this. Don't worry if you can't review the code, just let me know how you like the new API.\r\n\r\n**Problem**\r\n\r\nSources are currently created using `object` values:\r\n\r\n```scala\r\nobject db extends JdbcSource[SnakeCase]\r\n```\r\n\r\nIf the user overrides members of JdbcSource, the query probing stops to work because the source class can't be loaded at compile time. This is a general problem with macros, it isn't possible to load a class that is currently under definition in the compilation unit. [Example](https://github.com/getquill/quill/issues/108):\r\n\r\n```scala\r\nobject db extends JdbcSource[ PostgresDialect, SnakeCase ] {\r\n  override protected val dataSource =\r\n    play.api.db.DB.getDataSource( )( play.api.Play.current ).asInstanceOf[ DataSource with Closeable ]\r\n}\r\n```\r\n\r\nThe current workaround is define the source in a separate compilation unit, so the class can be loaded when the probing macro runs.\r\n\r\nThere are two additional problems:\r\n\r\n* Sources can't be defined using the Repl because the query probing relies on runtime reflection\r\n* The user currently can't customize the typesafe config resolution\r\n\r\n**Solution**\r\n\r\nCreate a new mechanism similar to query quotations that allows the users to override behavior without having to use a separate compilation unit. Example\r\n\r\n```scala\r\nval db = source(new JdbcSourceConfig[PostgresDialect, SnakeCase](\"myConfigKey\"))\r\n```\r\n\r\nWith overridden member:\r\n\r\n```scala\r\nval db = source(\r\n  new JdbcSourceConfig[PostgresDialect, SnakeCase](\"myConfigKey\") {\r\n    override def dataSource =\r\n      play.api.db.DB.getDataSource( )( play.api.Play.current ).asInstanceOf[ DataSource with Closeable ]\r\n  }\r\n)\r\n```\r\n\r\n`source` will store the config tree using an annotation to make it accessible at compile time. It's a mechanism similar to query quotations. When the source is being instantiated by the query probing macro, the tree is evaluated by the macro context.\r\n\r\n**Caveats**\r\n\r\n* The new implementation uses the `eval` method from the macro context. This method is known to be problematic, so it is possible that more complex features used inside the `source` quotation fail to compile.\r\n* The source quotation can't have references to values outside of the quotation."},"comment":{"url":"https://api.github.com/repos/getquill/quill/issues/comments/177970471","html_url":"https://github.com/getquill/quill/pull/136#issuecomment-177970471","issue_url":"https://api.github.com/repos/getquill/quill/issues/136","id":177970471,"user":{"login":"schmitch","id":1641401,"avatar_url":"https://avatars.githubusercontent.com/u/1641401?v=3","gravatar_id":"","url":"https://api.github.com/users/schmitch","html_url":"https://github.com/schmitch","followers_url":"https://api.github.com/users/schmitch/followers","following_url":"https://api.github.com/users/schmitch/following{/other_user}","gists_url":"https://api.github.com/users/schmitch/gists{/gist_id}","starred_url":"https://api.github.com/users/schmitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/schmitch/subscriptions","organizations_url":"https://api.github.com/users/schmitch/orgs","repos_url":"https://api.github.com/users/schmitch/repos","events_url":"https://api.github.com/users/schmitch/events{/privacy}","received_events_url":"https://api.github.com/users/schmitch/received_events","type":"User","site_admin":false},"created_at":"2016-02-01T13:25:38Z","updated_at":"2016-02-01T13:25:38Z","body":"just for clarity \"myConfigKey\" will internally be called like `Config.atPath(\"myConfigKey\")`\r\nso that if I have a config like:\r\n\r\n``\r\n\r\nblabla.config.db.queryProbing=true\r\nblabla.config.db.dataSourceClassName=org.postgresql.ds.PGSimpleDataSource\r\nblabla.config.db.dataSource.user=root\r\nblabla.config.db.dataSource.password=root\r\nblabla.config.db.dataSource.databaseName=database\r\nblabla.config.db.dataSource.portNumber=5432\r\nblabla.config.db.dataSource.serverName=host\r\n``\r\n\r\nI would call it like that:\r\n\r\n```\r\nval db = source(new JdbcSourceConfig[PostgresDialect, SnakeCase](\"blabla.db.config\"))\r\n```\r\n\r\nCorrect?"}}