{"id":42381549,"url":"https://github.com/twistedstream/google-sheets-table","last_synced_at":"2026-01-27T21:55:22.804Z","repository":{"id":220019273,"uuid":"750377184","full_name":"twistedstream/google-sheets-table","owner":"twistedstream","description":"Treat a Google Sheet like a database table","archived":false,"fork":false,"pushed_at":"2024-12-03T18:03:03.000Z","size":456,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-12T16:56:46.861Z","etag":null,"topics":["database","google-sheets","google-sheets-api"],"latest_commit_sha":null,"homepage":"https://twistedstream.github.io/google-sheets-table/","language":"TypeScript","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/twistedstream.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2024-01-30T14:31:50.000Z","updated_at":"2024-12-03T18:03:06.000Z","dependencies_parsed_at":"2024-02-15T18:42:08.381Z","dependency_job_id":"ee307ba9-0968-4a54-b032-4a21db7e67b8","html_url":"https://github.com/twistedstream/google-sheets-table","commit_stats":{"total_commits":48,"total_committers":2,"mean_commits":24.0,"dds":"0.45833333333333337","last_synced_commit":"9db955346b6c8a9b436d626cfb1f8b70c9ad2f45"},"previous_names":["twistedstream/google-sheets-table"],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/twistedstream/google-sheets-table","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twistedstream%2Fgoogle-sheets-table","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twistedstream%2Fgoogle-sheets-table/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twistedstream%2Fgoogle-sheets-table/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twistedstream%2Fgoogle-sheets-table/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twistedstream","download_url":"https://codeload.github.com/twistedstream/google-sheets-table/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twistedstream%2Fgoogle-sheets-table/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28823803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T18:44:20.126Z","status":"ssl_error","status_checked_at":"2026-01-27T18:44:09.161Z","response_time":168,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["database","google-sheets","google-sheets-api"],"created_at":"2026-01-27T21:55:22.012Z","updated_at":"2026-01-27T21:55:22.798Z","avatar_url":"https://github.com/twistedstream.png","language":"TypeScript","readme":"# google-sheets-table\n\n![google-sheets-table banner](./media/banner.svg)\n\n[![Release](https://img.shields.io/npm/v/google-sheets-table)](https://www.npmjs.com/package/google-sheets-table)\n[![build](https://github.com/twistedstream/google-sheets-table/actions/workflows/build.yml/badge.svg)](https://github.com/twistedstream/google-sheets-table/actions)\n![Downloads](https://img.shields.io/npm/dw/google-sheets-table)\n[![License](https://img.shields.io/:license-mit-blue.svg?style=flat)](https://opensource.org/licenses/MIT)\n\nTreat a Google Sheet like a database table.\n\n## Motivation\n\nFor simple projects, you often don't have the time (or the patience) to build a full admin backend for your app. A [Google Sheets document](https://www.google.com/sheets/about/) makes an ideal backend for these situations because:\n\n- You don't have to build an admin UI\n- It's easy and intuitive to view and even edit the data (it's just a spreadsheet)\n- You can easily layer on all kinds of extra analytics capabilities like pivot tables, charts, and graphs.\n\nThis simple library allows you to read and write data to individual sheets within a Google Sheets document as if they were tables and rows in a database.\n\n## Features\n\n- Search for rows using familiar predicate syntax, similar to the JavaScript [`Array.find()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) API\n- Easily find rows identified by one or more keys\n- Count all of the data rows in the table\n- Insert, update, and delete individual rows\n- Concurrent access to a given spreadsheet is prevented (using a [mutex](https://github.com/DirtyHairy/async-mutex?tab=readme-ov-file#mutex))\n\n## Installation\n\n```shell\nnpm install google-sheets-table\n```\n\n## Loading and configuring\n\n```javascript\nimport { GoogleSheetsTable } from \"google-sheets-table\";\n\nconst {\n  GOOGLE_AUTH_CLIENT_EMAIL: client_email,\n  GOOGLE_AUTH_PRIVATE_KEY: private_key,\n  GOOGLE_SPREADSHEET_ID: spreadsheetId,\n} = process.env;\n\nconst table = new GoogleSheetsTable({\n  // using a Google service account\n  credentials: {\n    client_email,\n    private_key,\n  },\n  spreadsheetId,\n  sheetName: \"products\",\n  // enforce that 'id' and 'sku' columns are unique\n  columnConstraints: { uniques: [\"id\", \"sku\"] },\n});\n```\n\nThe `credentials` object is a Google [`JWTInput`](https://github.com/googleapis/google-auth-library-nodejs/blob/3b19e9cfa0e7ca4ffd97fa0ebd96f065286573dc/src/auth/credentials.ts#L69) interface which supports the use of Google service accounts. To create a service account and give it the necessary access to your document, do the following:\n\n1. If you don't already have one, [create a new project](https://cloud.google.com/resource-manager/docs/creating-managing-projects) in the Google Cloud Console\n1. In the project, enable the [Google Sheets API](https://console.cloud.google.com/marketplace/product/google/sheets.googleapis.com)\n1. Create a service account in [IAM Credentials](https://console.cloud.google.com/apis/credentials)\n1. Download the JSON key and extract the `client_email` and `private_key` properties\n1. Export them in your environment as shown above\n1. Share access to your document, giving the service account (identified by its email address) either `Viewer` access (if your app only needs read-only access) or `Editor` access (if it needs full read/write)\n\n   ![share access](./media/share-access.png)\n\nThe `sheetName` property identifies which sheet in the Google Sheets document will be used as the table.\n\nThe `columnConstraints` property specifies column constraints that will be enforced when new rows are inserted or existing rows are updated.\n\n## Usage\n\nSo imagine you have the following Google Sheets document that contains this `products` sheet:\n\n![Example sheet](./media/example-sheet.png)\n\nFinding a single row:\n\n```javascript\nconst { row } = await table.findRow((r) =\u003e r.id === 1001);\nconsole.log(row);\n// =\u003e { _rowNumber: 2, id: 1001, sku: 'APL1', name: 'Apple', quantity: 10, price: 1.75, department: \"produce\" }\n```\n\n\u003e The `_rowNumber` property is a metadata field identifying the sheet row number\n\nGet all rows:\n\n```javascript\nconst { rows: allRows } = await table.findRows();\nconsole.log(allRows);\n// =\u003e [\n//      { _rowNumber: 2, id: 1001, sku: 'APL1', name: 'Apple', quantity: 10, price: 1.75, department: \"produce\" },\n//      { _rowNumber: 3, id: 1002, sku: 'BAN1', name: 'Banana', quantity: 11, price: 1.50, department: \"produce\" },\n//      { _rowNumber: 4, id: 1003, sku: 'TP1', name: 'Toilet paper', quantity: 99, price: 5.50, department: \"home\" },\n//      { _rowNumber: 5, id: 1004, sku: 'EGG1', name: 'Banana', quantity: 25, price: 2.50, department: \"dairy\" },\n//    ]\n```\n\nFinding specific rows:\n\n```javascript\nconst { rows } = await table.findRows((r) =\u003e r.quantity \u003c 50);\nconsole.log(rows);\n// =\u003e [\n//      { _rowNumber: 2, id: 1001, sku: 'APL1', name: 'Apple', quantity: 10, price: 1.75, department: 'produce' },\n//      { _rowNumber: 3, id: 1002, sku: 'BAN1', name: 'Banana', quantity: 11, price: 1.5, department: 'produce' },\n//      { _rowNumber: 5, id: 1004, sku: 'EGG1', name: 'Eggs', quantity: 25, price: 2.5, department: 'dairy' }\n//    ]\n```\n\nFinding rows and sorting them:\n\n```javascript\nconst { rows: sortedRows } = await table.findRows(\n  (r) =\u003e r.quantity \u003c 50,\n  [{ asc: \"department\" }, { desc: \"name\" }],\n);\nconsole.log(sortedRows);\n// =\u003e [\n//      { _rowNumber: 5, id: 1004, sku: 'EGG1', name: 'Eggs', quantity: 25, price: 2.5, department: 'dairy' },\n//      { _rowNumber: 3, id: 1002, sku: 'BAN1', name: 'Banana', quantity: 11, price: 1.5, department: 'produce' },\n//      { _rowNumber: 2, id: 1001, sku: 'APL1', name: 'Apple', quantity: 10, price: 1.75, department: 'produce' }\n//    ]\n```\n\nFinding rows by one or more keys:\n\n```javascript\nconst { rowsByKey } = await table.findKeyRows((r) =\u003e r.sku, [\"APL1\", \"EGG1\"]);\nconsole.log(rowsByKey);\n// =\u003e {\n//      APL1: { _rowNumber: 2, id: 1001, sku: 'APL1', name: 'Apple', quantity: 10, price: 1.75, department: \"produce\" } },\n//      EGG1: { _rowNumber: 5, id: 1002, sku: 'BAN1', name: 'Banana', quantity: 11, price: 1.50, department: \"produce\" } }\n//    }\n```\n\nCounting rows:\n\n```typescript\nconst count = await table.countRows();\nconsole.log(count);\n// =\u003e 4\n```\n\nInserting a new row:\n\n```javascript\nconst { insertedRow } = await table.insertRow({\n  id: 1005,\n  sku: \"BUT1\",\n  name: \"Buttr\", // notice the typo\n  quantity: 15,\n  price: 3.5,\n  department: \"dairy\",\n});\nconsole.log(insertedRow);\n// =\u003e { _rowNumber: 6, id: 1005, sku: 'BUT1', name: 'Buttr', quantity: 15, price: 3.5, department: \"dairy\" }\n```\n\nUpdating an existing row:\n\n```javascript\nconst { updatedRow } = await table.updateRow((r) =\u003e r.sku === \"BUT1\", {\n  name: \"Butter\",\n});\nconsole.log(updatedRow);\n// =\u003e { _rowNumber: 6, id: 1005, sku: 'BUT1', name: 'Butter', quantity: 15, price: 3.5, department: \"dairy\" }\n```\n\nDeleting an existing row:\n\n```javascript\nawait table.deleteRow((r) =\u003e r.sku === \"BUT1\");\n// NOTE: throws if row not found\n```\n\nSee the [`example.js`](./example.js) for the full example.\n\n## API\n\nCheck it out 👉 [API](https://twistedstream.github.io/google-sheets-table)\n\n## Contribution ideas\n\n- [ ] Improve performance with larger tables by not having to download the entire table for each operation\n- [ ] Add support for batch operations\n- [ ] Support concurrency locking across processes\n\n## License\n\n[MIT](./LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwistedstream%2Fgoogle-sheets-table","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwistedstream%2Fgoogle-sheets-table","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwistedstream%2Fgoogle-sheets-table/lists"}