Skip to content

Latest commit

 

History

History
71 lines (53 loc) · 3.46 KB

README.md

File metadata and controls

71 lines (53 loc) · 3.46 KB

Google-Sheets-Database

This NPM Package allows you to use a Google Spreadsheet as a database within your Node Js project.

How to use

There are 2 setup parts in order to get this package working. The first part is setting up the API endpoint that calls routes to my script endpoint within a Google Script on your Google Drive. The second part is installing the NPM package and connecting to your the database via the deployment ID.

Part 1: Google

  1. Create a new google script file
    image

  2. Add the MCLib script as a library to your script 1wuipW_9oqNOq1l0bdbLiIrt5JnX8xzI_Bb7jA7rRzArfpfmys_7wNlgU
    image image image

  3. Add doPost method that redirects to the MCLib doPost method
    const doPost = (e) => MCLib.doPost(e)
    image

  4. Deploy your script as an Web app
    image image image

  5. Authorize access
    image image image image

  6. Copy the Deployment ID to your clipboard image

Part 2: Node

  1. Set up your Node Project with node init

  2. Load this library into your project
    const googlesheetdatabase = require("google-sheet-database")

  3. Create a schema for a new table
    SampleSchema = new googlesheetdatabase.schema( ["id", "column1", "column2", "column3"] )

  4. Create a model for the schema
    SampleModel = new googlesheetdatabase.model("SampleModel", SampleSchema)

  5. Connect to the database
    googlesheetdatabase.connection.connect({ databaseName: YOUR_DATABASE_NAME, apiKey: YOUR_DEPLOYMENT_ID })

Performing CRUD Operations

WIthin this file you will see examples of all the different CRUD operations that can be performed. Below lists them for reference.

  • Inserting a single record (CREATE)
  • Update a single record (UPDATE)
  • Select a single record (READ)
  • Deleting a single record (DELETE)
  • Inserting Multiple Records (CREATE)
  • Update multiple records (UPDATE)
  • Select (READ)
  • Select with where condition (READ)
    image

Viewing the spreadsheet

image