{"action":"created","issue":{"url":"https://api.github.com/repos/playframework/anorm/issues/147","repository_url":"https://api.github.com/repos/playframework/anorm","labels_url":"https://api.github.com/repos/playframework/anorm/issues/147/labels{/name}","comments_url":"https://api.github.com/repos/playframework/anorm/issues/147/comments","events_url":"https://api.github.com/repos/playframework/anorm/issues/147/events","html_url":"https://github.com/playframework/anorm/pull/147","id":210015326,"number":147,"title":"PostgreSQL module","user":{"login":"cchantep","id":166062,"avatar_url":"https://avatars2.githubusercontent.com/u/166062?v=3","gravatar_id":"","url":"https://api.github.com/users/cchantep","html_url":"https://github.com/cchantep","followers_url":"https://api.github.com/users/cchantep/followers","following_url":"https://api.github.com/users/cchantep/following{/other_user}","gists_url":"https://api.github.com/users/cchantep/gists{/gist_id}","starred_url":"https://api.github.com/users/cchantep/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cchantep/subscriptions","organizations_url":"https://api.github.com/users/cchantep/orgs","repos_url":"https://api.github.com/users/cchantep/repos","events_url":"https://api.github.com/users/cchantep/events{/privacy}","received_events_url":"https://api.github.com/users/cchantep/received_events","type":"User","site_admin":false},"labels":[{"id":154391281,"url":"https://api.github.com/repos/playframework/anorm/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-02-24T10:42:50Z","updated_at":"2017-05-08T14:22:50Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/playframework/anorm/pulls/147","html_url":"https://github.com/playframework/anorm/pull/147","diff_url":"https://github.com/playframework/anorm/pull/147.diff","patch_url":"https://github.com/playframework/anorm/pull/147.patch"},"body":"Optional/extra module dedicated to PostgreSQL support:\r\n\r\n- JSONB support, using Play JSON\r\n- UUID support\r\n\r\n## Integration tests (using Docker)\r\n\r\nSetup a test DB named 'anorm147' from CLI:\r\n\r\n    docker run --rm --name pganorm147 -p ':5432' -e 'POSTGRES_USER=anorm147' -e 'POSTGRES_PASSWORD=anorm147' -e 'POSTGRES_DB=anorm147' postgres:9\r\n\r\nIn a separate shell, note the port to access the containerized DB:\r\n\r\n    docker port pganorm147 | cut -d ':' -f 2\r\n\r\nThen create a test table (with the 'anorm147' password):\r\n\r\n```\r\nexport MY_PG_PORT=\"32772\"\r\ncat > /dev/stdout << EOF | /path/to/bin/psql -h localhost -p \"$MY_PG_PORT\" -U anorm147 anorm147\r\nCREATE TABLE test(id VARCHAR PRIMARY KEY, json JSONB);\r\nCREATE TABLE test_seq(id UUID PRIMARY KEY);\r\nEOF\r\n```\r\n\r\nFrom the Anorm repository with the branch checkout'ed, execute `sbt`:\r\n\r\n```\r\nsbt> project anorm-postgres\r\nsbt> console\r\n```\r\n\r\nEdit the following test code (the port) and paste it in the started Scala console.\r\n\r\n```scala\r\nimport java.util.UUID\r\nimport java.sql._\r\nimport anorm._, postgresql._\r\nimport play.api.libs.json._\r\n\r\nval port = 32772\r\nval url = s\"jdbc:postgresql://localhost:$port/anorm147\"\r\nimplicit val con = DriverManager.getConnection(url, \"anorm147\", \"anorm147\")\r\n\r\nsealed trait MyEnum\r\ncase object Bar extends MyEnum\r\ncase object Lorem extends MyEnum\r\n\r\n// 1. Insert JSON\r\nimplicit val w: Writes[MyEnum] = Writes[MyEnum] {\r\n  case Bar => Json.obj(\"bar\" -> 1)\r\n  case Lorem => Json.obj(\"lorem\" -> 2)\r\n}\r\n\r\n// 1.a JsValue\r\nSQL\"\"\"INSERT INTO test(id, json) VALUES (${\"foo\"}, ${Json.obj(\"bar\" -> 1)})\"\"\".executeUpdate()\r\n\r\n// 1.b T: Writes\r\nSQL\"INSERT INTO test(id, json) VALUES(${\"bar\"}, ${asJson[MyEnum](Lorem)})\".executeUpdate()\r\n\r\n// 2. Insert UUID\r\nSQL\"INSERT INTO test_seq VALUES(${UUID.randomUUID()})\".executeUpdate()\r\n\r\n// 3. Select JSON\r\nimplicit val r: Reads[MyEnum] = Reads[MyEnum] { js =>\r\n  (js \\ \"bar\").validate[Int].map {\r\n    case 1 => Bar\r\n    case _ => Lorem\r\n  }\r\n}\r\n\r\n// 3.a JsValue\r\nSQL\"\"\"SELECT json FROM test WHERE id = ${\"foo\"}\"\"\".\r\n  as(SqlParser.scalar[JsValue].single)\r\n\r\n// 3.b JsObject\r\nSQL\"\"\"SELECT json FROM test WHERE id = ${\"foo\"}\"\"\".\r\n  as(SqlParser.scalar[JsObject].single)\r\n\r\n// 3.c T: Reads\r\nSQL\"\"\"SELECT json FROM test WHERE id = ${\"foo\"}\"\"\".\r\n  as(SqlParser.scalar(fromJson[MyEnum]).single)\r\n\r\n// 4. Select UUID\r\nSQL\"SELECT * FROM test_seq\".as(SqlParser.scalar[UUID].*)\r\n```"},"comment":{"url":"https://api.github.com/repos/playframework/anorm/issues/comments/299880943","html_url":"https://github.com/playframework/anorm/pull/147#issuecomment-299880943","issue_url":"https://api.github.com/repos/playframework/anorm/issues/147","id":299880943,"user":{"login":"cchantep","id":166062,"avatar_url":"https://avatars2.githubusercontent.com/u/166062?v=3","gravatar_id":"","url":"https://api.github.com/users/cchantep","html_url":"https://github.com/cchantep","followers_url":"https://api.github.com/users/cchantep/followers","following_url":"https://api.github.com/users/cchantep/following{/other_user}","gists_url":"https://api.github.com/users/cchantep/gists{/gist_id}","starred_url":"https://api.github.com/users/cchantep/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cchantep/subscriptions","organizations_url":"https://api.github.com/users/cchantep/orgs","repos_url":"https://api.github.com/users/cchantep/repos","events_url":"https://api.github.com/users/cchantep/events{/privacy}","received_events_url":"https://api.github.com/users/cchantep/received_events","type":"User","site_admin":false},"created_at":"2017-05-08T14:22:50Z","updated_at":"2017-05-08T14:22:50Z","body":"Up"}}
{"actor":{"display_login":"cchantep"}}