Sheet2DB JS/TS SDK

The Sheet2DBClient SDK allows developers to interact with their Google Sheets via the Sheet2DB platform using a clean and typed interface. It provides full CRUD support along with helper utilities for managing sheets.


📦 Installation

npm install @sheet2db/sdk

🚀 Usage

import { Sheet2DBClient } from '@sheet2db/sdk';

const client = new Sheet2DBClient('your-api-id');

// Optional authentication
client.useBearerTokenAuthentication('your-token');

// Example: Read rows
const data = await client.Read({ limit: 10 }, 'Sheet1');

🔐 Authentication Methods

client.useBasicAuthentication(username: string, password: string);
client.useJWTAuthentication(token: string);
client.useBearerTokenAuthentication(token: string);

🧠 Type Definitions

ReadOptions

{
  limit?: number;
  offset: number;
  sortColumn?: string;
  sortDirection: 'asc' | 'desc';
  sortColumnFormat?: 'date';
  filter?: string;
  format: 'rows' | 'columns' | 'matrix';
  columns?: string[];
  castNumbers?: string[];
}

InsertOptions

{
  data: any[];
}

UpdateOptions

// Update by row
{
  type: 'row';
  row: number;
  data: Record<string, any>;
}

// Update by filter
{
  type: 'filter';
  filter: string;
  data: Record<string, any>;
}

DeleteOptions

// Delete by row
{
  type: 'row';
  row: number;
}

// Delete by filter
{
  type: 'filter';
  filter: string;
}

AddSheetOptions

{
  name: string;
  firstRow?: string[];
  copyColumnsFrom?: string;
}

📚 Methods

Read(options: ReadOptions, sheet?: string)

Reads data from the sheet based on options provided.


Insert(options: InsertOptions, sheet?: string)

Inserts rows of data into the specified sheet.


Update(options: UpdateOptions, sheet?: string)

Updates rows based on a filter or row number.


Delete(options: DeleteOptions, sheet?: string)

Deletes rows based on a filter or row number.


AddSheet(options: AddSheetOptions)

Adds a new sheet with optional headers or by copying from another sheet.


DeleteSheet(sheet: string)

Deletes a sheet by name.


🧪 Example

await client.Insert({
  data: [
    { name: 'Alice', age: 28 },
    { name: 'Bob', age: 31 }
  ]
}, 'People');

await client.Update({
  type: 'row',
  row: 2,
  data: { age: 32 }
}, 'People');

await client.Delete({
  type: 'filter',
  filter: 'name:eq:Bob'
}, 'People');

🧾 Notes

  • 'sheet' argument is optional; default sheet will be used if not specified.
  • Supports pagination, sorting, and filtering.