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

sheetabase

v1.0.7

Published

Sheetabase is a lightweight package that transforms Google Sheets into a powerful database with easy-to-use ORM-like querying

Downloads

7

Readme

Sheetabase

Sheetabase is a lightweight package that transforms Google Sheets into a powerful database with easy-to-use ORM-like querying. It offers promise-based functions for creating, reading, updating, and deleting data, making it simple to integrate and use in your projects.

Installation

To install Sheetabase, use npm or yarn:

npm install sheetabase

or

yarn add sheetabase

Usage

Below is an example of how to set up and use Sheetabase to synchronize models, insert data, update data, find data, and delete data.

Setup

First, import the setupSheetabase function from the sheetabase package and configure your database:

const { setupSheetabase } = require("sheetabase");

const setup = setupSheetabase({
  sheetUrl:
    "https://docs.google.com/spreadsheets/d/1HNnIsnSEP0DbJ8bfO9JH6cx0sIrcRpm6U6ZbkKGEZC4/edit?usp=sharing",
  models: [
    {
      name: "TestDatabase", // Table Name / Sheet Name
      columns: [["id", "name", "status"], { pk: "id", autoIncrement: true }],
    },
  ],
});

Note: The sheetUrl must be a Google Sheets URL with edit access set to "Anyone with the link can edit".

Synchronize Model

Use the sync method to synchronize your model to the sheet. This will create the sheet and tables as specified in the setup if they do not already exist.

async function testSyncDB() {
  await setup.sync();
}

Insert Data

To insert data into the sheet, use the create method.

async function testInsertData() {
  await setup.use("TestDatabase").create({
    name: "Jojo",
    status: 200,
  });
}

Update Data

To update data in the sheet, use the update method with the data to update and the conditions for the update.

async function testUpdateData() {
  const result = await setup
    .use("TestDatabase")
    .update({ name: "Johan XI" }, { where: { id: 1 } });
}

// Example Result
// Result {
//   isError: false,
//   status: 200,
//   message: 'REQUEST COMPLETE',
//   data: { id: 1, name: 'Johan XI', status: 200 }
// }

Find One Record

To find a single record from the sheet, use the findOne method with the search conditions.

async function testFindOne() {
  const result = await setup.use("TestDatabase").findOne({ where: { id: 1 } });
}

// Example Result
// Result {
//   isError: false,
//   status: 200,
//   message: 'REQUEST COMPLETE',
//   data: { id: 1, name: 'Johan XI', status: 200 }
// }

Find All Record

To find all records that match certain conditions, use the findAll method.

async function testFindAll() {
  const result = await setup.use("TestDatabase").findAll({ where: { id: 1 } });
}

// Example Result
// Result {
//   isError: false,
//   status: 200,
//   message: 'REQUEST COMPLETE',
//   data: [{ id: 1, name: 'Johan XI', status: 200 }]
// }

Delete Data

To delete data from the sheet, use the delete method with the conditions for deletion.

async function testDeleteData() {
  const result = await setup.use("TestDatabase").delete({ where: { id: 1 } });
}

// Example Result
// Result {
//   isError: false,
//   status: 200,
//   message: 'REQUEST COMPLETE',
//   data: []
// }

Full Example

Here is the full example combining all the above methods:

const { setupSheetabase } = require("sheetabase");

const setup = setupSheetabase({
  sheetUrl:
    "https://docs.google.com/spreadsheets/d/1HNnIsnSEP0DbJ8bfO9JH6cx0sIrcRpm6U6ZbkKGEZC4/edit?usp=sharing",
  models: [
    {
      name: "TestDatabase",
      columns: [["id", "name", "status"], { pk: "id", autoIncrement: true }],
    },
  ],
});

async function testSyncDB() {
  await setup.sync();

  await setup.use("TestDatabase").create({
    name: "Jojo",
    status: 200,
  });

  const updateResult = await setup
    .use("TestDatabase")
    .update({ name: "Johan XI" }, { where: { id: 1 } });

  const findOneResult = await setup
    .use("TestDatabase")
    .findOne({ where: { id: 1 } });

  const findAllResult = await setup
    .use("TestDatabase")
    .findAll({ where: { id: 1 } });

  const deleteResult = await setup
    .use("TestDatabase")
    .delete({ where: { id: 1 } });
}

testSyncDB();

Contributing

If you find any issues or have suggestions for improvements, please create an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.