npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

googlesheets-raghbir

v1.0.2

Published

`@raghbir/googlesheetsorm` is an ORM (Object-Relational Mapping) library for Google Sheets. It allows you to interact with Google Sheets as if they were a database, providing methods to create, read, update, and delete rows in a sheet.

Downloads

8

Readme

@raghbir/googlesheetsorm

@raghbir/googlesheetsorm is an ORM (Object-Relational Mapping) library for Google Sheets. It allows you to interact with Google Sheets as if they were a database, providing methods to create, read, update, and delete rows in a sheet.

Installation

To install the package, run:

npm install @raghbir/googlesheetsorm

Usage

1. Setting up Google API Credentials

Before using the library, you need to set up Google API credentials. You can create a project in the Google Cloud Console and enable the Google Sheets API. Download the credentials file and keep it ready.

2. Initializing the Library

First, import the GoogleDB class and initialize it with the required options:

const { GoogleDB } = require('@raghbir/googlesheetsorm');

const db = new GoogleDB({
  auth: {
    // Replace with your actual credentials
    CLIENT_ID: 'your-client-id',
    CLIENT_SECRET: 'your-client-secret',
    REDIRECT_URI: 'your-redirect-uri',
    refreshToken: 'your-refresh-token'
  },
  spreadSheetLink: 'https://docs.google.com/spreadsheets/d/your-spreadsheet-id/edit#gid=0',
  spreadSheetName: 'Sheet1',
  schema: {
    name: { type: 'string', required: true },
    age: { type: 'number' },
    isActive: { type: 'boolean' }
  }
});

3. Creating a Record

To create a new record in the Google Sheet:

async function createRecord() {
  const record = await db.create({ name: 'John Doe', age: 30, isActive: true });
  console.log('Record created:', record);
}

createRecord();

4. Finding Records

To find records matching a query:

async function findRecords() {
  const records = await db.find({ isActive: true });
  console.log('Records found:', records);
}

findRecords();

5. Finding a Single Record

To find a single record matching a query:

async function findOneRecord() {
  const record = await db.findOne({ name: 'John Doe' });
  console.log('Record found:', record);
}

findOneRecord();

6. Updating a Record

To update a record matching a query:

async function updateRecord() {
  const updatedRecord = await db.update({ name: 'John Doe' }, { age: 31 });
  console.log('Record updated:', updatedRecord);
}

updateRecord();

7. Deleting a Record

To delete a record matching a query:

async function deleteRecord() {
  const deleteResponse = await db.delete({ name: 'John Doe' });
  console.log('Record deleted:', deleteResponse);
}

deleteRecord();

API Reference

GoogleDB

Constructor

new GoogleDB(options: GoogleDBOptions)
  • options: An object with the following properties:
    • auth: Authentication credentials for Google API.
    • spreadSheetLink: The link to your Google Spreadsheet.
    • spreadSheetName: The name of the sheet to use.
    • schema: The schema definition for the sheet.

Methods

  • create(data: { [key: string]: any }): Promise<{ [key: string]: any }>

    • Creates a new record in the Google Sheet.
    • data: The data to insert.
    • Returns a promise that resolves to the created record.
  • find(query: { [key: string]: any }): Promise<any[]>

    • Finds records matching the query.
    • query: The query to filter records.
    • Returns a promise that resolves to an array of matching records.
  • findOne(query: { [key: string]: any }): Promise

    • Finds a single record matching the query.
    • query: The query to filter records.
    • Returns a promise that resolves to the matching record or null.
  • update(query: { [key: string]: any }, newData: { [key: string]: any }): Promise<{ [key: string]: any }>

    • Updates records matching the query.
    • query: The query to filter records.
    • newData: The new data to update.
    • Returns a promise that resolves to the updated record.
  • delete(query: { [key: string]: any }): Promise<sheets_v4.Schema$UpdateValuesResponse>

    • Deletes records matching the query.
    • query: The query to filter records.
    • Returns a promise that resolves to the update response.

This documentation should help users understand how to install and use your npm package. Make sure to include any additional information or examples specific to your package's features and usage.