{"id":18034675,"url":"https://github.com/yuanqing/cuba","last_synced_at":"2025-10-04T02:30:24.194Z","repository":{"id":55814484,"uuid":"128429775","full_name":"yuanqing/cuba","owner":"yuanqing","description":":cuba: Google Sheets + SQL = JSON","archived":false,"fork":false,"pushed_at":"2021-01-30T07:39:54.000Z","size":447,"stargazers_count":56,"open_issues_count":5,"forks_count":9,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-22T20:52:11.656Z","etag":null,"topics":["google-api","google-sheets","spreadsheet"],"latest_commit_sha":null,"homepage":"https://codepen.io/lyuanqing/pen/bMdXgY","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yuanqing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-06T18:00:26.000Z","updated_at":"2025-06-07T13:44:09.000Z","dependencies_parsed_at":"2022-08-15T07:20:52.994Z","dependency_job_id":null,"html_url":"https://github.com/yuanqing/cuba","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/yuanqing/cuba","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanqing%2Fcuba","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanqing%2Fcuba/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanqing%2Fcuba/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanqing%2Fcuba/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yuanqing","download_url":"https://codeload.github.com/yuanqing/cuba/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanqing%2Fcuba/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278254771,"owners_count":25956675,"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","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["google-api","google-sheets","spreadsheet"],"created_at":"2024-10-30T11:13:20.932Z","updated_at":"2025-10-04T02:30:23.875Z","avatar_url":"https://github.com/yuanqing.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cuba [![npm Version](https://badgen.net/npm/v/cuba)](https://www.npmjs.org/package/cuba) [![Build Status](https://badgen.net/travis/yuanqing/cuba?label=build)](https://travis-ci.org/yuanqing/cuba) [![Bundle Size](https://badgen.net/bundlephobia/minzip/cuba)](https://bundlephobia.com/result?p=cuba)\n\n\u003e Google Sheets + SQL = JSON\n\n- Run [SQL-esque queries](https://developers.google.com/chart/interactive/docs/querylanguage#overview) against your Google Sheets spreadsheet, get results as JSON\n- Perfect for prototyping, or leveraging Google Sheets as a collaborative datastore for your app\n- Works in both Node and the browser\n\n## Usage\n\n\u003e [**Editable demo (CodePen)**](https://codepen.io/lyuanqing/pen/bMdXgY)\n\nTo start, enable link-sharing on your spreadsheet:\n\n1. Click the **`Share`** button on the top-right corner of the Google Sheets spreadsheet page.\n2. Click **`Get shareable link`** on the top-right corner of the modal.\n3. To the left of the **`Copy link`** button, ensure that access rights is set to **`Anyone with the link can view`**.\n\nThen:\n\n```js\nconst cuba = require('cuba')\n\nasync function main () {\n  const query = cuba('1InLekepCq4XgInfMueA2E2bqDqICVHHTXd_QZab0AOU')\n  const array = await query('select *')\n  console.log(array)\n  //=\u003e [\n  //=\u003e   { id: 1, name: 'foo' },\n  //=\u003e   { id: 2, name: 'bar' },\n  //=\u003e   { id: 3, name: 'baz' }\n  //=\u003e ]\n}\nmain()\n```\n\nHere, `1InLekepCq4XgInfMueA2E2bqDqICVHHTXd_QZab0AOU` is the ID of [our example spreadsheet](https://docs.google.com/spreadsheets/d/1InLekepCq4XgInfMueA2E2bqDqICVHHTXd_QZab0AOU/edit#gid=0); it is the value between `/d/` and `/edit` in the spreadsheet URL.\n\n### Querying private spreadsheets\n\nIn Node, we can also run queries on private spreadsheets that do not have link-sharing enabled:\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003e1. Create a Service Account on the Google API Console.\u003c/strong\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n1. Navigate to [the Google API Console](https://console.developers.google.com/apis/dashboard)\n2. Select a project from the drop-down box in the top bar.\n3. Click **`Credentials`** (the Key icon) on the left navigation bar.\n4. Click the **`Create credentials`** drop-down box, and select **`Service account key`**.\n5. Click the **`Select…`** drop-down box, and select **`New service account`**.\n6. Enter a **`Service account name`**. For **`Role`**, select **`Project › Viewer`**. For **`Key type`**, select **`JSON`**.\n7. Click the **`Create`** button. This will generate a JSON file with the Service Account credentials. Note the `client_email` and `private_key` values in this JSON file.\n\n\u003c/p\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003e2. Give view access to the Service Account.\u003c/strong\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n1. Navigate to your spreadsheet.\n2. Click the **`Share`** button on the top-right corner of the page.\n3. In the **`Enter names or email addresses…`** text box, enter the `client_email` of the Service Account, then click the **`Send`** button.\n\n\u003c/p\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003e3. Pass in the Service Account credentials when querying the spreadsheet with Cuba.\u003c/strong\u003e\u003c/summary\u003e\n\u003cp\u003e\n\n- With [the API](#api), pass in a `serviceAccountCredentials` object, specifying the `clientEmail` and `privateKey`.\n- With [the CLI](#cli), use the `--credentials` (or `-c`) flag to specify the path to the Service Account credentials JSON file.\n\n\u003c/p\u003e\n\u003c/details\u003e\n\n## Installation\n\n```sh\n$ yarn add cuba\n```\n\n## API\n\nFeature | Supported in Node? | Supported in the browser?\n:-|:-|:-\n[Array interface](#-array-interface) | Yes | Yes\n[Stream interface](#-stream-interface) | Yes | No\n[Querying private spreadsheets](#querying-private-spreadsheets) | Yes | No\n\n### Array interface\n\n```js\nconst cuba = require('cuba')\n```\n\n#### const querySpreadsheet = cuba(spreadsheetId [, serviceAccountCredentials])\n\n`cuba` returns a function for running queries on the spreadsheet with the given `spreadsheetId`.\n\n- `spreadsheetId` is a string representing the Google Sheets spreadsheet to be queried. This is the value between `/d/` and `/edit` in the spreadsheet URL.\n\n- *(Node only)* `serviceAccountCredentials` is an optional object literal. This is to run queries on private spreadsheets that do not have link-sharing enabled.\n\n    Key | Description | Default\n    :-|:-|:-\n    `clientEmail` | Email address of the Service Account that has view access to the spreadsheet being queried. | `undefined`\n    `privateKey` | Private key of the Service Account. | `undefined`\n\n#### const array = await querySpreadsheet([query, options])\n\n`querySpreadsheet` returns a Promise for an Array containing the results of running the `query` on the spreadsheet.\n\n- `query` is a [Google Visualization API Query Language](https://developers.google.com/chart/interactive/docs/querylanguage#overview) query. Defaults to `'select *'`.\n- `options` is an optional object literal.\n\n    Key | Description | Default\n    :-|:-|:-\n    `sheetId` | ID of the sheet to run the query on. This is the value after `#gid=` in the spreadsheet URL. Ignored if `sheetName` is specified. | `0`\n    `sheetName` | Name of the sheet to run the query on. | `undefined`\n    `transform` | A function for transforming each item in the result. | The identity function\n\n### Stream interface\n\n```js\nconst cubaStream = require('cuba').stream\n```\n\n#### const querySpreadsheet = cubaStream(spreadsheetId [, serviceAccountCredentials])\n\n`cubaStream` returns a function for running queries on the spreadsheet with the given `spreadsheetId`. The function signature is identical to [the corresponding function in the Array interface](#const-queryspreadsheet--cubaspreadsheetid).\n\n#### const stream = await querySpreadsheet([query, options])\n\n`querySpreadsheet` returns a Promise for a [Readable Stream](https://nodejs.org/api/stream.html#stream_class_stream_readable) containing the results of running the `query` on the spreadsheet. The function signature is identical to [the corresponding function in the Array interface](#const-array--await-queryspreadsheetquery-options).\n\n## CLI\n\n```\ncuba [query]\n\nRun the given query on a Google Sheets spreadsheet\n\nPositionals:\n  query  The Google Visualization API Query Language query to run on the Google\n         Sheets spreadsheet                       [string] [default: \"select *\"]\n\nOptions:\n  --help             Show help                                         [boolean]\n  --version          Show version number                               [boolean]\n  --credentials, -c  Path to the Service Account credentials JSON file; to run\n                     queries on private spreadsheets that do not have\n                     link-sharing enabled                               [string]\n  --id, -i           The Google Sheets spreadsheet ID; the value between `/d/`\n                     and `/edit` in the spreadsheet URL      [string] [required]\n  --sheetId, -s      ID of the sheet to run the query on; the value after\n                     `#gid=` in the spreadsheet URL      [string] [default: \"0\"]\n  --sheetName, -n    Name of the sheet to run the query on              [string]\n```\n\n## Prior art\n\n- [Tabletop](https://github.com/jsoma/tabletop)\n- [Sheetrock](https://github.com/chriszarate/sheetrock)\n- [google-spreadsheet](https://github.com/theoephraim/node-google-spreadsheet)\n\n## License\n\n[MIT](LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuanqing%2Fcuba","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyuanqing%2Fcuba","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuanqing%2Fcuba/lists"}