JavaScript/TypeScript client for SheetDB - Use Google Sheets as a relational database.
npm install sheetdb-jsimport { SheetDB } from "sheetdb-js";
// Connect to SheetDB REST API
const db = new SheetDB("http://localhost:8000/api");
// Query data
const monsters = await db
.table("monsters")
.filter({ danger_level__gte: 7 })
.orderBy("name")
.limit(10)
.get();
// Create a record
await db.table("monsters").create({
name: "Vampire",
danger_level: 8,
habitat: "Castle",
});
// Update a record
await db.table("monsters").update(1, {
danger_level: 9,
});
// Delete a record
await db.table("monsters").delete(1);import { useQuery, useMutation } from "sheetdb-js/react";
function MonsterList() {
const { data, loading, error } = useQuery("monsters", {
filter: { danger_level__gte: 7 },
});
const { mutate: createMonster } = useMutation("monsters", "create");
if (loading) return <div>Loading...</div>;
if (error) return <div>Error: {error.message}</div>;
return (
<div>
{data.map((monster) => (
<div key={monster.id}>{monster.name}</div>
))}
<button onClick={() => createMonster({ name: "Vampire" })}>
Add Monster
</button>
</div>
);
}const db = new SheetDB(baseUrl, options);baseUrl: Base URL of the SheetDB REST APIoptions.apiKey: Optional API key for authentication
table(name): Get a table query buildersync(): Trigger cache refreshlistTables(): Get list of all tables
filter(conditions): Add filter conditionsorderBy(field): Order results (prefix with-for descending)limit(n): Limit number of resultsoffset(n): Skip n resultsfields(fieldList): Select specific fieldsget(): Execute query and return resultscreate(data): Create a new recordupdate(id, data): Update a recorddelete(id): Delete a record
const { data, loading, error, refetch } = useQuery(table, options);const { mutate, loading, error } = useMutation(table, operation);MIT
Current Status:
- Located in
sheetdb-js/directory of the monorepo - Not included when you
pip install sheetdb - Separate npm package with its own dependencies
Installation (Current):
# Clone the monorepo
git clone https://github.com/yourusername/sheetdb.git
cd sheetdb/sheetdb-js
# Install and build
npm install
npm run build
# Link for local development
npm linkFuture Plans:
This component will be split into a separate repository:
- Repository:
sheetdb-js(standalone) - Package:
npm install sheetdb-js - Independent versioning
See REPOSITORY_STRUCTURE.md in the main repo for details.
# Install dependencies
npm install
# Build the package
npm run build
# Watch mode for development
npm run dev
# Run tests (if available)
npm testComplete examples are available in the main repository:
examples/js-client-vanilla.html- Vanilla JavaScript exampleexamples/js-client-react.jsx- React exampleexamples/react-monster-tracker/- Full React application
This is part of the SheetDB project. See the main repository for contribution guidelines.
Part of the SheetDB project - See main documentation