gsheet-to-db

2.1.6 • Public • Published

gsheet-to-db

npm

Example for gsheet-to-db GitHub repo link

https://github.com/saurabhgkp/gsheet-to-db-example

Easy to use and implement

SheetDB will turn your sheets into a JSON API, easy to integrate with other tools and all programming languages.

operations

You can read and edit your spreadsheet with GET, POST, PUT and DELETE requests with just a few lines of code.

FAQ

In Google Sheets you have to set data in header vale by manually first Field must be an 'id' and remaining is upto you

id Name Status Salary
1 Wilson FullTime $40,000
2 saurabh FullTime $120,000
3 herry FullTime $40,000
 id |	 Name |    Status |	Salary
this field Are Add by manually field
may Different (As you Want 'id' is First Field !importent)

passing data in body is like

{
    "B":"herry",
    "C":"FullTime",
    "D":"$40,000"
}

always use capital letters ===> Don't A, This is use for 'id' use B C D to the Z for passing data

prerequisite

Activate Google Sheets API. Go to the Google console developer and enable Google Sheets API. https://console.cloud.google.com/apis/dashboard And get JSON key. DO NOT commit the JSON key! Add the file to .gitignore now and import it into the code! Or use environment variables.

Installation

Install my-project with npm

  npm i gsheet-to-db

Import

const { Gsheet } =  require("gsheet-to-db")
const  gdata  =  new  Gsheet("./keyFile.json", "spreadsheetId", "sheetName")

 let  data1  =  await  gdata.findAll()
 let  data2  =  await  gdata.findById(id)
 let  data3  =  await  gdata.create(data)
 let  data4  =  await  gdata.deleteById(id)
 let  data5  =  await  gdata.updateById(id, data)

Code Explanation

"./keyFile.json" this keysFile you can get it from Google console developer

spreadsheetIdyou can get from spreadsheet URL for example https://docs.google.com/spreadsheets/d/1JmpRfmEfSdVAxAu2SRvzsnswI1-ln-3F_1xtlg/edit?pli=1#gid=0 here after /d/ and before /edit is your spreadsheetId ="1JmpRfmEfSdVAxAu2SRvzsnswI1-ln-3F_1xtlg"

sheet name can be found at the bottom of spreadsheets by default is something like "sheet1"

let data3 = await gdata.create(data) here data must be started from "B" not "A". "A" is reserved for "id" for example

{
    "B":"herry",
    "C":"FullTime",
    "D":"$40,000"
    ...
}

for any help, you can DM me on LinkedIn

🔗 Links

linkedin

Package Sidebar

Install

npm i gsheet-to-db

Weekly Downloads

3

Version

2.1.6

License

ISC

Unpacked Size

8.84 kB

Total Files

3

Last publish

Collaborators

  • saurabhgkp