Registry / database / sqlite-cache-for-google-sheets

sqlite-cache-for-google-sheets

JSON →
library9.0.0jsnpmunverified

Opinionated SQLite cache layer for Google Sheets data, designed for local development workflow where schema changes frequently. Version 9.0.0 is stable, actively maintained on GitHub. Ships TypeScript types. Provides a one-time load from Google Sheets into a local SQLite database, then allows querying via better-sqlite3. Unlike direct API queries, it avoids runtime dependency on Google Sheets and enables fast iteration. Requires API key, doc ID, and sheet ID. Uses a configurable map function to transform rows. Returns a better-sqlite3 database object for querying.

npm install sqlite-cache-for-google-sheets
INSTALL
IMPORT
SIG · SQLITE-CACHE-FOR-G
S
sqlite-cache-for-google-sheets
databasejavascriptv9.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createDatabase
import { createDatabase } from 'sqlite-cache-for-google-sheets'
import createDatabase from 'sqlite-cache-for-google-sheets'
Named export, not default.
DatabaseConfig
import type { DatabaseConfig } from 'sqlite-cache-for-google-sheets'
TypeScript type for config object.
SheetRow
import type { SheetRow } from 'sqlite-cache-for-google-sheets'
import { SheetRow } from 'sqlite-cache-for-google-sheets'
Type-only import; use 'import type'.
all exports
const { createDatabase } = require('sqlite-cache-for-google-sheets')
const sqliteCache = require('sqlite-cache-for-google-sheets')
CJS require destructure named export, or use default? Actually, there is no default export, so only destructure works.

Shows loading data from Google Sheets into a local SQLite database and querying it.

import { createDatabase } from 'sqlite-cache-for-google-sheets'; const mapFunction = (row) => ({ name: row.get('Name'), tags: row.get('Tags'), }); const config = { apiKey: process.env.SHEETS_API_KEY || '', docId: process.env.DOC_ID || '', sheetId: process.env.SHEET_ID || '', mapFunction, primaryKey: 'date', databaseFilename: './cache.db', databaseTableName: 'items', }; (async () => { const db = await createDatabase(config); const rows = db.prepare('SELECT * FROM items').all(); console.log(rows); })();
Debug
Known issues
breakingcreateDatabase() now returns a better-sqlite3 database object instead of a promise that resolves to void.
fix
Capture the return value and use it directly for queries.
affects: >=9.0.0
breakingConfig option 'databaseFilename' must be a writable path; defaults to './cache.db'.
fix
Ensure the directory exists and is writable.
affects: >=9.0.0
gotchaThe mapFunction receives a SheetRow object that has a get() method, not a plain object.
fix
Use row.get('columnName') instead of row.columnName.
affects: >=9.0.0
gotchaDatabase table is created with all columns as TEXT; no type coercion.
fix
Cast values in SQL queries (e.g., CAST(value AS INTEGER)).
affects: >=9.0.0
Errors
Common errors & fixes
TypeError: createDatabase is not a function
Default import used instead of named import.
fix
import { createDatabase } from 'sqlite-cache-for-google-sheets'
Error: Cannot find module 'better-sqlite3'
Missing peer dependency.
fix
npm install better-sqlite3
Error: SHEETS_API_KEY is required
Missing environment variable or config property.
fix
Set SHEETS_API_KEY in environment or config.apiKey.
Upgrade
Version history
9.0.0latest on npm
Audit
Dependencies
better-sqlite3requiredRequired for SQLite database creation and querying.
googleapisrequiredUsed to fetch data from Google Sheets.
Agent activity
21 hits · last 30 days
node
14
Meta
2
OpenAI (training)
2
Amazon
1
Resources
sqlite-cache-for-google-sheets — npm install sqlite-cache-for-google-sheets · libregistry