{"action":"created","comment":{"url":"https://api.github.com/repos/graphcool/prisma/pulls/comments/183377115","pull_request_review_id":114361507,"id":183377115,"diff_hunk":"@@ -0,0 +1,248 @@\n+package com.prisma.api.connector.postgresql.database\n+\n+import java.sql.{PreparedStatement, ResultSet}\n+\n+import com.prisma.api.connector.Types.DataItemFilterCollection\n+import com.prisma.api.connector._\n+import com.prisma.gc_values._\n+import com.prisma.shared.models.IdType.Id\n+import com.prisma.shared.models.{Function => _, _}\n+import slick.dbio.DBIOAction\n+import slick.jdbc.PostgresProfile.api._\n+import slick.jdbc.{SQLActionBuilder, _}\n+import slick.sql.SqlStreamingAction\n+\n+import scala.concurrent.ExecutionContext.Implicits.global\n+\n+object PostgresApiDatabaseQueryBuilder {\n+  import JdbcExtensions._\n+  import QueryArgumentsExtensions._\n+  import SlickExtensions._\n+\n+  def getResultForModel(model: Model): GetResult[PrismaNode] = GetResult { ps: PositionedResult =>\n+    getPrismaNode(model, ps)\n+  }\n+\n+  private def getPrismaNode(model: Model, ps: PositionedResult) = {\n+    val data = model.scalarNonListFields.map(field => field.name -> ps.rs.getGcValue(field.name, field.typeIdentifier))\n+\n+    PrismaNode(id = ps.rs.getId, data = RootGCValue(data: _*))\n+  }\n+\n+  def getResultForModelAndRelationSide(model: Model, side: String, oppositeSide: String): GetResult[PrismaNodeWithParent] = GetResult { ps: PositionedResult =>\n+    val node       = getPrismaNode(model, ps)\n+    val firstSide  = ps.rs.getParentId(side)\n+    val secondSide = ps.rs.getParentId(oppositeSide)\n+    val parentId   = if (firstSide == node.id) secondSide else firstSide\n+\n+    PrismaNodeWithParent(parentId, node)\n+  }\n+\n+  implicit object GetRelationNode extends GetResult[RelationNode] {\n+    override def apply(ps: PositionedResult): RelationNode = RelationNode(ps.rs.getId, ps.rs.getAsID(\"A\"), ps.rs.getAsID(\"B\"))\n+\n+  }\n+\n+  implicit object GetRelationCount extends GetResult[(IdGCValue, Int)] {\n+    override def apply(ps: PositionedResult): (IdGCValue, Int) = (ps.rs.getId, ps.rs.getInt(\"Count\"))\n+  }\n+\n+  def getResultForScalarListField(field: Field): GetResult[ScalarListElement] = GetResult { ps: PositionedResult =>\n+    val resultSet = ps.rs\n+    val nodeId    = resultSet.getString(\"nodeId\")\n+    val position  = resultSet.getInt(\"position\")\n+    val value     = resultSet.getGcValue(\"value\", field.typeIdentifier)\n+    ScalarListElement(nodeId, position, value)\n+  }\n+\n+  def selectAllFromTable(\n+      projectId: String,\n+      model: Model,\n+      args: Option[QueryArguments],\n+      overrideMaxNodeCount: Option[Int] = None\n+  ): DBIOAction[ResolverResult[PrismaNode], NoStream, Effect] = {\n+\n+    val tableName                                        = model.name\n+    val (conditionCommand, orderByCommand, limitCommand) = extractQueryArgs(projectId, tableName, args, None, overrideMaxNodeCount = overrideMaxNodeCount)\n+\n+    val query = sql\"\"\"select * from \"#$projectId\".\"#$tableName\"\"\"\" ++\n+      prefixIfNotNone(\"where\", conditionCommand) ++\n+      prefixIfNotNone(\"order by\", orderByCommand) ++\n+      prefixIfNotNone(\"limit\", limitCommand)\n+\n+    query.as[PrismaNode](getResultForModel(model)).map(args.get.resultTransform)\n+  }\n+\n+  def selectAllFromRelationTable(\n+      projectId: String,\n+      relationId: String,\n+      args: Option[QueryArguments],\n+      overrideMaxNodeCount: Option[Int] = None\n+  ): DBIOAction[ResolverResult[RelationNode], NoStream, Effect] = {\n+\n+    val tableName                                        = relationId\n+    val (conditionCommand, orderByCommand, limitCommand) = extractQueryArgs(projectId, tableName, args, None, overrideMaxNodeCount = overrideMaxNodeCount)\n+\n+    val query = sql\"\"\"select * from \"#$projectId\".\"#$tableName\"\"\"\" ++\n+      prefixIfNotNone(\"where\", conditionCommand) ++\n+      prefixIfNotNone(\"order by\", orderByCommand) ++\n+      prefixIfNotNone(\"limit\", limitCommand)\n+\n+    query.as[RelationNode].map(args.get.resultTransform)\n+  }\n+\n+  def selectAllFromListTable(projectId: String,\n+                             model: Model,\n+                             field: Field,\n+                             args: Option[QueryArguments],\n+                             overrideMaxNodeCount: Option[Int] = None): DBIOAction[ResolverResult[ScalarListValues], NoStream, Effect] = {\n+\n+    val tableName                                        = s\"${model.name}_${field.name}\"\n+    val (conditionCommand, orderByCommand, limitCommand) = extractQueryArgs(projectId, tableName, args, None, overrideMaxNodeCount = overrideMaxNodeCount, true)\n+\n+    val query =","path":"server/connectors/api-connector-postgresql/src/main/scala/com/prisma/api/connector/postgresql/database/PostgresApiDatabaseQueryBuilder.scala","position":103,"original_position":103,"commit_id":"9958b6de78240bc055d34ca5914db607260857e2","original_commit_id":"9958b6de78240bc055d34ca5914db607260857e2","user":{"login":"codacy-bot","id":19940114,"avatar_url":"https://avatars1.githubusercontent.com/u/19940114?v=4","gravatar_id":"","url":"https://api.github.com/users/codacy-bot","html_url":"https://github.com/codacy-bot","followers_url":"https://api.github.com/users/codacy-bot/followers","following_url":"https://api.github.com/users/codacy-bot/following{/other_user}","gists_url":"https://api.github.com/users/codacy-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/codacy-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codacy-bot/subscriptions","organizations_url":"https://api.github.com/users/codacy-bot/orgs","repos_url":"https://api.github.com/users/codacy-bot/repos","events_url":"https://api.github.com/users/codacy-bot/events{/privacy}","received_events_url":"https://api.github.com/users/codacy-bot/received_events","type":"User","site_admin":false},"body":"![Codacy](https://app.codacy.com/assets/images/favicon.png) Issue found: [Don't use SELECT * in SQL queries](https://app.codacy.com/app/graphcool/prisma/pullRequest?prid=1559610)","created_at":"2018-04-23T12:32:52Z","updated_at":"2018-04-23T12:32:52Z","html_url":"https://github.com/graphcool/prisma/pull/2238#discussion_r183377115","pull_request_url":"https://api.github.com/repos/graphcool/prisma/pulls/2238","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/graphcool/prisma/pulls/comments/183377115"},"html":{"href":"https://github.com/graphcool/prisma/pull/2238#discussion_r183377115"},"pull_request":{"href":"https://api.github.com/repos/graphcool/prisma/pulls/2238"}}},"pull_request":{"url":"https://api.github.com/repos/graphcool/prisma/pulls/2238","id":182745182,"html_url":"https://github.com/graphcool/prisma/pull/2238","diff_url":"https://github.com/graphcool/prisma/pull/2238.diff","patch_url":"https://github.com/graphcool/prisma/pull/2238.patch","issue_url":"https://api.github.com/repos/graphcool/prisma/issues/2238","number":2238,"state":"open","locked":false,"title":"[WIP] Postgres integration with new config format","user":{"login":"dpetrick","id":4272382,"avatar_url":"https://avatars0.githubusercontent.com/u/4272382?v=4","gravatar_id":"","url":"https://api.github.com/users/dpetrick","html_url":"https://github.com/dpetrick","followers_url":"https://api.github.com/users/dpetrick/followers","following_url":"https://api.github.com/users/dpetrick/following{/other_user}","gists_url":"https://api.github.com/users/dpetrick/gists{/gist_id}","starred_url":"https://api.github.com/users/dpetrick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpetrick/subscriptions","organizations_url":"https://api.github.com/users/dpetrick/orgs","repos_url":"https://api.github.com/users/dpetrick/repos","events_url":"https://api.github.com/users/dpetrick/events{/privacy}","received_events_url":"https://api.github.com/users/dpetrick/received_events","type":"User","site_admin":false},"body":"tbd","created_at":"2018-04-19T11:23:46Z","updated_at":"2018-04-23T12:32:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"05d12a6c1e84570dd1b1f1801ca6feff365c4b80","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/graphcool/prisma/pulls/2238/commits","review_comments_url":"https://api.github.com/repos/graphcool/prisma/pulls/2238/comments","review_comment_url":"https://api.github.com/repos/graphcool/prisma/pulls/comments{/number}","comments_url":"https://api.github.com/repos/graphcool/prisma/issues/2238/comments","statuses_url":"https://api.github.com/repos/graphcool/prisma/statuses/9958b6de78240bc055d34ca5914db607260857e2","head":{"label":"graphcool:config_integration","ref":"config_integration","sha":"9958b6de78240bc055d34ca5914db607260857e2","user":{"login":"graphcool","id":17219288,"avatar_url":"https://avatars0.githubusercontent.com/u/17219288?v=4","gravatar_id":"","url":"https://api.github.com/users/graphcool","html_url":"https://github.com/graphcool","followers_url":"https://api.github.com/users/graphcool/followers","following_url":"https://api.github.com/users/graphcool/following{/other_user}","gists_url":"https://api.github.com/users/graphcool/gists{/gist_id}","starred_url":"https://api.github.com/users/graphcool/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/graphcool/subscriptions","organizations_url":"https://api.github.com/users/graphcool/orgs","repos_url":"https://api.github.com/users/graphcool/repos","events_url":"https://api.github.com/users/graphcool/events{/privacy}","received_events_url":"https://api.github.com/users/graphcool/received_events","type":"Organization","site_admin":false},"repo":{"id":69164196,"name":"prisma","full_name":"graphcool/prisma","owner":{"login":"graphcool","id":17219288,"avatar_url":"https://avatars0.githubusercontent.com/u/17219288?v=4","gravatar_id":"","url":"https://api.github.com/users/graphcool","html_url":"https://github.com/graphcool","followers_url":"https://api.github.com/users/graphcool/followers","following_url":"https://api.github.com/users/graphcool/following{/other_user}","gists_url":"https://api.github.com/users/graphcool/gists{/gist_id}","starred_url":"https://api.github.com/users/graphcool/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/graphcool/subscriptions","organizations_url":"https://api.github.com/users/graphcool/orgs","repos_url":"https://api.github.com/users/graphcool/repos","events_url":"https://api.github.com/users/graphcool/events{/privacy}","received_events_url":"https://api.github.com/users/graphcool/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/graphcool/prisma","description":"⚡️ Prisma turns your database into a realtime GraphQL API","fork":false,"url":"https://api.github.com/repos/graphcool/prisma","forks_url":"https://api.github.com/repos/graphcool/prisma/forks","keys_url":"https://api.github.com/repos/graphcool/prisma/keys{/key_id}","collaborators_url":"https://api.github.com/repos/graphcool/prisma/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/graphcool/prisma/teams","hooks_url":"https://api.github.com/repos/graphcool/prisma/hooks","issue_events_url":"https://api.github.com/repos/graphcool/prisma/issues/events{/number}","events_url":"https://api.github.com/repos/graphcool/prisma/events","assignees_url":"https://api.github.com/repos/graphcool/prisma/assignees{/user}","branches_url":"https://api.github.com/repos/graphcool/prisma/branches{/branch}","tags_url":"https://api.github.com/repos/graphcool/prisma/tags","blobs_url":"https://api.github.com/repos/graphcool/prisma/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/graphcool/prisma/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/graphcool/prisma/git/refs{/sha}","trees_url":"https://api.github.com/repos/graphcool/prisma/git/trees{/sha}","statuses_url":"https://api.github.com/repos/graphcool/prisma/statuses/{sha}","languages_url":"https://api.github.com/repos/graphcool/prisma/languages","stargazers_url":"https://api.github.com/repos/graphcool/prisma/stargazers","contributors_url":"https://api.github.com/repos/graphcool/prisma/contributors","subscribers_url":"https://api.github.com/repos/graphcool/prisma/subscribers","subscription_url":"https://api.github.com/repos/graphcool/prisma/subscription","commits_url":"https://api.github.com/repos/graphcool/prisma/commits{/sha}","git_commits_url":"https://api.github.com/repos/graphcool/prisma/git/commits{/sha}","comments_url":"https://api.github.com/repos/graphcool/prisma/comments{/number}","issue_comment_url":"https://api.github.com/repos/graphcool/prisma/issues/comments{/number}","contents_url":"https://api.github.com/repos/graphcool/prisma/contents/{+path}","compare_url":"https://api.github.com/repos/graphcool/prisma/compare/{base}...{head}","merges_url":"https://api.github.com/repos/graphcool/prisma/merges","archive_url":"https://api.github.com/repos/graphcool/prisma/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/graphcool/prisma/downloads","issues_url":"https://api.github.com/repos/graphcool/prisma/issues{/number}","pulls_url":"https://api.github.com/repos/graphcool/prisma/pulls{/number}","milestones_url":"https://api.github.com/repos/graphcool/prisma/milestones{/number}","notifications_url":"https://api.github.com/repos/graphcool/prisma/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/graphcool/prisma/labels{/name}","releases_url":"https://api.github.com/repos/graphcool/prisma/releases{/id}","deployments_url":"https://api.github.com/repos/graphcool/prisma/deployments","created_at":"2016-09-25T12:54:40Z","updated_at":"2018-04-23T12:12:21Z","pushed_at":"2018-04-23T12:30:30Z","git_url":"git://github.com/graphcool/prisma.git","ssh_url":"git@github.com:graphcool/prisma.git","clone_url":"https://github.com/graphcool/prisma.git","svn_url":"https://github.com/graphcool/prisma","homepage":"https://www.prisma.io/","size":15129,"stargazers_count":7121,"watchers_count":7121,"language":"Scala","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":393,"mirror_url":null,"archived":false,"open_issues_count":360,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":393,"open_issues":360,"watchers":7121,"default_branch":"master"}},"base":{"label":"graphcool:master","ref":"master","sha":"01aeae9de91b2ee383866b75c3e943f929cbb07f","user":{"login":"graphcool","id":17219288,"avatar_url":"https://avatars0.githubusercontent.com/u/17219288?v=4","gravatar_id":"","url":"https://api.github.com/users/graphcool","html_url":"https://github.com/graphcool","followers_url":"https://api.github.com/users/graphcool/followers","following_url":"https://api.github.com/users/graphcool/following{/other_user}","gists_url":"https://api.github.com/users/graphcool/gists{/gist_id}","starred_url":"https://api.github.com/users/graphcool/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/graphcool/subscriptions","organizations_url":"https://api.github.com/users/graphcool/orgs","repos_url":"https://api.github.com/users/graphcool/repos","events_url":"https://api.github.com/users/graphcool/events{/privacy}","received_events_url":"https://api.github.com/users/graphcool/received_events","type":"Organization","site_admin":false},"repo":{"id":69164196,"name":"prisma","full_name":"graphcool/prisma","owner":{"login":"graphcool","id":17219288,"avatar_url":"https://avatars0.githubusercontent.com/u/17219288?v=4","gravatar_id":"","url":"https://api.github.com/users/graphcool","html_url":"https://github.com/graphcool","followers_url":"https://api.github.com/users/graphcool/followers","following_url":"https://api.github.com/users/graphcool/following{/other_user}","gists_url":"https://api.github.com/users/graphcool/gists{/gist_id}","starred_url":"https://api.github.com/users/graphcool/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/graphcool/subscriptions","organizations_url":"https://api.github.com/users/graphcool/orgs","repos_url":"https://api.github.com/users/graphcool/repos","events_url":"https://api.github.com/users/graphcool/events{/privacy}","received_events_url":"https://api.github.com/users/graphcool/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/graphcool/prisma","description":"⚡️ Prisma turns your database into a realtime GraphQL API","fork":false,"url":"https://api.github.com/repos/graphcool/prisma","forks_url":"https://api.github.com/repos/graphcool/prisma/forks","keys_url":"https://api.github.com/repos/graphcool/prisma/keys{/key_id}","collaborators_url":"https://api.github.com/repos/graphcool/prisma/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/graphcool/prisma/teams","hooks_url":"https://api.github.com/repos/graphcool/prisma/hooks","issue_events_url":"https://api.github.com/repos/graphcool/prisma/issues/events{/number}","events_url":"https://api.github.com/repos/graphcool/prisma/events","assignees_url":"https://api.github.com/repos/graphcool/prisma/assignees{/user}","branches_url":"https://api.github.com/repos/graphcool/prisma/branches{/branch}","tags_url":"https://api.github.com/repos/graphcool/prisma/tags","blobs_url":"https://api.github.com/repos/graphcool/prisma/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/graphcool/prisma/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/graphcool/prisma/git/refs{/sha}","trees_url":"https://api.github.com/repos/graphcool/prisma/git/trees{/sha}","statuses_url":"https://api.github.com/repos/graphcool/prisma/statuses/{sha}","languages_url":"https://api.github.com/repos/graphcool/prisma/languages","stargazers_url":"https://api.github.com/repos/graphcool/prisma/stargazers","contributors_url":"https://api.github.com/repos/graphcool/prisma/contributors","subscribers_url":"https://api.github.com/repos/graphcool/prisma/subscribers","subscription_url":"https://api.github.com/repos/graphcool/prisma/subscription","commits_url":"https://api.github.com/repos/graphcool/prisma/commits{/sha}","git_commits_url":"https://api.github.com/repos/graphcool/prisma/git/commits{/sha}","comments_url":"https://api.github.com/repos/graphcool/prisma/comments{/number}","issue_comment_url":"https://api.github.com/repos/graphcool/prisma/issues/comments{/number}","contents_url":"https://api.github.com/repos/graphcool/prisma/contents/{+path}","compare_url":"https://api.github.com/repos/graphcool/prisma/compare/{base}...{head}","merges_url":"https://api.github.com/repos/graphcool/prisma/merges","archive_url":"https://api.github.com/repos/graphcool/prisma/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/graphcool/prisma/downloads","issues_url":"https://api.github.com/repos/graphcool/prisma/issues{/number}","pulls_url":"https://api.github.com/repos/graphcool/prisma/pulls{/number}","milestones_url":"https://api.github.com/repos/graphcool/prisma/milestones{/number}","notifications_url":"https://api.github.com/repos/graphcool/prisma/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/graphcool/prisma/labels{/name}","releases_url":"https://api.github.com/repos/graphcool/prisma/releases{/id}","deployments_url":"https://api.github.com/repos/graphcool/prisma/deployments","created_at":"2016-09-25T12:54:40Z","updated_at":"2018-04-23T12:12:21Z","pushed_at":"2018-04-23T12:30:30Z","git_url":"git://github.com/graphcool/prisma.git","ssh_url":"git@github.com:graphcool/prisma.git","clone_url":"https://github.com/graphcool/prisma.git","svn_url":"https://github.com/graphcool/prisma","homepage":"https://www.prisma.io/","size":15129,"stargazers_count":7121,"watchers_count":7121,"language":"Scala","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":393,"mirror_url":null,"archived":false,"open_issues_count":360,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":393,"open_issues":360,"watchers":7121,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/graphcool/prisma/pulls/2238"},"html":{"href":"https://github.com/graphcool/prisma/pull/2238"},"issue":{"href":"https://api.github.com/repos/graphcool/prisma/issues/2238"},"comments":{"href":"https://api.github.com/repos/graphcool/prisma/issues/2238/comments"},"review_comments":{"href":"https://api.github.com/repos/graphcool/prisma/pulls/2238/comments"},"review_comment":{"href":"https://api.github.com/repos/graphcool/prisma/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/graphcool/prisma/pulls/2238/commits"},"statuses":{"href":"https://api.github.com/repos/graphcool/prisma/statuses/9958b6de78240bc055d34ca5914db607260857e2"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"codacy-bot"}}