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

nodequentsheets

v0.0.16

Published

This is a package that turns google sheets into a database that is accessible in a node.js ORM

Downloads

76

Readme

nodequentsheets

This is a package that turns google sheets into a quasi node.js ORM. It uses the google-api-nodejs-client to authenticate with the google sheets API. It currently implements the Google service account for authentication, but future releases might incorporate other authentications.

At this point, you can pull data form a sheet, manipulate that data, then write it back. The downside to this format is that it primarily works through batch updating. Even if one row is manipulated, this package will clear the sheet, then readd all the rows. It assumes that there is a header row.

In order to better facilitate testing, nodequentsheets allows you to put the sheet ID of a production and a developement sheet and it gives you the option to set the mode to either development or production. In order to do this, you need to set .env (currently in the root of the package).

To use this package, you need to have a google service account and a google sheets document. You need to have the service account's credentials stored in a file named credentials.json in a directory named storage.

You can install this package using npm, npm i nodequentsheets

Basic Usage

This package utilizes the dotenv npm package and requires you to set .env environment variables: DEV_ID="devSpreadsheetID" PROD_ID="devSpreadsheetID"

Once your environment variables are set you can load in the Sheets class and set your options:

require("dotenv").config()
const Sheets = require("../src/Sheets")

const db = new Sheets({
    developmentId: process.env.DEV_ID,
    productionId: process.env.PROD_ID,
    serviceAccount: require("../storage/credentials.json"),
    useCache: true,
})
// Set the DB mode to true for a development sheet or false for a production sheet
db.setMode({ development: true })
// You can set a column in the spreadsheed to act like a primary column.
// Currently nodequentsheets assigns a numerical ID to each row in the spreadsheet when
// it is converted to an object and stored in the values property.
db.setPrimaryColumn("ID")

// Once the options are set you can initialize the Class, which will set up the Google Sheets
// Authentication
await db.init()

// Once the class is initiated, you can make a call to the Google Sheets API to pull the rows
// from the sheet, using various .where conditions.
// If no where conditions are assigned, you will retrieve all the values in the spreadsheet.
// Sheets transforms all header row values into lower case, with no special characters, and
// underscores instead of spaces, so make sure you search the columns based on the new criteria
const Sheet = (await db.table("sheetname"))
    .where({
        column: "name",
        operator: "=",
        value: "John",
    })
    .where({
        column: "primary_address",
        operator: "=",
        value: "123 Street Address",
    })

// Order By statements are also acceptable
const Sheet = (await db.table("sheetname")).orderBy({ column: "ID", direction: "desc" })

// You can also pass your own custom way of sorting:
const Sheet = (await db.table("sheetname")).orderByRaw((data) => {
    return data.sort((a, b) => {
        return a.ID - b.ID;
    }
})

// After you have populated the values in the class, you can loop through and manipulate each row
for (const row of Table.get()) {
    row.ID = Math.random(15)
}
Table.save()