{"id":19593345,"url":"https://github.com/livebook-dev/req_bigquery","last_synced_at":"2025-04-27T15:32:56.267Z","repository":{"id":62430840,"uuid":"489121843","full_name":"livebook-dev/req_bigquery","owner":"livebook-dev","description":"Conveniences for querying Google BigQuery with Req","archived":true,"fork":false,"pushed_at":"2025-01-16T17:20:47.000Z","size":54,"stargazers_count":14,"open_issues_count":0,"forks_count":9,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-26T23:04:21.807Z","etag":null,"topics":["bigquery","req"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/livebook-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-05T20:48:08.000Z","updated_at":"2025-01-17T09:22:34.000Z","dependencies_parsed_at":"2024-04-10T20:26:09.346Z","dependency_job_id":"e036eedc-5a5d-4766-8759-c2940c8aebf9","html_url":"https://github.com/livebook-dev/req_bigquery","commit_stats":{"total_commits":21,"total_committers":5,"mean_commits":4.2,"dds":"0.38095238095238093","last_synced_commit":"a7249c6512d5d7658d2b4e8d16a991b01ca3b688"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livebook-dev%2Freq_bigquery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livebook-dev%2Freq_bigquery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livebook-dev%2Freq_bigquery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livebook-dev%2Freq_bigquery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/livebook-dev","download_url":"https://codeload.github.com/livebook-dev/req_bigquery/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251162329,"owners_count":21545753,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bigquery","req"],"created_at":"2024-11-11T08:39:12.243Z","updated_at":"2025-04-27T15:32:51.257Z","avatar_url":"https://github.com/livebook-dev.png","language":"Elixir","readme":"# ReqBigQuery\n\n[![Hex pm](http://img.shields.io/hexpm/v/req_bigquery.svg?style=flat)](https://hex.pm/packages/req_bigquery)\n\n[Req](https://github.com/wojtekmach/req) plugin for [Google BigQuery](https://cloud.google.com/bigquery/docs/reference/rest).\n\nReqBigQuery makes it easy to make BigQuery queries. It uses [Goth](https://github.com/peburrows/goth)\nfor authentication. Query results are decoded into the `ReqBigQuery.Result` struct.\nThe struct implements the `Table.Reader` protocol and thus can be efficiently traversed by rows or columns.\n\n## Usage\n\n```elixir\nMix.install([\n  {:goth, \"~\u003e 1.3.0\"},\n  {:req, \"~\u003e 0.3.5\"},\n  {:req_bigquery, \"~\u003e 0.1.1\"}\n])\n\n# We use Goth to authenticate to Google Cloud API.\n# See: https://hexdocs.pm/goth/1.3.0-rc.4/Goth.Token.html#fetch/1-source for more information.\ncredentials = File.read!(\"credentials.json\") |\u003e Jason.decode!()\nsource = {:service_account, credentials, []}\n{:ok, _} = Goth.start_link(name: MyGoth, source: source, http_client: \u0026Req.request/1)\n\nproject_id = System.fetch_env!(\"PROJECT_ID\")\n\n# With plain string query\nquery = \"\"\"\nSELECT title, SUM(views) AS views\n  FROM `bigquery-public-data.wikipedia.table_bands`\n WHERE EXTRACT(YEAR FROM datehour) \u003c= 2021\n GROUP BY title\n ORDER BY views DESC\n LIMIT 10\n\"\"\"\n\nreq = Req.new() |\u003e ReqBigQuery.attach(goth: MyGoth, project_id: project_id)\nres = Req.post!(req, bigquery: query).body\n#=\u003e\n# %ReqBigQuery.Result{\n#   columns: [\"title\", \"views\"],\n#   job_id: \"job_JDDZKquJWkY7x0LlDcmZ4nMQqshb\",\n#   num_rows: 10,\n#   rows: %Stream{}\n# }\n\nEnum.to_list(res.rows)\n#=\u003e\n# [\n#   [\"The_Beatles\", 13758950],\n#   [\"Queen_(band)\", 12019563],\n#   [\"Pink_Floyd\", 9522503],\n#   [\"AC/DC\", 8972364],\n#   [\"Led_Zeppelin\", 8294994],\n#   [\"Linkin_Park\", 8242802],\n#   [\"The_Rolling_Stones\", 7825952],\n#   [\"Red_Hot_Chili_Peppers\", 7302904],\n#   [\"Fleetwood_Mac\", 7199563],\n#   [\"Twenty_One_Pilots\", 6970692]\n# ]\n\n# With parameterized query\nquery = \"\"\"\nSELECT EXTRACT(YEAR FROM datehour) AS year, SUM(views) AS views\n  FROM `bigquery-public-data.wikipedia.table_bands`\n WHERE EXTRACT(YEAR FROM datehour) \u003c= 2021\n   AND title = ?\n GROUP BY year\n ORDER BY views DESC\n\"\"\"\n\nreq = Req.new() |\u003e ReqBigQuery.attach(goth: MyGoth, project_id: project_id)\nres = Req.post!(req, bigquery: {query, [\"Linkin_Park\"]}).body\n#=\u003e\n# %ReqBigQuery.Result{\n#   columns: [\"year\", \"views\"],\n#   job_id: \"job_GXiJvALNsTAoAOJ39Eg3Mw94XMUQ\",\n#   num_rows: 7,\n#   rows: %Stream{}\n# }\n\nEnum.to_list(res.rows)\n#=\u003e [[2017, 2895889], [2016, 1173359], [2018, 1133770], [2020, 906538], [2015, 860899], [2019, 790747], [2021, 481600]]\n```\n\n## License\n\nCopyright (C) 2022 Dashbit\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flivebook-dev%2Freq_bigquery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flivebook-dev%2Freq_bigquery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flivebook-dev%2Freq_bigquery/lists"}