{"library":"sheets-database","title":"Google Sheets Database","description":"sheets-database is a JavaScript/TypeScript library designed to enable developers to use Google Sheets as a lightweight, no-cost database or content management system. Currently at version 1.0.4, it provides a simple and intuitive API for common database operations like creating, reading, updating, and deleting (CRUD) tables and their entries. The library offers multiple authentication methods, including Service Account, OAuth, Access Token, and API Key, and includes features to optimize memory and network usage for suitable use cases. While it handles internal synchronization with Google Sheets, it is explicitly positioned for small applications and datasets, warning against its use for applications with many entries or complex joins where traditional databases are more appropriate. Release cadence appears to be minor patches within the 1.0.x range, indicating stability and ongoing maintenance.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install sheets-database"],"cli":null},"imports":["import { SheetDatabase } from 'sheets-database';","await db.useServiceAccount({...});"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { SheetDatabase } from 'sheets-database';\n\n// Initialize the Database with doc ID (long id in the sheets URL)\nconst db = new SheetDatabase(process.env.GOOGLE_SHEET_ID ?? '');\n\nasync function run() {\n  // Initialize Auth using a Service Account for robust server-side access.\n  // Ensure GOOGLE_SERVICE_ACCOUNT_EMAIL and GOOGLE_PRIVATE_KEY are set in your environment variables.\n  // The private key may need newline characters replaced if loaded from a single-line environment variable.\n  await db.useServiceAccount({\n    client_email: process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL ?? '',\n    private_key: (process.env.GOOGLE_PRIVATE_KEY ?? '').replace(/\\\\n/g, '\\n'),\n  });\n\n  await db.sync(); // Connects with the sheet and fetches initial data\n\n  // ADDING TABLES\n  const table1 = await db.addTable('products', ['id', 'name', 'price']);\n  console.log('Table \"products\" added.');\n\n  // Insert some data\n  await table1.insertOne({ 'id': 1, 'name': 'Laptop', 'price': 1200 });\n  await table1.insert([\n    { 'id': 2, 'name': 'Mouse', 'price': 25 },\n    ['3', 'Keyboard', 75]\n  ]);\n  console.log('Data inserted into products table:', table1.getData());\n\n  // RENAMING TABLES\n  await table1.rename('inventory');\n  console.log('Table renamed to \"inventory\".');\n\n  // Update entries\n  await db.inventory.updateRowsWhere(\n    (currentData) => currentData.name === 'Laptop',\n    (data) => ({ ...data, price: 1250 })\n  );\n  console.log('Updated inventory data:', db.inventory.getData());\n\n  // DELETING TABLES (Commented out to prevent accidental deletion in quickstart)\n  // await db.inventory.drop();\n  // console.log('Table \"inventory\" dropped.');\n}\n\nrun().catch(console.error);","lang":"typescript","description":"This quickstart initializes a SheetDatabase instance, authenticates using a Google Service Account (best practice for backend), synchronizes with the sheet, adds a new table, inserts and updates data, and demonstrates renaming a table. It includes robust environment variable handling for credentials.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}